2012-08-07 61 views

回答

1

這會遍歷所有直通公共性能

dynamic something = new {id = "1", name = "name"}; 
    Type type = something.GetType(); 
    var properties = type.GetProperties(); 
    foreach (var property in properties) 
    { 
     var value = property.GetGetMethod().Invoke(something, null); 
     Console.WriteLine(string.Format("{0}:{1}", property.Name, value)); 
    }