Example #1
0
        public TypeScriptFluent WithFormatter(TsSimpleMemberTypeFormatter formatter)
        {
            TsMemberTypeFormatter tsMemberTypeFormatter =
                (tsProperty, memberTypeName) => {
                var asCollection = tsProperty.PropertyType as TsCollection;
                var isCollection = asCollection != null;

                return(isCollection
                                                ? formatter(memberTypeName, true, asCollection.Dimension)
                                                : formatter(memberTypeName, false));
            };

            _scriptGenerator.SetMemberTypeFormatter(tsMemberTypeFormatter);

            return(this);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the TsGenerator class with the default formatters.
        /// </summary>
        public TsGenerator()
        {
            _references       = new List <string>();
            _generatedClasses = new HashSet <TsClass>();
            _generatedEnums   = new HashSet <TsEnum>();

            _typeFormatters = new TsTypeFormatterCollection();
            _typeFormatters.RegisterTypeFormatter <TsClass>((type, formatter) =>
            {
                var tsClass = ((TsClass)type);
                if (!tsClass.GenericArguments.Any())
                {
                    return(tsClass.Name);
                }
                return(tsClass.Name + "<" + string.Join(", ", tsClass.GenericArguments.Select(a => a as TsCollection != null ? this.GetFullyQualifiedTypeName(a) + "[]" : this.GetFullyQualifiedTypeName(a))) + ">");
            });
            _typeFormatters.RegisterTypeFormatter <TsSystemType>((type, formatter) => ((TsSystemType)type).Kind.ToTypeScriptString());
            _typeFormatters.RegisterTypeFormatter <TsCollection>((type, formatter) =>
            {
                var itemType = ((TsCollection)type).ItemsType;
                if (!(itemType is TsClass itemTypeAsClass) || !itemTypeAsClass.GenericArguments.Any())
                {
                    return(this.GetTypeName(itemType));
                }
                return(this.GetTypeName(itemType));
            });
            _typeFormatters.RegisterTypeFormatter <TsEnum>((type, formatter) => ((TsEnum)type).Name);

            _typeConvertors = new TypeConvertorCollection();

            _docAppender = new NullDocAppender();

            _memberFormatter         = DefaultMemberFormatter;
            _memberTypeFormatter     = DefaultMemberTypeFormatter;
            _typeVisibilityFormatter = DefaultTypeVisibilityFormatter;
            _moduleNameFormatter     = DefaultModuleNameFormatter;

            this.IndentationString  = "\t";
            this.GenerateConstEnums = true;
            this.Mode     = TsGenerationModes.Definitions;
            this.EnumMode = TsEnumModes.Number;
        }
Example #3
0
 /// <summary>
 /// Registers a formatter for member types
 /// </summary>
 /// <param name="formatter">The formatter to register</param>
 /// <returns>Instance of the TypeScriptFluent that enables fluent configuration.</returns>
 public TypeScriptFluent WithMemberTypeFormatter(TsMemberTypeFormatter formatter)
 {
     _scriptGenerator.SetMemberTypeFormatter(formatter);
     return(this);
 }
Example #4
0
 /// <summary>
 /// Sets the formatter for class member types.
 /// </summary>
 /// <param name="formatter">The formatter to register.</param>
 public void SetMemberTypeFormatter(TsMemberTypeFormatter formatter)
 {
     _memberTypeFormatter = formatter;
 }
Example #5
0
 /// <summary>
 /// Registers a formatter for member types
 /// </summary>
 /// <param name="formatter">The formatter to register</param>
 /// <returns>Instance of the TypeScriptFluent that enables fluent configuration.</returns>
 public DefinitionOptionsBuilder WithMemberTypeFormatter(TsMemberTypeFormatter formatter)
 {
     Generator.Options.MemberTypeFormatter = formatter;
     return(this);
 }