/// <summary> /// Loads a <see cref="TsPropertySymbol" /> from the specified <see cref="TsPropertyMetadata" /> and <see cref="TsSymbolLookup" />. /// </summary> /// <param name="propertyMetadata">The property metadata.</param> /// <param name="symbolLookup">The symbol lookup.</param> /// <param name="options">The options.</param> /// <returns>A <see cref="TsPropertySymbol" />.</returns> /// <exception cref="NotSupportedException">The type {property.PropertyType.FullName} of {property.Name}</exception> internal static TsPropertySymbol LoadFrom(TsPropertyMetadata propertyMetadata, TsSymbolLookup symbolLookup, ISymbolLoadOptions options) { if (!symbolLookup.TryResolveSymbol(propertyMetadata.Property.PropertyType, out TsTypeSymbol type)) { throw new NotSupportedException($"The type {propertyMetadata.Property.PropertyType.FullName} of {propertyMetadata.Name} is not supported."); } string name = GetPropertyName(propertyMetadata.Property, options); return(new TsPropertySymbol(name, type, propertyMetadata)); }
/// <summary> /// Loads a <see cref="TsTypeSymbol" /> from the specified <see cref="TsTypeMetadata" /> using the <see cref="TsSymbolLookup" />. /// </summary> /// <param name="typeMetadata">The type metadata.</param> /// <param name="symbolLookup">The symbol lookup.</param> /// <param name="options">The options.</param> /// <returns>A <see cref="TsTypeSymbol" />.</returns> internal static TsTypeSymbol LoadFrom(TsTypeMetadata typeMetadata, TsSymbolLookup symbolLookup, ISymbolLoadOptions options) { if (typeMetadata.Type.IsGenericType) { throw new NotSupportedException("Generic types are not currently supported."); } TsTypeSymbol baseTypeSymbol = null; if (typeMetadata.Type.IsClass && !typeMetadata.Flatten && typeMetadata.Type.BaseType != null && typeMetadata.Type.BaseType != typeof(object)) { baseTypeSymbol = symbolLookup.ResolveSymbol(typeMetadata.Type.BaseType); } List <TsTypeSymbol> interfaceTypeSymbols = new List <TsTypeSymbol>(); if (!typeMetadata.Flatten) { foreach (Type interfaceType in typeMetadata.Type.GetInterfaces()) { if (symbolLookup.TryResolveSymbol(interfaceType, out TsTypeSymbol interfaceTypeSymbol)) { interfaceTypeSymbols.Add(interfaceTypeSymbol); } } } List <TsPropertySymbol> propertySymbols = new List <TsPropertySymbol>(); foreach (PropertyInfo property in typeMetadata.GetProperties()) { propertySymbols.Add(TsPropertySymbol.LoadFrom(property, symbolLookup, options)); } TsTypeSymbol symbol = new TsTypeSymbol ( name: typeMetadata.Name, symbolKind: GetSymbolKind(typeMetadata), baseTypeSymbol, interfaceTypeSymbols, propertySymbols, typeMetadata ); return(symbol); }