/// <summary>Gets the default value code.</summary> /// <param name="schema">The schema.</param> /// <param name="allowsNull">Specifies whether the default value assignment also allows null.</param> /// <param name="targetType">The type of the target.</param> /// <param name="typeNameHint">The type name hint to use when generating the type and the type name is missing.</param> /// <param name="useSchemaDefault">if set to <c>true</c> uses the default value from the schema if available.</param> /// <param name="typeResolver">The type resolver.</param> /// <returns>The code.</returns> public virtual string GetDefaultValue(JsonSchema4 schema, bool allowsNull, string targetType, string typeNameHint, bool useSchemaDefault, TypeResolverBase typeResolver) { if (schema.Default == null || !useSchemaDefault) { return(null); } var actualSchema = schema is JsonProperty ? ((JsonProperty)schema).ActualTypeSchema : schema.ActualSchema; if (actualSchema.IsEnumeration && !actualSchema.Type.HasFlag(JsonObjectType.Object) && actualSchema.Type != JsonObjectType.None) { return(GetEnumDefaultValue(schema, actualSchema, typeNameHint, typeResolver)); } if (schema.Type.HasFlag(JsonObjectType.String)) { return("\"" + ConversionUtilities.ConvertToStringLiteral(schema.Default.ToString()) + "\""); } if (schema.Type.HasFlag(JsonObjectType.Boolean)) { return(schema.Default.ToString().ToLowerInvariant()); } if (schema.Type.HasFlag(JsonObjectType.Integer) || schema.Type.HasFlag(JsonObjectType.Number)) { return(GetNumericValue(schema.Type, schema.Default, schema.Format)); } return(null); }
/// <summary>Generates the additional objects JavaScript code.</summary> /// <param name="additionalSettings">The additional settings.</param> /// <returns>The code.</returns> protected string GenerateAdditionalSettings(IDictionary <string, object> additionalSettings) { var code = ""; foreach (var pair in additionalSettings) { code += pair.Key + ": " + (pair.Value is string? "\"" + ConversionUtilities.ConvertToStringLiteral((string)pair.Value) + "\"" : pair.Value is bool?pair.Value.ToString().ToLowerInvariant() : string.Format(CultureInfo.InvariantCulture, "{0}", pair.Value)) + ", \n "; } return(code); }