<PackageReference Include="NJsonSchema" Version="9.4.5" />

XmlObjectExtension

public static class XmlObjectExtension
Extension methods to help out generating XMLObject structure to schema.
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace NJsonSchema.Infrastructure { public static class XmlObjectExtension { public static void GenerateXmlObjectForType(this JsonSchema4 schema, Type type) { List<Attribute> list = type.GetTypeInfo().GetCustomAttributes().ToList(); if (list.Any()) { dynamic val = list.TryGetIfAssignableTo("System.Xml.Serialization.XmlTypeAttribute", TypeNameStyle.FullName); if (val != null) XmlObjectExtension.GenerateXmlObject(val.TypeName, val.Namespace, false, false, schema); } } public static void GenerateXmlObjectForItemType(this JsonSchema4 schema, Type type) { if (schema.Xml == null) GenerateXmlObject(type.get_Name(), null, false, false, schema); } public static void GenerateXmlObjectForProperty(this JsonProperty propertySchema, Type type, string propertyName, IEnumerable<Attribute> attributes) { string text = null; string namespace = null; bool flag = false; if (propertySchema.Type == JsonObjectType.Array) { dynamic val = attributes.TryGetIfAssignableTo("System.Xml.Serialization.XmlArrayAttribute", TypeNameStyle.FullName); if (val != null) { text = (string)val.ElementName; namespace = (string)val.Namespace; } dynamic val2 = attributes.TryGetIfAssignableTo("System.Xml.Serialization.XmlArrayItemAttribute", TypeNameStyle.FullName); if (val2 != null) { dynamic val3 = val2.ElementName; dynamic val4 = val2.Namespace; XmlObjectExtension.GenerateXmlObject(val3, val4, true, false, propertySchema.Item); } flag = true; } dynamic val5 = attributes.TryGetIfAssignableTo("System.Xml.Serialization.XmlElementAttribute", TypeNameStyle.FullName); if (val5 != null) { text = (string)val5.ElementName; namespace = (string)val5.Namespace; } dynamic val6 = attributes.TryGetIfAssignableTo("System.Xml.Serialization.XmlAttributeAttribute", TypeNameStyle.FullName); if (val6 != null) { if ((!string.IsNullOrEmpty(val6.AttributeName))) text = (string)val6.AttributeName; if ((!string.IsNullOrEmpty(val6.Namespace))) namespace = (string)val6.Namespace; } if (string.IsNullOrEmpty(text) && propertySchema.Type == JsonObjectType.None) { dynamic val7 = type.GetTypeInfo().GetCustomAttributes().TryGetIfAssignableTo("System.Xml.Serialization.XmlTypeAttribute", TypeNameStyle.FullName); if (val7 != null) text = propertyName; } if (!string.IsNullOrEmpty(text) | flag) GenerateXmlObject(text, namespace, flag, (val6 != null) ? true : false, propertySchema); } private static void GenerateXmlObject(string name, string namespace, bool wrapped, bool isAttribute, JsonSchema4 schema) { schema.Xml = new JsonXmlObject { Name = name, Wrapped = wrapped, Namespace = namespace, ParentSchema = schema, Attribute = isAttribute }; } } }