2010-12-13 5 views

Antwort

3

Kann so etwas wie unten

dort Say ist ein Objekt strlist

PropertyInfo[] info = strList.GetType().GetProperties(); 

     Dictionary<string, object> propNamesAndValues = new Dictionary<string, object>(); 

     foreach (PropertyInfo pinfo in info) 
     { 
      propNamesAndValues.Add(pinfo.Name, pinfo.GetValue(strList, null)); 
     }    
0

Versuchen Sie, so etwas zu verwenden:

MyClass aClass = new MyClass(); 

Type t = aClass.GetType(); 
PropertyInfo[] pi = t.GetProperties(); 

foreach (PropertyInfo prop in pi) 
    Console.WriteLine("Prop: {0}", prop.Name); 

Hoffe, dass es Ihnen helfen.

1

versuchen diese

var properties = myObj.GetType() 
        .GetProperties(BindingFlags.Instance | BindingFlags.Public); 
var propertyNames = properties.Select(p => p.Name); 
var propertyValues = properties.Select(p => p.GetValue(myObj, null)); 
Verwandte Themen