M
Morten Wennevik [C# MVP]
Hi Coconet
MemberInfo won't tell you much other than what kind of members are available. You would then need to obtain a MethodInfo, PropertyInfo or FieldInfo to get the actual values. In your case this code piece should listthe string
MyStruct f = new MyStruct();
Type t = f.GetType();
FieldInfo[] fields = f.GetType().GetFields();
List<string> values = new List<string>();
foreach (FieldInfo fi in fields)
values.Add(fi.GetValue(fi).ToString());
MemberInfo won't tell you much other than what kind of members are available. You would then need to obtain a MethodInfo, PropertyInfo or FieldInfo to get the actual values. In your case this code piece should listthe string
MyStruct f = new MyStruct();
Type t = f.GetType();
FieldInfo[] fields = f.GetType().GetFields();
List<string> values = new List<string>();
foreach (FieldInfo fi in fields)
values.Add(fi.GetValue(fi).ToString());
I am trying to enumerate all of the name/value info from a struct with
Reflection. It looks like this:
public struct MyStruct
{
public const string ValueOne = "something";
public const string ValueTwo = "somethingelse";
}
In another class, I would like to enumerate it into MemberInfo[] so I
can use the parts. How to do that in C# 2.0?
Thanks.