/// <summary>
        ///     Includes specified types to resulting typing exported as TypeScript enumerations
        /// </summary>
        /// <param name="builder">Configuration builder</param>
        /// <param name="types">Types to include</param>
        /// <param name="configuration">Configuration to be applied to each type</param>
        /// <returns>Fluent</returns>
        public static void ExportAsEnums(this ConfigurationBuilder builder, IEnumerable <Type> types,
                                         Action <EnumExportBuilder> configuration = null)
        {
            foreach (var type in types)
            {
                var untypedConf = builder.TypeExportBuilders.GetOrCreate(type, () =>
                {
                    var bp = builder.GetCheckedBlueprint <TsEnumAttribute>(type);
                    var t  = typeof(EnumExportBuilder <>).MakeGenericType(type);
                    return((EnumExportBuilder)t.InstanceInternal(bp));
                });

                var conf = untypedConf as EnumExportBuilder;
                if (conf == null)
                {
                    ErrorMessages.RTE0017_FluentContradict.Throw(type, "enum");
                }

                if (configuration != null)
                {
                    try
                    {
                        configuration(conf);
                    }
                    catch (Exception ex)
                    {
                        ErrorMessages.RTE0006_FluentSingleError.Throw(ex.Message, "enum", type.FullName);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Includes specified type to resulting typing exported as TypeScript class
        /// </summary>
        /// <typeparam name="T">Type to include</typeparam>
        /// <param name="builder">Configuration builder</param>
        /// <returns>Fluent</returns>
        public static InterfaceExportBuilder <T> ExportAsInterface <T>(this ConfigurationBuilder builder)
        {
            var bp = builder.GetCheckedBlueprint <TsInterfaceAttribute>(typeof(T));

            var conf =
                builder.TypeExportBuilders.GetOrCreate(typeof(T), () => new InterfaceExportBuilder <T>(bp))
                as InterfaceExportBuilder <T>;

            if (conf == null)
            {
                ErrorMessages.RTE0017_FluentContradict.Throw(typeof(T), "interface");
            }

            return(conf);
        }
        /// <summary>
        ///     Includes specified type to resulting typing exported as TypeScript enumeration
        /// </summary>
        /// <typeparam name="T">Type to include</typeparam>
        /// <param name="builder">Configuration builder</param>
        /// <returns>Fluent</returns>
        public static EnumExportBuilder <T> ExportAsEnum <T>(this ConfigurationBuilder builder)
            where T : struct
        {
            var bp   = builder.GetCheckedBlueprint <TsEnumAttribute>(typeof(T));
            var conf =
                builder.TypeExportBuilders.GetOrCreate(typeof(T), () => new EnumExportBuilder <T>(bp))
                as EnumExportBuilder <T>;

            if (conf == null)
            {
                ErrorMessages.RTE0017_FluentContradict.Throw(typeof(T), "enum");
            }

            return(conf);
        }