/// <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)).ToArray()) + ">"); }); _typeFormatters.RegisterTypeFormatter <TsSystemType>((type, formatter) => ((TsSystemType)type).Kind.ToTypeScriptString()); _typeFormatters.RegisterTypeFormatter <TsCollection>((type, formatter) => { var itemType = ((TsCollection)type).ItemsType; var itemTypeAsClass = itemType as TsClass; if (itemTypeAsClass == null || !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 = " "; this.GenerateConstEnums = true; // AGW _suppressModules = new List <string>(); }
/// <summary> /// Registers the formatter for the specific TsType /// </summary> /// <typeparam name="TFor">The type to register the formatter for. TFor is restricted to TsType and derived classes.</typeparam> /// <param name="formatter">The formatter to register</param> /// <remarks> /// If a formatter for the type is already registered, it is overwritten with the new value. /// </remarks> public void RegisterTypeFormatter <TFor>(TsTypeFormatter formatter) where TFor : TsType { _typeFormatters.RegisterTypeFormatter <TFor>(formatter); }