Note that there are some explanatory texts on larger screens.

plurals
  1. POAttribute.IsDefined doesn't see attributes applied with MetadataType class
    primarykey
    data
    text
    <p><strong>If I apply attributes to a partial class via the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.metadatatypeattribute.aspx" rel="nofollow noreferrer">MetadataType attribute</a>, those attributes are not found via <a href="http://msdn.microsoft.com/en-us/library/system.attribute.isdefined(VS.85).aspx" rel="nofollow noreferrer">Attribute.IsDefined()</a>.</strong> Anyone know why, or what I'm doing wrong?</p> <p>Below is a test project I created for this, but I'm really trying to apply custom attributes to a LINQ to SQL entity class - like <a href="https://stackoverflow.com/questions/393687/how-can-i-add-my-attributes-to-code-generated-linq2sql-classes-properties/667119#667119">this answer in this question</a>.</p> <p>Thanks!</p> <pre><code>using System; using System.ComponentModel.DataAnnotations; using System.Reflection; namespace MetaDataTest { class Program { static void Main(string[] args) { PropertyInfo[] properties = typeof(MyTestClass).GetProperties(); foreach (PropertyInfo propertyInfo in properties) { Console.WriteLine(Attribute.IsDefined(propertyInfo, typeof(MyAttribute))); Console.WriteLine(propertyInfo.IsDefined(typeof(MyAttribute), true)); Console.WriteLine(propertyInfo.GetCustomAttributes(true).Length); // Displays: // False // False // 0 } Console.ReadLine(); } } [MetadataType(typeof(MyMeta))] public partial class MyTestClass { public string MyField { get; set; } } public class MyMeta { [MyAttribute()] public string MyField { get; set; } } [AttributeUsage(AttributeTargets.All)] public class MyAttribute : System.Attribute { } } </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.
 

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