I have create an custom attribute for properties (AttributeTarget).
Next, i've created a class with a property, and on this property i've declared the custom attribute.
So far so good.
I can read the custom attribute of this property in my class. Yeah!
The "trouble" comes with the next set of properties that have this custom attribute. All the properties undergo the same steps that take the custom attribute and create a new class and set one of the values of the new class to the value of the property... The rest of the class is interpreted via the attribute.
So what i want is something like:
CreateNewClassFromAttribute(MyObject.Property1); |
I've tried a few things, but i cannot seem to access the attribute in the function. All i get is the type and value of property, the attribute seems lost.
The best i could do is:
CreateNewClassFromAttribute(MyObject, "Property1"); |
Then i can take the string, reflect on MyObject and find the property/attributes.
But i really, really hate passing in strings like that...
Am i missing something
TIA

Passing properties with attributes to functions
Aleksei Vassiljev
mbkasi
I've found this article that explains my scenario:
http://blogs.msdn.com/ericgu/118233.aspx
Mike from Wauwatosa
CreateNewClassFromAttribute(MyObject.Property1);
This code runs the get-method of the property, gets the return value and puts that into the argument of the CreateNewClass method. The fact that the value came from a property is lost at this point.
You would need an object describing the property itself, which is the System.Reflection.PropertyInfo class. But you can only get that via reflection:
MyObject.GetType().GetProperty("Property1");
But there's that string again... I can't see a solution for your problem, sorry.