private static XmlSchemaSimpleTypeRestriction ExtractNumberAndIntegerFacets(JsonSchema jSchema, TypeKeyword type) { XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction(); double? minValue = GetterExtensions.Minimum(jSchema); double? minExclusiveValue = GetterExtensions.ExclusiveMinimum(jSchema); if (type.Value == JsonSchemaType.Number) { content.BaseTypeName = new XmlQualifiedName("decimal", XML_SCHEMA_NS); } else if (type.Value == JsonSchemaType.Integer) { if (minValue != null && minValue == 0.0) { content.BaseTypeName = new XmlQualifiedName("positiveInteger", XML_SCHEMA_NS); } else { content.BaseTypeName = new XmlQualifiedName("integer", XML_SCHEMA_NS); } } if (minValue != null || minExclusiveValue != null) { if (minValue != null) { XmlSchemaMinInclusiveFacet facet = new XmlSchemaMinInclusiveFacet { Value = FormatDouble((double)minValue), }; content.Facets.Add(facet); } else { XmlSchemaMinExclusiveFacet facet = new XmlSchemaMinExclusiveFacet { Value = FormatDouble((double)minExclusiveValue), }; content.Facets.Add(facet); } } double? maxValue = GetterExtensions.Maximum(jSchema); double? maxExclusiveValue = GetterExtensions.ExclusiveMaximum(jSchema); if (maxValue != null || maxExclusiveValue != null) { if (maxValue != null) { XmlSchemaMaxInclusiveFacet maxInclusiveFacet = new XmlSchemaMaxInclusiveFacet { Value = FormatDouble((double)maxValue), }; content.Facets.Add(maxInclusiveFacet); } else { XmlSchemaMaxExclusiveFacet maxExclusiveFacet = new XmlSchemaMaxExclusiveFacet { Value = FormatDouble((double)maxExclusiveValue), }; content.Facets.Add(maxExclusiveFacet); } } return content; }
private static XmlSchemaSimpleTypeRestriction ExtractNumberAndIntegerFacets(JsonSchema jSchema, TypeKeyword type) { XmlSchemaSimpleTypeRestriction content = new XmlSchemaSimpleTypeRestriction(); double?minValue = GetterExtensions.Minimum(jSchema); double?minExclusiveValue = GetterExtensions.ExclusiveMinimum(jSchema); if (type.Value == JsonSchemaType.Number) { content.BaseTypeName = new XmlQualifiedName("decimal", XML_SCHEMA_NS); } else if (type.Value == JsonSchemaType.Integer) { if (minValue != null && minValue == 1) { content.BaseTypeName = new XmlQualifiedName("positiveInteger", XML_SCHEMA_NS); } else { content.BaseTypeName = new XmlQualifiedName("integer", XML_SCHEMA_NS); } } double?maxValue = GetterExtensions.Maximum(jSchema); double?maxExclusiveValue = GetterExtensions.ExclusiveMaximum(jSchema); Regex regex = new Regex("^[9]+$"); if ((minValue != null && maxValue != null) && Math.Abs((double)minValue).Equals(maxValue) && regex.IsMatch(maxValue.ToString())) { XmlSchemaTotalDigitsFacet facet = new XmlSchemaTotalDigitsFacet { Value = FormatDouble(maxValue.ToString().Length), }; content.Facets.Add(facet); } else { if (minValue != null || minExclusiveValue != null) { if (minValue != null) { XmlSchemaMinInclusiveFacet facet = new XmlSchemaMinInclusiveFacet { Value = FormatDouble((double)minValue), }; content.Facets.Add(facet); } else { XmlSchemaMinExclusiveFacet facet = new XmlSchemaMinExclusiveFacet { Value = FormatDouble((double)minExclusiveValue), }; content.Facets.Add(facet); } } if (maxValue != null || maxExclusiveValue != null) { if (maxValue != null) { XmlSchemaMaxInclusiveFacet maxInclusiveFacet = new XmlSchemaMaxInclusiveFacet { Value = FormatDouble((double)maxValue), }; content.Facets.Add(maxInclusiveFacet); } else { XmlSchemaMaxExclusiveFacet maxExclusiveFacet = new XmlSchemaMaxExclusiveFacet { Value = FormatDouble((double)maxExclusiveValue), }; content.Facets.Add(maxExclusiveFacet); } } } return(content); }