/// <summary> /// 获得类型信息 /// </summary> /// <param name="t"></param> /// <returns></returns> public static TypeModel GetTypeFromCache(Type t) { var item = TypeModelCacheManager.Get(t.FullName); if (item != null) { return(item.Copy()); } else { item = new TypeModel(); TypeModelCacheManager.Set(t.FullName, item); item = ModelFactory.CreateTypeModel(t); return(item); } }
public static TypeModel ToTypeModel(this string fullTypeName) { var model = TypeModelCacheManager.Get(fullTypeName); if (model == null) { var type = fullTypeName.ToType(); if (type != null) { model = type.ToTypeModel(); } else { model = TypeDefinition.FromString(fullTypeName).ToTypeModel(); } TypeModelCacheManager.Set(fullTypeName, model); } return(model); }
public static TypeModel ToTypeModel(this Type t) { if (t == null) { return(null); } TypeModel model = TypeModelCacheManager.Get(t.FullName); if (model != null) { return(model); } model = t.ToTypeModelWithoutProperties(); if (model.Properties.Count == 0) { var properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public); if (properties != null) { foreach (var p in properties) { TypeModel m = p.PropertyType.ToTypeModelWithoutProperties(); m.MemberName = p.Name; var desc = ResolverHelper.GetMemberFromCache(p.DeclaringType, x => { return(x.Name.StartsWith("P:" + p.DeclaringType.FullName + "." + p.Name)); }); m.Description = desc?.Summary?.Trim(); model.Properties.Add(m); } } } if (model.IsClass) { TypeModelCacheManager.Set(t.FullName, model); } return(model); }
/// <summary> /// 获得类型信息 /// </summary> /// <param name="typeName"></param> /// <returns></returns> public static TypeModel GetTypeFromCache(string typeName) { return(TypeModelCacheManager.Get(typeName)); }