コード例 #1
0
ファイル: ReadAttributes.cs プロジェクト: morecodding/samples
 static void Main(string[] args)
 {
     ModelXYZ x = new ModelXYZ() { Name = "Lucas", Age = 21 };
         var prop = ReadAttributes(ref x, "Idade");
         var idade = prop.GetValue(x);
         Console.Write(idade);
         Console.ReadKey();
 }
コード例 #2
0
ファイル: ReadAttributes.cs プロジェクト: morecodding/samples
 static PropertyInfo ReadAttributes(ref ModelXYZ model, string valueAttribute)
 {
     return (from p in model.GetType().GetProperties()
                  from it in p.GetCustomAttributes(typeof(POC), true)
                  where ((POC)it).Name == valueAttribute
                  select p).FirstOrDefault();
 }