vendredi 10 avril 2015

get values with reflection in generic class in c#

I have a problem in c#. I want to use a generic class with reflection and I want to know the current object values. But them is not read.



class Foo<T>
{
internal static void read(T[] block)
{
Type type = typeof(T);
foreach (var item in block)
{
foreach (PropertyInfo pi in type.GetProperties())
{
PropertyAttributes myAttributes = pi.Attributes;
Console.WriteLine(pi.Name); //names of variables appear
Console.WriteLine(pi.Attributes); // appear: "none"
}
}
}





Aucun commentaire:

Enregistrer un commentaire