0

I have a Silverlight application and I'm using Entity Framework and Ria Services.

I need to create a custom attribute that I will use to recognize some properties.

Ex. :

public class Person
{
    [IsSpecialProperty]
    public string PersonProperty { get; set; }
}

public class IsSpecialPropertyAttribute : Attribute
{

}

I named the class file "IsSpecialPropertyAttribute.shared.cs" to access it from the client.

And from the client side, I use the method :

var attributes = (IsSpecialPropertyAttribute[])Attribute.GetCustomAttributes(memberInfo, typeof(IsSpecialPropertyAttribute));

This method is working for system attributes but not with my custom attribute...

Any idea why ?

This method give me all the other attributes, but not the custom I created...

var test = Attribute.GetCustomAttributes(memberInfo);

1 Answer 1

0

You could try two other approaches:

var attributes = memberInfo.GetCustomAttributes(typeof(IsSpecialPropertyAttribute), true);

or:

var attribute = person.GetType().GetCustomAttributes(typeof(IsSpecialPropertyAttribute), true).FirstOrDefault() as IsSpecialPropertyAttribute;
1
  • Thanks, but it doesn't work. "Attribute.GetCustomAttributes(memberInfo);" get the list of all other attributes, but not the one I created...
    – Gab
    Mar 16, 2015 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.