Problem in working with Custom attributes

Posted on 2005-05-09
Last Modified: 2010-05-18
    Could you please let me know whether it is possible to set the value of a customattribute (derived from System.Attribute) in .net using reflection? if s, then will be possible to have different values for the customattribute for different instances of the class? Hope I am clear..
        This is a bit urgent.Any guidance will really be of great help to me..
Thanks in advance..

Question by:viswasiva
    LVL 2

    Accepted Solution

    My understanding is that Attribute properties are fixed at compile time and are invariant across all instances of a class. What are you trying to acheive by using custom attributes?

    Author Comment

    Thanks for the inputs. I am using this custom attributes to represent the metadata of my class. I wanted to store different values of the meta data for different instances. Could u pls tell me If there is a possibility of changing the customattribute property value? When wil be the setter function called..????
    We have GetCustomAttributes() method to get the values of the custom attributes..I want to know whether it can be set? If so, what is the function used for that?
    LVL 2

    Expert Comment

    I'm not an expert on reflection, but i suspect that what you are trying to do is not possible and isn't what attributes are intended for.

    Could you not use class properties to store instance-specific metadata instead?

    Author Comment

    Yeah..I can..But am a bit curious to know what will be the use of setter function in the customattribute class..and when will it be called. I am trying to make use of that..if possible.
    LVL 96

    Expert Comment

    by:Bob Learned
    AFAIK, attributes are descriptors for the methods, properties, at compile time, and cannot be set at run-time.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now