• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Problem in working with Custom attributes

Team.,
    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..

Regards,
Viswa
0
viswasiva
Asked:
viswasiva
  • 2
  • 2
1 Solution
 
SThorogoodCommented:
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?
0
 
viswasivaAuthor Commented:
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?
0
 
SThorogoodCommented:
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?
0
 
viswasivaAuthor Commented:
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.
0
 
Bob LearnedCommented:
AFAIK, attributes are descriptors for the methods, properties, at compile time, and cannot be set at run-time.

Bob
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now