Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get all System.Attributes from overridden member?
    primarykey
    data
    text
    <p>I am trying to find the DataMember attribute on properties of a class. I can find the attribute if it is on a property defined directly in the class. However if the property is defined in a base class and overridden, the attribute is not found. I have found several links stating you have to use System.Attribute to get this information. Below is a direct quote from <a href="http://msdn.microsoft.com/en-us/library/b6xa75x5%28v=vs.95%29.aspx" rel="nofollow">Microsoft</a>.</p> <blockquote> <p>Calling ICustomAttributeProvider.GetCustomAttributes on PropertyInfo or EventInfo when the inherit parameter of GetCustomAttributes is true does not walk the type hierarchy. Use System.Attribute to inherit custom attributes.</p> </blockquote> <p>This seems to fix the problem completely when using the full framework. This seems to fix the problem for ONLY "non-system" attributes in Silverlight (tested on Silverlight 3.0, 4.0, 5.0). My sample code below shows that DataMemberAttribute is not returned while another custom defined Attribute is returned. Is this a bug or am I missing something?</p> <pre><code>public class CustomAttribute : Attribute { } public class Animal { [DataMember(), CustomAttribute()] public virtual decimal Weight { get; set; } } public class Dog : Animal { public override decimal Weight { get; set; } } public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); var animalAttributes = Attribute.GetCustomAttributes(typeof(Animal).GetProperties()[0], true); var dogAttributes = Attribute.GetCustomAttributes(typeof(Dog).GetProperties()[0], true); //animalAttributes contains 2 entries (DataMember, CustomAttribute) //dogAttributes contains only 1 entry (CustomAttribute) } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload