コード例 #1
0
        /// <summary>
        /// Gets the name of the property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="options">The options.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="NotSupportedException">Unsupported name style: {options.NameStyle}</exception>
        private static string GetPropertyName(PropertyInfo property, ISymbolLoadOptions options)
        {
            string result = null;

            switch (options.PropertyNameStyle)
            {
            case PropertyNameStyle.AsIs:
                result = property.Name;
                break;

            case PropertyNameStyle.CamelCase:
                result = property.Name.Camelize();
                break;

            case PropertyNameStyle.PascalCase:
                result = property.Name.Pascalize();
                break;

            default:
                throw new NotSupportedException($"Unsupported name style: {options.PropertyNameStyle}.");
            }

            if (TypeScriptLanguage.IsReservedKeyword(result))
            {
                throw new ArgumentException($"The {property.DeclaringType.FullName}.{property.Name} property results in an invalid field name with the {options.PropertyNameStyle} name style: {result}.");
            }

            return(result);
        }
コード例 #2
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));
        }
コード例 #3
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));
        }
コード例 #4
0
 /// <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;
 }
コード例 #5
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);
        }
コード例 #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));
        }