我有以下代码。它返回汇编信息,因为它是closed generic type。
List<String> list = new List<String>();
t = list.GetType();
Console.WriteLine(t.FullName);
打印以下内容:
//System.Collections.Generic.List`1[[System.String, mscorlib,
//Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
我知道我可以写出在&#34; [[&#34;和&#34;]]&#34;删除版本,文化和publickeytoken等属性。我想知道是否有更清洁的方法来删除这些属性?
编辑: 我想要的输出是
//System.Collections.Generic.List`1[[System.String, mscorlib]], mscorlib
答案 0 :(得分:0)
像这样:
internal class Program {
public static void Main(string[] args) {
List<String> list = new List<String>();
Type t = list.GetType();
string yourString = string.Format(
"{0}.{1}.[[{2}, {3}]], {3}",
t.Namespace,
t.Name,
t.GetGenericArguments()[0],
t.Assembly.GetName().Name);
Console.WriteLine(yourString);
// This prints :
//System.Collections.Generic.List`1[[System.String, mscorlib]], mscorlib
}
}