码迷,mamicode.com
首页 > Windows程序 > 详细

c# 通过反射输出成员变量以及成员变量的值

时间:2017-09-30 18:03:53      阅读:410      评论:0      收藏:0      [点我收藏+]

标签:system   .text   str   sys   ati   only   roi   variables   UI   

/**
* @Author rexzhao
* 工具类 仅限于
* public variable
*/
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using UnityEngine;
//#if !UNITY_ANDROID && UNITY_EDITOR

#if __DEBUG
public static class ObjectUtils
{
public static string Print_VariablesOf<T>(T t)
{
var type = t.GetType();
var Fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
StringBuilder sb = new StringBuilder();
foreach (var finfo in Fields)
{
var test = finfo.GetValue(t);
if (test == null)
continue;
sb.Append(finfo.Name.ToString());
sb.Append(": ");
sb.Append(test.ToString());
sb.AppendLine();
}
return sb.ToString();
}
}
#endif

c# 通过反射输出成员变量以及成员变量的值

标签:system   .text   str   sys   ati   only   roi   variables   UI   

原文地址:http://www.cnblogs.com/rexzhao/p/7615408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!