public TypeScriptType BuildAndImportType(TypeScriptUnit targetUnit, IAttributeProvider?attributeProvider, ITypeInfo typeInfo) { var(isNullable, resultType) = TypeScriptGeneratorHelpers.ProcessNullable(attributeProvider, typeInfo, Options.NullabilityMode); var targetType = GetTypeScriptType(targetUnit, resultType, attributeProvider); return(TypeScriptGeneratorHelpers.BuildTargetNullableTypeByOptions(targetType, isNullable, Options)); }
public TypeScriptType BuildAndImportType([NotNull] TypeScriptUnit targetUnit, [CanBeNull] ICustomAttributeProvider customAttributeProvider, [NotNull] Type type) { var(isNullable, resultType) = TypeScriptGeneratorHelpers.ProcessNullable(customAttributeProvider, type, Options.NullabilityMode); var targetType = GetTypeScriptType(targetUnit, resultType, customAttributeProvider); return(TypeScriptGeneratorHelpers.BuildTargetNullableTypeByOptions(targetType, isNullable, Options)); }
private TypeScriptType GetMaybeNullableComplexType(TypeScriptUnit unit, ITypeInfo type, IPropertyInfo property, bool isNullable) { var propertyType = BuildAndImportType(unit, property, type); if (property.PropertyType.IsGenericParameter) { propertyType = new TypeScriptTypeReference(property.PropertyType.Name); } return(TypeScriptGeneratorHelpers.BuildTargetNullableTypeByOptions(propertyType, isNullable, Options)); }
public virtual TypeScriptTypeMemberDeclaration?ResolveProperty(TypeScriptUnit unit, ITypeGenerator typeGenerator, ITypeInfo typeInfo, IPropertyInfo propertyInfo) { foreach (var propertyResolver in propertyResolvers) { var result = propertyResolver.ResolveProperty(unit, typeGenerator, typeInfo, propertyInfo); if (result != null) { return(result); } } return(null); }
private TypeScriptType GetTypeScriptType(TypeScriptUnit targetUnit, ITypeInfo typeInfo, IAttributeProvider?attributeProvider) { if (typeDeclarations.ContainsKey(typeInfo)) { return(typeDeclarations[typeInfo].ReferenceFrom(targetUnit, this, attributeProvider)); } if (typeInfo.IsGenericTypeDefinition && typeInfo.GetGenericTypeDefinition().Equals(TypeInfo.From(typeof(Nullable <>)))) { return(new TypeScriptNullableType(GetTypeScriptType(targetUnit, typeInfo.GetGenericArguments()[0], null))); } return(ResolveType(typeInfo).ReferenceFrom(targetUnit, this, attributeProvider)); }
private TypeScriptType GetTypeScriptType([NotNull] TypeScriptUnit targetUnit, [NotNull] Type type, [CanBeNull] ICustomAttributeProvider customAttributeProvider) { customAttributeProvider = ArrayTypeBuildingContext.Accept(type) ? customAttributeProvider : null; var typeDeclarationKey = new TypeDeclarationKey(type, customAttributeProvider); if (typeDeclarations.ContainsKey(typeDeclarationKey)) { return(typeDeclarations[typeDeclarationKey].ReferenceFrom(targetUnit, this)); } if (type.IsGenericTypeDefinition && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(new TypeScriptNullableType(GetTypeScriptType(targetUnit, type.GetGenericArguments()[0], null))); } var context = ResolveType(type, customAttributeProvider); return(context.ReferenceFrom(targetUnit, this)); }
public TypeScriptTypeMemberDeclaration?ResolveProperty(TypeScriptUnit unit, ITypeInfo typeInfo, IPropertyInfo propertyInfo) { var customMemberDeclaration = customTypeGenerator.ResolveProperty(unit, this, typeInfo, propertyInfo); if (customMemberDeclaration != null) { return(customMemberDeclaration); } if (propertyInfo.IsNameDefined(nameof(ContractGeneratorIgnoreAttribute))) { return(null); } var(isNullable, trueType) = TypeScriptGeneratorHelpers.ProcessNullable(propertyInfo, propertyInfo.PropertyType, Options.NullabilityMode); return(new TypeScriptTypeMemberDeclaration { Name = propertyInfo.Name.ToLowerCamelCase(), Optional = isNullable && Options.EnableOptionalProperties, Type = GetMaybeNullableComplexType(unit, trueType, propertyInfo, isNullable), }); }
public TypeScriptTypeMemberDeclaration ResolveProperty([NotNull] TypeScriptUnit unit, [NotNull] Type type, [NotNull] PropertyInfo property) { var customMemberDeclaration = customTypeGenerator.ResolveProperty(unit, this, type, property); if (customMemberDeclaration != null) { return(customMemberDeclaration); } if (property.GetCustomAttributes <ContractGeneratorIgnoreAttribute>().Any()) { return(null); } var(isNullable, trueType) = TypeScriptGeneratorHelpers.ProcessNullable(property, property.PropertyType, Options.NullabilityMode); return(new TypeScriptTypeMemberDeclaration { Name = property.Name.ToLowerCamelCase(), Optional = isNullable && Options.EnableOptionalProperties, Type = GetMaybeNullableComplexType(unit, trueType, property, isNullable), }); }
public TypeScriptTypeMemberDeclaration?ResolveProperty(TypeScriptUnit unit, ITypeInfo typeInfo, IPropertyInfo propertyInfo) { var customMemberDeclaration = customTypeGenerator.ResolveProperty(unit, this, typeInfo, propertyInfo); if (customMemberDeclaration != null) { return(customMemberDeclaration); } if (propertyInfo.IsNameDefined(nameof(ContractGeneratorIgnoreAttribute))) { return(null); } var typeScriptType = this.BuildAndImportType(unit, propertyInfo.PropertyType); return(new TypeScriptTypeMemberDeclaration { Name = propertyInfo.Name.ToLowerCamelCase(), Optional = typeScriptType is INullabilityWrapperType && Options.EnableOptionalProperties, Type = typeScriptType, }); }
public TypeScriptTypeReference AddTypeImport(ITypeInfo sourceType, TypeScriptTypeDeclaration typeDeclaration, TypeScriptUnit sourceUnit) { if (sourceUnit != this && !imports.ContainsKey(sourceType)) { imports.Add(sourceType, new TypeScriptImportFromUnitStatement { TypeName = typeDeclaration.Name, CurrentUnit = this, TargetUnit = sourceUnit, }); } return(new TypeScriptTypeReference(typeDeclaration.Name)); }
public static TypeScriptType BuildAndImportType(this ITypeGenerator typeGenerator, TypeScriptUnit typeScriptUnit, ITypeInfo type) { return(typeGenerator.ResolveType(type).ReferenceFrom(type, typeScriptUnit, typeGenerator)); }