ile uygulanan özellikleri görmezse MetadataType attribute aracılığıyla kısmi sınıfa öznitelikleri uygularsam, bu öznitelikleri Attribute.IsDefined() aracılığıyla bulamaz. Herkes neden olduğunu ya da yanlış yaptığımı biliyor mu?Attribute.IsDefined, MetadataType sınıfı
Aşağıda, bunun için oluşturduğum bir test projesi var, ancak gerçekten bir özelliğe LINQ için SQL varlık sınıfına - this answer in this question gibi - uygulamak istiyorum.
Teşekkürler!
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
{
}
}
onay bu şuna, ben zaten burada http://stackoverflow.com/a/24757520/3050647 – elia07
onay bunun bu soruya: @AdamGrid cevabı kullanarak, böyle kod almak için modifiye Bu soruya şu soruyu zaten cevaplandırdım: http://stackoverflow.com/a/24757520/3050647 – elia07