1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Reflection;
- using System.Text;
- namespace TBL.CSharp.Base
- {
- public static partial class Extension
- {
- /// <summary>
- /// 获取可编译的类型名
- /// </summary>
- 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;
- }
- /// <summary>
- /// 获取程序集列表
- /// </summary>
- public static IEnumerable<Assembly> GetAssemblies()
- {
- return AppDomain.CurrentDomain.GetAssemblies();
- }
- }
- }
|