110,538
社区成员
发帖
与我相关
我的任务
分享
class xxx
{
public int ma = 20;
private int mb = 100;
private string sa = "abc";
private string sb = "33333";
private string sc = "ewr";
}
// 通过反射的形式获得一个对象的所有字段名字和值的描述集合
public static string MSreflection<T>(T type, int ISeveryHH)
{
Type ty = type.GetType();
FieldInfo[] fiel = ty.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
string sall = "";
string HH = ISeveryHH == 1 ? Environment.NewLine : "";
foreach (FieldInfo fil in fiel)
{
object onow = fil.GetValue(type);
string sone = onow != null ? onow.ToString() : "NULL";
sall += "[" + fil.Name + "=" + sone + "] " + HH;
}
return sall;
}
xxx mx = new xxx();
MSreflection<xxx>(mx, 1);
class test
{
Dictionary<int, int> dary = new Dictionary<int, int>();
List<List<int>> sary = new List<List<int>>();
List<int> nary = new List<int>();
xxx mx = new xxx();
wori wr = new wori();
Tuple<Type, List<int>, string, int, long> tup = new Tuple<Type, List<int>, string, int, long>(typeof(int),null, null, 0, 1);
}
test ttt = new test();
MSreflection<test>(ttt, 1);