c# 通過反射輸出成員變量以及成員變量的值


/**
* @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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM