比如一个对象 List<int> m
给出m
返回一个字符串"List<int>"
static string GetTypeDescribe(Type tp)
{
string ret = string.Empty;
if (tp.IsGenericType)//是否是泛型
{
var name = tp.FullName.Split('`')[0];
ret += name;
ret += "<";
var tps = tp.GetGenericArguments();//返回泛型类型数组
for (int i = 0; i < tps.Length; i++)
{
ret += GetTypeDescribe(tps[i]);
if (i != tps.Length - 1)
ret += ",";
}
ret += ">";
}
else
ret = tp.FullName;
return ret;
}
运行结果
网友评论