| re: Some attribute questions
what i want to know is if there is a way to specify to the compiler that a custom attribute can only be applied to a property with a set accessor (CanWrite == true).
Something like AttributeUsage does.
[AttributeUsage(AttributeTargets.Property)]
public class SomeAttribute : Attribute {}
public SomeClass
{
[SomeAttribute ] //I want a compiler error here because the attribute SomeAttribute is applied to an property that does not have a set
public int onlyGetProp { get {return 0;} }
[SomeAttribute ] //
public int onlyGetProp { get {return 0;} set { /*do something*/} }
}
Is it possible to have the described behavior?
Also can i do something like this:
Attribute[] atts = (Attribute[])GetType().GetCustomAttributes(typeof(SomeAttribut e), true);
foreach(Attribute a in atts)
{
MemberInfo mi = a.getMember(); //this method should give the member info where the instance of the attribute has applied, does such thing exists???
}
|