コード例 #1
0
        public ISchemaSimpleTypeExecutor Build([NotNull] SchemaSimpleType schemaSimpleType)
        {
            var executor = (ISchemaSimpleTypeExecutor)executors[schemaSimpleType];

            if (executor == null)
            {
                lock (executorsLock)
                {
                    executor = (ISchemaSimpleTypeExecutor)executors[schemaSimpleType];
                    if (executor == null)
                    {
                        executors[schemaSimpleType] = executor = BuildNoLock(schemaSimpleType);
                    }
                }
            }
            return(executor);
        }
コード例 #2
0
        public SchemaSimpleTypeExecutor([CanBeNull] ISchemaSimpleTypeExecutor baseExecutor, [NotNull] SchemaSimpleType schemaSimpleType)
            : base(baseExecutor)
        {
            this.schemaSimpleType = schemaSimpleType;
            var restriction = schemaSimpleType.Restriction;

            if (restriction != null)
            {
                length    = restriction.Length;
                minLength = restriction.MinLength;
                maxLength = restriction.MaxLength;
                var atomicBaseType = schemaSimpleType.AtomicBaseType;
                if (ReferenceEquals(atomicBaseType, SchemaSimpleType.Integer) ||
                    ReferenceEquals(atomicBaseType, SchemaSimpleType.Int) ||
                    ReferenceEquals(atomicBaseType, SchemaSimpleType.Decimal))
                {
                    minInclusiveDecimal = ParseDecimal(restriction.MinInclusive);
                    minExclusiveDecimal = ParseDecimal(restriction.MinExclusive);
                    maxInclusiveDecimal = ParseDecimal(restriction.MaxInclusive);
                    maxExclusiveDecimal = ParseDecimal(restriction.MaxExclusive);
                    isNumber            = true;
                }
                if (ReferenceEquals(atomicBaseType, SchemaSimpleType.Date) ||
                    ReferenceEquals(atomicBaseType, SchemaSimpleType.GYear) ||
                    ReferenceEquals(atomicBaseType, SchemaSimpleType.GMonth))
                {
                    if (ReferenceEquals(atomicBaseType, SchemaSimpleType.Date))
                    {
                        typeCode = DateTimeTypeCode.Date;
                    }
                    else if (ReferenceEquals(atomicBaseType, SchemaSimpleType.GYear))
                    {
                        typeCode = DateTimeTypeCode.GYear;
                    }
                    else if (ReferenceEquals(atomicBaseType, SchemaSimpleType.GMonth))
                    {
                        typeCode = DateTimeTypeCode.GMonth;
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                    minInclusiveDate = ParseDate(restriction.MinInclusive, typeCode);
                    minExclusiveDate = ParseDate(restriction.MinExclusive, typeCode);
                    maxInclusiveDate = ParseDate(restriction.MaxInclusive, typeCode);
                    maxExclusiveDate = ParseDate(restriction.MaxExclusive, typeCode);
                }
                totalDigits    = restriction.TotalDigits;
                fractionDigits = restriction.FractionDigits;
                if (fractionDigits != null && totalDigits == null)
                {
                    throw new InvalidOperationException("The 'totalDigits' facet must be specified along with the 'fractionDigits' facet");
                }
                regexes = (restriction.Patterns ?? new string[0]).Select(SchemaRegexParser.Parse).ToArray();
                if (restriction.Patterns != null && restriction.Patterns.Length > 0)
                {
                    if (!string.IsNullOrEmpty(restriction.PatternDescription))
                    {
                        patternDescription = restriction.PatternDescription;
                    }
                    else if (schemaSimpleType.Description != null && schemaSimpleType.Description.Length > 0)
                    {
                        patternDescription = string.Join("; ", schemaSimpleType.Description);
                    }
                    else
                    {
                        patternDescription = GetPatternsDescription(restriction.Patterns);
                    }
                }
                if (!isNumber)
                {
                    if (typeCode == DateTimeTypeCode.None)
                    {
                        stringValues = restriction.Values == null || restriction.Values.Length == 0
                                           ? null
                                           : new HashSet <string>(restriction.Values);
                    }
                    else
                    {
                        xsdDateTimeValues = restriction.Values == null || restriction.Values.Length == 0
                                                ? null
                                                : restriction.Values.Select(s => string.IsNullOrEmpty(s) ? null : XsdDateTimeWrapper.Parse(s, typeCode)).ToList();
                    }
                }
                else
                {
                    decimalValues = restriction.Values == null || restriction.Values.Length == 0
                                        ? null
                                        : restriction.Values.Select(s => decimal.Parse(s, decimalStyle, CultureInfo.InvariantCulture)).ToList();
                }
                switch (restriction.WhiteSpace)
                {
                case SchemaSimpleTypeRestriction.WhiteSpaceEnum.Replace:
                    prepareValue = CDataNormalize;
                    break;

                case SchemaSimpleTypeRestriction.WhiteSpaceEnum.Collapse:
                    prepareValue = NonCDataNormalize;
                    break;
                }
            }
        }
コード例 #3
0
        private ISchemaSimpleTypeExecutor BuildNoLock([NotNull] SchemaSimpleType schemaSimpleType)
        {
            var baseExecutor = schemaSimpleType.BaseType == null ? null : Build((SchemaSimpleType)schemaSimpleType.BaseType);

            return(new SchemaSimpleTypeExecutor(baseExecutor, schemaSimpleType));
        }