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(); }
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(); }