Skip to content

Commit

Permalink
Merge branch 'las-nsc-las/non-nullable-arrays'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Jun 16, 2022
2 parents 961b3a2 + c7c13a1 commit 0ed7e5c
Show file tree
Hide file tree
Showing 4 changed files with 789 additions and 853 deletions.
44 changes: 10 additions & 34 deletions XmlSchemaClassGenerator/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;

namespace XmlSchemaClassGenerator
Expand All @@ -12,31 +9,18 @@ public static class Extensions
{
public static XmlSchema GetSchema(this XmlSchemaObject xmlSchemaObject)
{
while (xmlSchemaObject != null && !(xmlSchemaObject is XmlSchema))
while (xmlSchemaObject is not null and not XmlSchema)
xmlSchemaObject = xmlSchemaObject.Parent;
return (XmlSchema)xmlSchemaObject;
}

public static PropertyValueTypeCode GetPropertyValueTypeCode(this TypeModel model)
public static PropertyValueTypeCode GetPropertyValueTypeCode(this TypeModel model) => model switch
{
if (model is not SimpleModel simpleType)
{
if (!(model is EnumModel))
{
return PropertyValueTypeCode.Other;
}
return PropertyValueTypeCode.ValueType;
}
if (simpleType.ValueType.IsArray)
{
return PropertyValueTypeCode.Array;
}
if (simpleType.ValueType.IsValueType)
{
return PropertyValueTypeCode.ValueType;
}
return PropertyValueTypeCode.Other;
}
SimpleModel { ValueType.IsArray: true } => PropertyValueTypeCode.Array,
SimpleModel { ValueType.IsValueType: true } => PropertyValueTypeCode.ValueType,
SimpleModel or not EnumModel => PropertyValueTypeCode.Other,
_ => PropertyValueTypeCode.ValueType
};

public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> propertySelector)
{
Expand All @@ -45,17 +29,9 @@ public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TS

public static string QuoteIfNeeded(this string text)
{
if (string.IsNullOrEmpty(text))
{
return text;
}

if (text.Contains(" "))
{
return "\"" + text + "\"";
}

return text;
return string.IsNullOrEmpty(text) ? text
: text.Contains(" ") ? "\"" + text + "\""
: text;
}
}
}
81 changes: 81 additions & 0 deletions XmlSchemaClassGenerator/IXmlSchemaNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System.Xml;
using System.Xml.Schema;

namespace XmlSchemaClassGenerator
{
public interface IXmlSchemaNode
{
//string Name { get; }
string DefaultValue { get; }
string FixedValue { get; }
XmlSchemaForm Form { get; }
XmlQualifiedName QualifiedName { get; }
XmlQualifiedName RefName { get; }
//XmlQualifiedName SchemaTypeName { get; }
//XmlSchemaType SchemaType { get; }
//XmlSchemaType NodeSchemaType { get; }

XmlSchemaAnnotated Base { get; }
XmlSchemaForm FormDefault { get; }
}

public sealed class XmlSchemaAttributeEx : IXmlSchemaNode
{
private XmlSchemaAttributeEx(XmlSchemaAttribute xs) => Real = xs;

public XmlSchemaAttribute Real { get; }

//public string Name => Real.Name;
public string DefaultValue => Real.DefaultValue;
public string FixedValue => Real.FixedValue;
public XmlSchemaForm Form => Real.Form;
public XmlQualifiedName QualifiedName => Real.QualifiedName;
public XmlQualifiedName RefName => Real.RefName;
//public XmlQualifiedName SchemaTypeName => Real.SchemaTypeName;
//public XmlSchemaSimpleType SchemaType => Real.SchemaType;
public XmlSchemaSimpleType AttributeSchemaType => Real.AttributeSchemaType;

public XmlSchemaAnnotated Base => Real;

public XmlSchemaForm FormDefault => Base.GetSchema().AttributeFormDefault;

//XmlSchemaType IXmlSchemaNode.SchemaType => SchemaType;

//XmlSchemaType IXmlSchemaNode.NodeSchemaType => AttributeSchemaType;

public XmlSchemaUse Use => Real.Use;

public static implicit operator XmlSchemaAttributeEx(XmlSchemaAttribute xs) => new(xs);
public static implicit operator XmlSchemaAttribute(XmlSchemaAttributeEx ex) => ex.Real;
}

public sealed class XmlSchemaElementEx : IXmlSchemaNode
{
private XmlSchemaElementEx(XmlSchemaElement xs) => Real = xs;

public XmlSchemaElement Real { get; }

//public string Name => Real.Name;
public string DefaultValue => Real.DefaultValue;
public string FixedValue => Real.FixedValue;
public XmlSchemaForm Form => Real.Form;
public XmlQualifiedName QualifiedName => Real.QualifiedName;
public XmlQualifiedName RefName => Real.RefName;
//public XmlQualifiedName SchemaTypeName => Real.SchemaTypeName;
//public XmlSchemaType SchemaType => Real.SchemaType;
public XmlSchemaType ElementSchemaType => Real.ElementSchemaType;

public XmlSchemaAnnotated Base => Real;

public XmlSchemaForm FormDefault => Base.GetSchema().ElementFormDefault;

//XmlSchemaType IXmlSchemaNode.SchemaType => SchemaType;

//XmlSchemaType IXmlSchemaNode.NodeSchemaType => ElementSchemaType;

public bool IsNillable => Real.IsNillable;

public static implicit operator XmlSchemaElementEx(XmlSchemaElement xs) => new(xs);
public static implicit operator XmlSchemaElement(XmlSchemaElementEx ex) => ex.Real;
}
}
Loading

0 comments on commit 0ed7e5c

Please sign in to comment.