Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// Resolves the type symbols for the specified <see cref="Type"/> objects.
        /// </summary>
        /// <param name="types">The types.</param>
        /// <returns>An <see cref="IReadOnlyList{T}"/> of <see cref="TsTypeSymbol"/>.</returns>
        public IReadOnlyList <TsTypeSymbol> ResolveTypeSymbols(IEnumerable <Type> types)
        {
            List <TsTypeSymbol>   results      = new List <TsTypeSymbol>();
            TsSymbolLookup        symbolLookup = new TsSymbolLookup();
            TsDtoTypeSymbolHelper dtoHelper    = new TsDtoTypeSymbolHelper(symbolLookup, this.options);

            TsDependencySortVisitor sortVisitor = new TsDependencySortVisitor();
            IReadOnlyList <Type>    sortedTypes = sortVisitor.Sort(types);

            foreach (Type type in sortedTypes)
            {
                TsTypeSymbol symbol = TsTypeSymbol.LoadFrom(type, symbolLookup, this.options);

                symbolLookup.Add(type, symbol);
                results.Add(symbol);
            }

            results.AddRange(dtoHelper.CreateAndConfigureDtoSymbols(results));

            return(results);
        }
Пример #3
0
        /// <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));
        }
Пример #4
0
        /// <summary>
        /// Loads a <see cref="TsPropertySymbol" /> from the specified <see cref="PropertyInfo" /> and <see cref="TsSymbolLookup" />.
        /// </summary>
        /// <param name="property">The property.</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(PropertyInfo property, TsSymbolLookup symbolLookup, ISymbolLoadOptions options)
        {
            TsPropertyMetadata propertyMetadata = TsPropertyMetadata.LoadFrom(property);

            return(LoadFrom(propertyMetadata, symbolLookup, options));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TsDtoTypeSymbolHelper"/> class.
 /// </summary>
 /// <param name="symbolLookup">The symbol lookup.</param>
 /// <param name="options">The options.</param>
 public TsDtoTypeSymbolHelper(TsSymbolLookup symbolLookup, ISymbolLoadOptions options)
 {
     this.options      = options;
     this.symbolLookup = symbolLookup;
 }
Пример #6
0
        /// <summary>
        /// Loads a <see cref="TsTypeSymbol" /> from the specified <see cref="Kind" /> using the <see cref="TsSymbolLookup" />.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="symbolLookup">The symbol lookup.</param>
        /// <param name="options">The options.</param>
        /// <returns>A <see cref="TsTypeSymbol" />.</returns>
        internal static TsTypeSymbol LoadFrom(Type type, TsSymbolLookup symbolLookup, ISymbolLoadOptions options)
        {
            TsTypeMetadata typeMetadata = TsTypeMetadata.LoadFrom(type);

            return(LoadFrom(typeMetadata, symbolLookup, options));
        }