private List<Constraint> ConvertToConstraints(XmlSchemaObject restriction, MetadataAttribute attr)
{
List<Constraint> constraints = new List<Constraint>();
/// XmlSchemaSimpleTypeRestriction
if (restriction is XmlSchemaSimpleTypeRestriction)
{
XmlSchemaSimpleTypeRestriction simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)restriction;
// if content of simpletype is a restriction
if (restriction != null)
{
// if the simpletype is a domin constraint
if (XmlSchemaUtility.IsEnumerationType(simpleTypeRestriction))
{
constraints.Add(GetDomainConstraint(simpleTypeRestriction, attr, GetDescription(simpleTypeRestriction.Annotation)));
}
else
{
foreach (XmlSchemaObject facet in simpleTypeRestriction.Facets)
{
Constraint c = ConvertFacetToConstraint(facet, attr, constraints);
if (c != null)
constraints.Add(c);
}
}
}
}
/// XmlSchemaSimpleContentRestriction
if (restriction is XmlSchemaSimpleContentRestriction)
{
XmlSchemaSimpleContentRestriction simpleContentRestriction = (XmlSchemaSimpleContentRestriction)restriction;
// if content of simpletype is a restriction
if (restriction != null)
{
// if the simpletype is a domin constraint
if (XmlSchemaUtility.IsEnumerationType(simpleContentRestriction))
{
constraints.Add(GetDomainConstraint(simpleContentRestriction, attr, GetDescription(simpleContentRestriction.Annotation)));
}
else
{
foreach (XmlSchemaObject facet in simpleContentRestriction.Facets)
{
Constraint c = ConvertFacetToConstraint(facet, attr, constraints);
if (c != null)
constraints.Add(c);
}
}
}
}
return constraints;
}