/// <summary> /// 如果不是系统类型则自动转换成构建器生成的类名 /// </summary> /// <param name="builder"></param> /// <param name="type"></param> /// <returns></returns> public static string ToBuilderType(this BuilderOptions builder, Type type) { if (type == null) { return(string.Empty); } var res = Reflection.SystemCsType(type); if (!string.IsNullOrWhiteSpace(res)) { return(res); } if (Reflection.IsCollection(type)) { var typeDefinition = type.GetGenericTypeDefinition(); var types = string.Join(',', type.GetGenericArguments().Select(x => { var sysType = Reflection.SystemCsType(x); return(string.IsNullOrWhiteSpace(sysType) ? builder.GetName(x.Name) : sysType); })); var collectionType = typeDefinition == typeof(IEnumerable <>) ? "IEnumerable" : typeDefinition == typeof(IReadOnlyCollection <>) ? "IReadOnlyCollection" : typeDefinition == typeof(IReadOnlyList <>) ? "IReadOnlyList" : typeDefinition == typeof(ICollection <>) ? "ICollection" : typeDefinition == typeof(IList <>) ? "IList" : typeDefinition == typeof(List <>) ? "List" : typeDefinition == typeof(IDictionary <,>) ? "IDictionary" : typeDefinition == typeof(Dictionary <,>) ? "Dictionary" : ""; return($"{collectionType}<{types}>"); } if (Reflection.IsEnum(type)) { return(type.FullName); } return(builder.GetName(type.Name)); }