我有一个第三方对象,它被传递给我的一个方法。该对象包含20个左右的字符串成员。如何轻松列出所有字符串名及其值?
发布于 2011-06-14 03:08:46
你是在说房产吗?如果是这样,您可以使用反射:
Dim properties = theObject.GetType().GetProperties()
For Each prop In properties
Console.WriteLine("{0}: {1}", prop.Name, _
prop.GetValue(theObject, New Object() { }))
Next这将通过GetProperties返回对象的所有公共属性。
发布于 2011-06-14 03:06:43
然后使用o.GetType().GetProperties(),使用PropertyInfo.PropertyType属性确保它是字符串,然后,使用foreach属性,调用GetValue (o, null)
props = o.GetType().GetProperties()
PropertyInfo prop = props(0)
Console.WriteLine (prop.Name & " = " & prop.GetValue (o, Nothing))https://stackoverflow.com/questions/6334899
复制相似问题