public TypeScriptGenerator([NotNull] TypeScriptGenerationOptions options, [NotNull] ICustomTypeGenerator customTypeGenerator, [NotNull] IRootTypesProvider rootTypesProvider) { Options = options ?? throw new ArgumentNullException(nameof(options)); this.customTypeGenerator = customTypeGenerator ?? throw new ArgumentNullException(nameof(customTypeGenerator)); rootTypes = rootTypesProvider?.GetRootTypes() ?? throw new ArgumentNullException(nameof(rootTypesProvider)); typeUnitFactory = new DefaultTypeScriptGeneratorOutput(); typeDeclarations = new Dictionary <TypeDeclarationKey, ITypeBuildingContext>(); }
public TypeScriptGenerator(TypeScriptGenerationOptions options, ICustomTypeGenerator customTypeGenerator, IRootTypesProvider typesProvider, ITypeInfo[] types = null) { Options = options ?? throw new ArgumentNullException(nameof(options)); TypesProvider = typesProvider ?? throw new ArgumentNullException(nameof(typesProvider)); this.customTypeGenerator = customTypeGenerator ?? throw new ArgumentNullException(nameof(customTypeGenerator)); rootTypes = typesProvider?.GetRootTypes() ?? throw new ArgumentNullException(nameof(typesProvider)); typeUnitFactory = new DefaultTypeScriptGeneratorOutput(); typeDeclarations = new Dictionary <ITypeInfo, ITypeBuildingContext>(); }
private static void ValidateOptions(TypeScriptGenerationOptions options, JavaScriptTypeChecker?javaScriptTypeChecker = null) { if (javaScriptTypeChecker == JavaScriptTypeChecker.Flow && options.EnumGenerationMode == EnumGenerationMode.TypeScriptEnum) { throw new ArgumentException("Flow is not compatible with TypeScript enums"); } const string enumName = "Enum"; if (options.Pluralize == null || string.IsNullOrEmpty(options.Pluralize(enumName)) || enumName == options.Pluralize(enumName)) { throw new ArgumentException("Invalid Pluralize function: Pluralize cannot return null, empty string or unchanged argument"); } }
public static TypeScriptType BuildTargetNullableTypeByOptions(TypeScriptType innerType, bool isNullable, TypeScriptGenerationOptions options) { if (!(innerType is INullabilityWrapperType) && isNullable && options.EnableExplicitNullability) { if (!options.UseGlobalNullable) { return(new TypeScriptOrNullType(innerType)); } if (options.UseGlobalNullable) { return(new TypeScriptNullableType(innerType)); } } return(innerType); }