using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
namespace TBL.CSharp.Base
{
public static partial class Extension
{
///
/// 获取可编译的类型名
///
public static string GetCompilableName(this Type type, bool isFullName = false)
{
var name = isFullName ? type.FullName : type.Name;
Debug.Assert(!string.IsNullOrEmpty(name));
if (type.IsGenericType)
{
var strings = name.Split('`');
var args = type.GenericTypeArguments;
var sb = new StringBuilder();
Debug.Assert(strings.Length > 1);
for (var i = 0; i < args.Length; i++)
{
if (i != 0)
sb.Append(", ");
sb.Append(GetCompilableName(args[i], true));
}
name = $"{strings[0]}<{sb}>";
}
name = name.Replace('+', '.');
return name;
}
///
/// 获取程序集列表
///
public static IEnumerable GetAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies();
}
}
}