结构为
public class UNIDEVICE_Ext
{
public string szPicUrl;//图片地址;
public string szPicUrlExt;//图片地址多张图;
public string szDevice;//房间设施;
}
如何获得结构的成员,调用什么方法?这个问题应该给不难 我找不到那个方法,求高手赐教
public class UNIDEVICE_Ext
{
public string szPicUrl;//图片地址;
public string szPicUrlExt;//图片地址多张图;
public string szDevice;//房间设施;
}
如何获得结构的成员,调用什么方法?这个问题应该给不难 我找不到那个方法,求高手赐教
用list存储的
Type myObjectType = typeof(UNIDEVICE_Ext);
System.Reflection.FieldInfo[] fieldInfo = myObjectType.GetFields();
foreach (System.Reflection.FieldInfo info in fieldInfo)
{
Console.WriteLine(info.Name);
}
另外,在 C# 代码中推荐使用 Carmel 而不是匈牙利命名规范。
class Program
{
static void Main(string[] args)
{
UNIDEVICE_Ext obj1 = new UNIDEVICE_Ext { szDevice = "aaa", szPicUrl = "bbb", szPicUrlExt = "ccc" };
Type type = obj1.GetType(); FieldInfo[] fileds = type.GetFields(); Dictionary<string, string> filedValueMap = new Dictionary<string, string>();
foreach (FieldInfo fi in fileds)
{
filedValueMap.Add(fi.Name, fi.GetValue(obj1) as string);
} foreach (var keyval in filedValueMap)
Console.WriteLine("{0}:{1}", keyval.Key, keyval.Value); Console.ReadLine();
}
} public class UNIDEVICE_Ext
{
public string szPicUrl;//图片地址;
public string szPicUrlExt;//图片地址多张图;
public string szDevice;//房间设施;
}