/// <summary> /// Convert <see cref="IResourceTypeNode"/> to <see cref="ResourceTypeModel"/> without converting a type twice /// </summary> internal ResourceTypeModel ConvertType(IResourceTypeNode node, ResourceTypeModel baseType) { var resType = node.ResourceType; if (TypeCache.ContainsKey(node.Name)) { return(TypeCache[node.Name]); } // Remove generic arguments from type name var typeModel = new ResourceTypeModel { Creatable = node.Creatable, Name = node.Name, BaseType = baseType?.Name, // Read display name of the type otherwise use type short name DisplayName = resType.GetCustomAttribute <DisplayNameAttribute>(false)?.DisplayName ?? Regex.Replace(resType.Name, @"`\d", string.Empty), // Read description of the type Description = resType.GetCustomAttribute <DescriptionAttribute>(false)?.Description, // Convert resource constructors Constructors = node.Constructors.Select(ctr => EntryConvert.EncodeMethod(ctr, Serialization)).ToArray() }; // Convert reference properties var properties = node.ResourceType.GetProperties(); var references = GetReferences(properties); var overrides = GetReferenceOverrides(properties); typeModel.References = references.Select(reference => ConvertReferenceProperty(reference, overrides)).ToArray(); typeModel.DerivedTypes = node.DerivedTypes.Select(t => ConvertType(t, typeModel)).ToArray(); TypeCache[node.Name] = typeModel; return(typeModel); }