Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7035943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:21:53+00:00 2026-05-28T01:21:53+00:00

I want to do this: [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)] sealed class

  • 0

I want to do this:

[AttributeUsage(AttributeTargets.Property, 
                Inherited = false, 
                AllowMultiple = true)]
sealed class MyAttribute : Attribute
{
    readonly string showName;
    readonly Type controlType;

    public Type ControlType
    {
        get { return controlType; }
    } 

    readonly Func<Control, object> selector;

    public Func<Control, object> Selector
    {
        get { return selector; }
    } 


    public MyAttribute(string showName, 
                       Type controlType, 
                       Func<Control, object> selector)
    {
        this.showName = showName;
        this.controlType = controlType;
        this.selector = selector;
    }

    public string ShowName
    {
        get { return showName; }
    }

}
class Foo
{
    // problem. Do you have an idea?
    [My("id number", 
     typeof(NumericUpDown), 
     Convert.ToInt32(control=>((NumericUpDown)control).Value))] 
    public int Id { get; set; }
}

I want to do attribute that contains name, type of control, and selector for take from the control the value of the property.

I try do it, and can’t.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:21:54+00:00Added an answer on May 28, 2026 at 1:21 am

    No, you cannot use an anonymous method or lambda expression in an attribute decoration.

    Incidentally, if you could, it would be (moving the control declaration):

    control=>Convert.ToInt32(((NumericUpDown)control).Value)
    

    But… You can’t. Either use the string name of a method that you resolve with reflection, or use something like a subclass of the attribute class with a virtual method override instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a marker interface something like this: [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class MyAttribute
I have the following ValidationAttribute class [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public
I want to use map mechanism, based on property attribute marking, like this: [AttributeUsage(AttributeTargets.Property
I want to use unobtrusive validation on my MVC app. I've created class [AttributeUsage(AttributeTargets.Property,
I'm writing an attribute (it's a ValidatorAttribute) that currently has [AttributeUsage(AttributeTargets.Property)] which restricts the
I have a C# annotation which is : [AttributeUsage(AttributeTargets.Method)] public class OperationInfo : System.Attribute
I have this div: <div class=inauguration-image> I do not want this text to display,
According to a book I'm reading, the AllowMultiple public property of AttributeUsage specifies: ...whether
I want this code to be possible. template<typename K, typename T, typename Comparer> class
I want this below class to return IList<> Please tell me why it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.