コード例 #1
0
        private int?ParseMaxLength(XsdItem xsdItem)
        {
            var maxStr    = xsdItem.MaxLength;
            int?maxLength = null;

            // Oddball case hackery...
            if (maxStr == "max")
            {
                logger.LogWarning($"MaxLength for {xsdItem.Name} is 'max', which really should not be supported.");
                maxLength = 999;   // got a better idea?
            }
            else if (!string.IsNullOrEmpty(maxStr))
            {
                // Ok, we should have a number...
                int i;
                if (int.TryParse(maxStr, out i))
                {
                    maxLength = i;
                }
                else
                {
                    // TODO - improve this error message
                    throw new LoaderException($"Malformed max length ({maxStr}) for {xsdItem.Name}.");
                }
            }

            return(maxLength);
        }
コード例 #2
0
 private void ProcessEnums(XsdItem item, CsvRow row)
 {
     if ((item.DataType == "NMTOKEN") && !string.IsNullOrEmpty(row.EnumValues))
     {
         item.EnumValues.AddRange(row.EnumValues.Split('|').Select(x => x.Trim()));
     }
 }
コード例 #3
0
        private void ProcessSimpleType(XsdItem xsdItem, XmlSchemaSimpleType simpleType)
        {
            xsdItem.DataType = simpleType.Datatype.ValueType.Name;

            var restriction = (XmlSchemaSimpleTypeRestriction)simpleType.Content;

            if (restriction != null)
            {
                var maxLengthFacet = restriction.Facets.OfType <XmlSchemaMaxLengthFacet>().FirstOrDefault();
                if (maxLengthFacet != null)
                {
                    xsdItem.MaxLength = maxLengthFacet.Value;
                }

                foreach (var ev in restriction.Facets.OfType <XmlSchemaEnumerationFacet>())
                {
                    xsdItem.EnumValues.Add(ev.Value);

                    // A little hacky...is there a better way?
                    xsdItem.DataType = "NMTOKEN";
                }
            }
        }