internal static CodeExpression CreateGetBuiltInSimpleType(XmlTypeCode typeCode)  {
     return CodeDomHelper.CreateMethodCall(
             new CodeTypeReferenceExpression("XmlSchemaType"),
             Constants.GetBuiltInSimpleType,
             CodeDomHelper.CreateFieldReference(Constants.XmlTypeCode, typeCode.ToString()));
             
 }
 private static bool? IsDataTypeAttributeAllowed(XmlTypeCode typeCode, GeneratorConfiguration configuration)
 {
     bool? result;
     switch (typeCode)
     {
         case XmlTypeCode.AnyAtomicType:
             // union
             result = false;
             break;
         case XmlTypeCode.Integer:
         case XmlTypeCode.NegativeInteger:
         case XmlTypeCode.NonNegativeInteger:
         case XmlTypeCode.NonPositiveInteger:
         case XmlTypeCode.PositiveInteger:
             if (configuration.IntegerDataType != null && configuration.IntegerDataType != typeof(string))
                 result = false;
             else
                 result = null;
             break;
         case XmlTypeCode.Base64Binary:
         case XmlTypeCode.HexBinary:
             result = true;
             break;
         default:
             result = null;
             break;
     }
     return result;
 }
		private void Init (DateTime value, XmlSchemaType xmlType)
		{
			if (xmlType == null)
				throw new ArgumentNullException ("xmlType");
			xmlTypeCode = XmlTypeCode.DateTime;
			this.dateTimeValue = value;
			schemaType = xmlType;
		}
예제 #4
0
		private void Init (byte [] value, XmlSchemaType xmlType)
		{
			if (xmlType == null)
				throw new ArgumentNullException ("xmlType");
			xmlTypeCode = XmlTypeCode.Base64Binary;
			this.bytesValue = value;
			schemaType = xmlType;
		}
		private void Init (bool value, XmlSchemaType xmlType)
		{
			if (xmlType == null)
				throw new ArgumentNullException ("xmlType");
			xmlTypeCode = XmlTypeCode.Boolean;
			this.booleanValue = value;
			schemaType = xmlType;
		}
 public static XmlSchemaComplexType GetBuiltInComplexType(XmlTypeCode typeCode)
 {
     if (typeCode == XmlTypeCode.Item)
     {
         return XmlSchemaComplexType.AnyType;
     }
     return null;
 }
예제 #7
0
 public XQuerySequenceType(XmlTypeCode typeCode, XmlTypeCardinality cardinality, Type clrType)
     : this(typeCode, XmlQualifiedNameTest.Wildcard)
 {
     Cardinality = cardinality;
     ParameterType = clrType;
     IsNode = TypeCodeIsNodeType(TypeCode);
     if (TypeCode != XmlTypeCode.Item && !IsNode)
         SchemaType = XmlSchemaType.GetBuiltInSimpleType(TypeCode);
 }
예제 #8
0
 private void Init(DateTime value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     this.xmlTypeCode   = XmlTypeCode.DateTime;
     this.dateTimeValue = value;
     this.schemaType    = xmlType;
 }
예제 #9
0
 public SequenceType(XmlTypeCode typeCode, XmlQualifiedNameTest nameTest, XmlSchemaType schemaType, bool isNillable = false)
 {
     TypeCode    = typeCode;
     Cardinality = XmlTypeCardinality.One;
     NameTest    = nameTest;
     SchemaType  = schemaType;
     Nillable    = isNillable;
     IsNode      = TypeCodeIsNodeType(TypeCode);
     ItemType    = TypeCodeToItemType(TypeCode, SchemaType);
 }
예제 #10
0
 /// <summary>
 /// Strongly typed indexer.
 /// </summary>
 public bool this[XmlTypeCode index1, XmlTypeCode index2]
 {
     get
     {
         return(this[(int)index1, (int)index2]);
     }
     //                set {
     //                    this[(int)index1, (int)index2] = value;
     //                }
 }
예제 #11
0
 private void Init(float value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     xmlTypeCode     = XmlTypeCode.Float;
     this.floatValue = value;
     schemaType      = xmlType;
 }
예제 #12
0
        internal static FacetsChecker GetFacetsChecker(XmlTypeCode typeCode)
        {
            if (FacetsCheckerMapping == null)
            {
                InitMapping();
            }

            return FacetsCheckerMapping[typeCode];
            
        }
예제 #13
0
 private void Init(double value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     xmlTypeCode      = XmlTypeCode.Double;
     this.doubleValue = value;
     schemaType       = xmlType;
 }
예제 #14
0
 private void Init(byte [] value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     xmlTypeCode     = XmlTypeCode.Base64Binary;
     this.bytesValue = value;
     schemaType      = xmlType;
 }
예제 #15
0
        public static XmlSchemaType GetBuiltInType(XmlTypeCode type)
        {
            XmlSchemaType t = XmlSchemaType.GetBuiltInSimpleType(type);

            if (t != null)
            {
                return(t);
            }
            return(XmlSchemaType.GetBuiltInComplexType(type));
        }
예제 #16
0
 private void Init(long value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     xmlTypeCode    = XmlTypeCode.Long;
     this.longValue = value;
     schemaType     = xmlType;
 }
예제 #17
0
 private void Init(decimal value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     this.xmlTypeCode  = XmlTypeCode.Decimal;
     this.decimalValue = value;
     this.schemaType   = xmlType;
 }
예제 #18
0
 private void Init(bool value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     xmlTypeCode       = XmlTypeCode.Boolean;
     this.booleanValue = value;
     schemaType        = xmlType;
 }
예제 #19
0
 private void Init(int value, XmlSchemaType xmlType)
 {
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     this.xmlTypeCode = XmlTypeCode.Int;
     this.intValue    = value;
     this.schemaType  = xmlType;
 }
예제 #20
0
        private static Type GetEffectiveType(XmlTypeCode typeCode, XmlSchemaDatatypeVariety variety, GeneratorConfiguration configuration)
        {
            Type result;

            switch (typeCode)
            {
            case XmlTypeCode.AnyAtomicType:
                // union
                result = typeof(string);
                break;

            case XmlTypeCode.AnyUri:
            case XmlTypeCode.Duration:
            case XmlTypeCode.GDay:
            case XmlTypeCode.GMonth:
            case XmlTypeCode.GMonthDay:
            case XmlTypeCode.GYear:
            case XmlTypeCode.GYearMonth:
                result = variety == XmlSchemaDatatypeVariety.List ? typeof(string[]) : typeof(string);
                break;

            case XmlTypeCode.Time:
                if (configuration.TimeDataType == null || configuration.TimeDataType == typeof(string))
                {
                    // default to string
                    result = typeof(string);
                }
                else
                {
                    // otherwise, use the specified type
                    result = configuration.TimeDataType;
                }
                break;

            case XmlTypeCode.Integer:
            case XmlTypeCode.NegativeInteger:
            case XmlTypeCode.NonNegativeInteger:
            case XmlTypeCode.NonPositiveInteger:
            case XmlTypeCode.PositiveInteger:
                if (configuration.IntegerDataType == null || configuration.IntegerDataType == typeof(string))
                {
                    result = typeof(string);
                }
                else
                {
                    result = configuration.IntegerDataType;
                }
                break;

            default:
                result = null;
                break;
            }
            return(result);
        }
예제 #21
0
 public SequenceType(XmlTypeCode typeCode, XmlTypeCardinality cardinality, Type clrType)
     : this(typeCode, XmlQualifiedNameTest.Wildcard)
 {
     Cardinality   = cardinality;
     ParameterType = clrType;
     IsNode        = TypeCodeIsNodeType(TypeCode);
     if (TypeCode != XmlTypeCode.Item && !IsNode)
     {
         SchemaType = XmlSchemaType.GetBuiltInSimpleType(TypeCode);
     }
 }
예제 #22
0
 public SequenceType(XmlTypeCode typeCode, XmlQualifiedNameTest nameTest)
 {
     TypeCode    = typeCode;
     Cardinality = XmlTypeCardinality.One;
     NameTest    = nameTest;
     IsNode      = TypeCodeIsNodeType(TypeCode);
     if (TypeCode != XmlTypeCode.Item && !IsNode)
     {
         SchemaType = XmlSchemaType.GetBuiltInSimpleType(TypeCode);
     }
     ItemType = TypeCodeToItemType(TypeCode, SchemaType);
 }
예제 #23
0
 public SequenceType(XmlTypeCode typeCode, IXmlSchemaInfo schemaInfo, Type clrType)
 {
     TypeCode        = typeCode;
     NameTest        = XmlQualifiedNameTest.Wildcard;
     Cardinality     = XmlTypeCardinality.One;
     SchemaType      = schemaInfo.SchemaType;
     SchemaElement   = schemaInfo.SchemaElement;
     SchemaAttribute = schemaInfo.SchemaAttribute;
     ParameterType   = clrType;
     IsNode          = TypeCodeIsNodeType(TypeCode);
     ItemType        = TypeCodeToItemType(TypeCode, SchemaType);
 }
예제 #24
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction) {
     firstPattern = true;
     regStr = null;
     pattern_facet = null;
     datatype = baseDatatype;
     derivedRestriction = restriction;
     baseFlags = datatype.Restriction != null ? datatype.Restriction.Flags : 0;
     baseFixedFlags = datatype.Restriction != null ? datatype.Restriction.FixedFlags : 0;
     validRestrictionFlags = datatype.ValidRestrictionFlags;
     nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     builtInEnum = !(datatype is Datatype_union || datatype is Datatype_List) ? datatype.TypeCode : 0;
     builtInType = (int)builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(builtInEnum).Datatype : datatype;
 }
예제 #25
0
        private Exception TryMatchAtomicType(object value, NameTable nameTable, XNamespaceResolver resolver)
        {
            XmlSchemaDatatype datatype  = DataType;
            XmlTypeCode       typeCode  = datatype.TypeCode;
            Exception         exception = null;

            try {
                datatype.ChangeType(value, DataType.ValueType, resolver);
            }
            catch (Exception e) {
                exception = e;
            }
            return(exception);
        }
예제 #26
0
        public static Type GetDotNetType(this XmlTypeCode typeCode)
        {
            var objectMapping = TypeMapper.ObjectMappings.SingleOrDefault(p => p.Value.MappedToType.AsCaseless() == typeCode.ToString());

            if (DotNetMappings.Any(p => p.Value.MappedFromType == objectMapping.Value.MappedFromType))
            {
                var dotNetMapping = DotNetMappings.Single(p => p.Value.MappedFromType == objectMapping.Value.MappedFromType);
                var type          = Type.GetType("System." + dotNetMapping.Value.MappedToType, true);

                return(type);
            }

            return(null);
        }
예제 #27
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     _firstPattern = true;
     _regStr = null;
     _pattern_facet = null;
     _datatype = baseDatatype;
     _derivedRestriction = restriction;
     _baseFlags = _datatype.Restriction != null ? _datatype.Restriction.Flags : 0;
     _baseFixedFlags = _datatype.Restriction != null ? _datatype.Restriction.FixedFlags : 0;
     _validRestrictionFlags = _datatype.ValidRestrictionFlags;
     _nonNegativeInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     _builtInEnum = !(_datatype is Datatype_union || _datatype is Datatype_List) ? _datatype.TypeCode : 0;
     _builtInType = (int)_builtInEnum > 0 ? DatatypeImplementation.GetSimpleTypeFromTypeCode(_builtInEnum).Datatype : _datatype;
 }
예제 #28
0
 public FacetsCompiler(DatatypeImplementation baseDatatype, RestrictionFacets restriction)
 {
     this.firstPattern          = true;
     this.regStr                = null;
     this.pattern_facet         = null;
     this.datatype              = baseDatatype;
     this.derivedRestriction    = restriction;
     this.baseFlags             = (this.datatype.Restriction != null) ? this.datatype.Restriction.Flags : ((RestrictionFlags)0);
     this.baseFixedFlags        = (this.datatype.Restriction != null) ? this.datatype.Restriction.FixedFlags : ((RestrictionFlags)0);
     this.validRestrictionFlags = this.datatype.ValidRestrictionFlags;
     this.nonNegativeInt        = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.NonNegativeInteger).Datatype;
     this.builtInEnum           = (!(this.datatype is Datatype_union) && !(this.datatype is Datatype_List)) ? this.datatype.TypeCode : XmlTypeCode.None;
     this.builtInType           = (this.builtInEnum > XmlTypeCode.None) ? DatatypeImplementation.GetSimpleTypeFromTypeCode(this.builtInEnum).Datatype : this.datatype;
 }
예제 #29
0
 private void Init(string value, XmlSchemaType xmlType)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (xmlType == null)
     {
         throw new ArgumentNullException("xmlType");
     }
     this.xmlTypeCode = XmlTypeCode.String;
     this.stringValue = value;
     this.schemaType  = xmlType;
 }
예제 #30
0
        internal static Type RuntimeTypeFromXmlTypeCode(XmlTypeCode typeCode)
        {
            switch (typeCode)
            {
            case XmlTypeCode.Long:
                return(typeof(long));

            case XmlTypeCode.Int:
                return(typeof(int));

            case XmlTypeCode.Short:
                return(typeof(short));

            default:
                switch (typeCode)
                {
                case XmlTypeCode.String:
                    return(typeof(string));

                case XmlTypeCode.Boolean:
                    return(typeof(bool));

                case XmlTypeCode.Decimal:
                    return(typeof(decimal));

                case XmlTypeCode.Float:
                    return(typeof(float));

                case XmlTypeCode.Double:
                    return(typeof(double));

                default:
                    if (typeCode != XmlTypeCode.Item)
                    {
                        throw new NotSupportedException(string.Format("XQuery internal error: Cannot infer Runtime Type from XmlTypeCode {0}.", typeCode));
                    }
                    return(typeof(object));

                case XmlTypeCode.DateTime:
                    return(typeof(DateTime));
                }
                break;

            case XmlTypeCode.UnsignedInt:
                return(typeof(uint));

            case XmlTypeCode.UnsignedShort:
                return(typeof(ushort));
            }
        }
        private Exception CheckBuiltInFacets(string s, XmlTypeCode typeCode, bool verifyUri)
        {
            Exception exception = null;

            switch (typeCode)
            {
            case XmlTypeCode.AnyUri:
                if (verifyUri)
                {
                    Uri uri;
                    exception = XmlConvert.TryToUri(s, out uri);
                }
                return(exception);

            case XmlTypeCode.QName:
            case XmlTypeCode.Notation:
                return(exception);

            case XmlTypeCode.NormalizedString:
                return(XmlConvert.TryVerifyNormalizedString(s));

            case XmlTypeCode.Token:
                return(XmlConvert.TryVerifyTOKEN(s));

            case XmlTypeCode.Language:
                if ((s != null) && (s.Length != 0))
                {
                    if (!LanguagePattern.IsMatch(s))
                    {
                        return(new XmlSchemaException("Sch_InvalidLanguageId", string.Empty));
                    }
                    return(exception);
                }
                return(new XmlSchemaException("Sch_EmptyAttributeValue", string.Empty));

            case XmlTypeCode.NmToken:
                return(XmlConvert.TryVerifyNMTOKEN(s));

            case XmlTypeCode.Name:
                return(XmlConvert.TryVerifyName(s));

            case XmlTypeCode.NCName:
            case XmlTypeCode.Id:
            case XmlTypeCode.Idref:
            case XmlTypeCode.Entity:
                return(XmlConvert.TryVerifyNCName(s));
            }
            return(exception);
        }
예제 #32
0
        /// <summary>
        /// Return true if the type of "item" is a subtype of the type identified by "code".
        /// </summary>
        public bool MatchesXmlType(XPathItem item, XmlTypeCode code)
        {
            // All atomic type codes appear after AnyAtomicType
            if (code > XmlTypeCode.AnyAtomicType)
            {
                return(!item.IsNode && item.XmlType.TypeCode == code);
            }

            // Handle node code and AnyAtomicType
            switch (code)
            {
            case XmlTypeCode.AnyAtomicType: return(!item.IsNode);

            case XmlTypeCode.Node: return(item.IsNode);

            case XmlTypeCode.Item: return(true);

            default:
                if (!item.IsNode)
                {
                    return(false);
                }

                switch (((XPathNavigator)item).NodeType)
                {
                case XPathNodeType.Root: return(code == XmlTypeCode.Document);

                case XPathNodeType.Element: return(code == XmlTypeCode.Element);

                case XPathNodeType.Attribute: return(code == XmlTypeCode.Attribute);

                case XPathNodeType.Namespace: return(code == XmlTypeCode.Namespace);

                case XPathNodeType.Text: return(code == XmlTypeCode.Text);

                case XPathNodeType.SignificantWhitespace: return(code == XmlTypeCode.Text);

                case XPathNodeType.Whitespace: return(code == XmlTypeCode.Text);

                case XPathNodeType.ProcessingInstruction: return(code == XmlTypeCode.ProcessingInstruction);

                case XPathNodeType.Comment: return(code == XmlTypeCode.Comment);
                }
                break;
            }

            Debug.Fail("XmlTypeCode " + code + " was not fully handled.");
            return(false);
        }
예제 #33
0
 public static bool TypeCodeIsNodeType(XmlTypeCode typeCode)
 {
     switch (typeCode)
     {
     case XmlTypeCode.Node:
     case XmlTypeCode.Element:
     case XmlTypeCode.Attribute:
     case XmlTypeCode.Document:
     case XmlTypeCode.Comment:
     case XmlTypeCode.Text:
     case XmlTypeCode.ProcessingInstruction:
         return(true);
     }
     return(false);
 }
 protected XmlBaseConverter(XmlSchemaType schemaType)
 {
     XmlSchemaDatatype datatype = schemaType.Datatype;
     while ((schemaType != null) && !(schemaType is XmlSchemaSimpleType))
     {
         schemaType = schemaType.BaseXmlSchemaType;
     }
     if (schemaType == null)
     {
         schemaType = XmlSchemaType.GetBuiltInSimpleType(datatype.TypeCode);
     }
     this.schemaType = schemaType;
     this.typeCode = schemaType.TypeCode;
     this.clrTypeDefault = schemaType.Datatype.ValueType;
 }
        private Exception CheckBuiltInFacets(string s, XmlTypeCode typeCode, bool verifyUri)
        {
            Exception exception = null;
            switch (typeCode)
            {
                case XmlTypeCode.AnyUri:
                    if (verifyUri)
                    {
                        Uri uri;
                        exception = XmlConvert.TryToUri(s, out uri);
                    }
                    return exception;

                case XmlTypeCode.QName:
                case XmlTypeCode.Notation:
                    return exception;

                case XmlTypeCode.NormalizedString:
                    return XmlConvert.TryVerifyNormalizedString(s);

                case XmlTypeCode.Token:
                    return XmlConvert.TryVerifyTOKEN(s);

                case XmlTypeCode.Language:
                    if ((s != null) && (s.Length != 0))
                    {
                        if (!LanguagePattern.IsMatch(s))
                        {
                            return new XmlSchemaException("Sch_InvalidLanguageId", string.Empty);
                        }
                        return exception;
                    }
                    return new XmlSchemaException("Sch_EmptyAttributeValue", string.Empty);

                case XmlTypeCode.NmToken:
                    return XmlConvert.TryVerifyNMTOKEN(s);

                case XmlTypeCode.Name:
                    return XmlConvert.TryVerifyName(s);

                case XmlTypeCode.NCName:
                case XmlTypeCode.Id:
                case XmlTypeCode.Idref:
                case XmlTypeCode.Entity:
                    return XmlConvert.TryVerifyNCName(s);
            }
            return exception;
        }
예제 #36
0
        protected XmlBaseConverter(XmlSchemaType schemaType)
        {
            XmlSchemaDatatype datatype = schemaType.Datatype;

            while ((schemaType != null) && !(schemaType is XmlSchemaSimpleType))
            {
                schemaType = schemaType.BaseXmlSchemaType;
            }
            if (schemaType == null)
            {
                schemaType = XmlSchemaType.GetBuiltInSimpleType(datatype.TypeCode);
            }
            this.schemaType     = schemaType;
            this.typeCode       = schemaType.TypeCode;
            this.clrTypeDefault = schemaType.Datatype.ValueType;
        }
        private static bool TryParseCode(string value, out XmlTypeCode code)
        {
            if (value != null)
            {
                try
                {
                    code = (XmlTypeCode)Enum.Parse(typeof(XmlTypeCode), value, true);
                    return(true);
                }
                catch (FormatException)
                {
                }
            }

            code = XmlTypeCode.None;
            return(false);
        }
예제 #38
0
        public QilNode ConvertToType(XmlTypeCode requiredType, QilNode n)
        {
            switch (requiredType)
            {
            case XmlTypeCode.String: return(ConvertToString(n));

            case XmlTypeCode.Double: return(ConvertToNumber(n));

            case XmlTypeCode.Boolean: return(ConvertToBoolean(n));

            case XmlTypeCode.Node: return(EnsureNodeSet(n));

            case XmlTypeCode.Item: return(n);

            default: Debug.Fail("Unexpected XmlTypeCode: " + requiredType); return(null);
            }
        }
예제 #39
0
		public static XmlTypeCode GetFallbackType (XmlTypeCode type)
		{
			switch (type) {
			case XmlTypeCode.AnyAtomicType:
				return XmlTypeCode.Item;
			case XmlTypeCode.UntypedAtomic:
				return XmlTypeCode.String;
			case XmlTypeCode.Notation:
				return XmlTypeCode.QName;
			case XmlTypeCode.NormalizedString:
			case XmlTypeCode.Token:
			case XmlTypeCode.Language:
			case XmlTypeCode.NmToken:
			case XmlTypeCode.Name:
			case XmlTypeCode.NCName:
			case XmlTypeCode.Id:
			case XmlTypeCode.Idref:
			case XmlTypeCode.Entity:
				return XmlTypeCode.String;
			case XmlTypeCode.NonPositiveInteger:
				return XmlTypeCode.Decimal;
			case XmlTypeCode.NegativeInteger:
				return XmlTypeCode.NonPositiveInteger;
			case XmlTypeCode.Long:
				return XmlTypeCode.Integer;
			case XmlTypeCode.Short:
				return XmlTypeCode.Int;
			case XmlTypeCode.Byte:
				return XmlTypeCode.Int;
			case XmlTypeCode.NonNegativeInteger:
				return XmlTypeCode.Decimal;
			case XmlTypeCode.UnsignedLong:
				return XmlTypeCode.NonNegativeInteger;
			case XmlTypeCode.UnsignedInt:
				return XmlTypeCode.Integer;
			case XmlTypeCode.UnsignedShort:
				return XmlTypeCode.Int;
			case XmlTypeCode.UnsignedByte:
				return XmlTypeCode.UnsignedShort;
			case XmlTypeCode.PositiveInteger:
				return XmlTypeCode.NonNegativeInteger;
			default:
				return XmlTypeCode.None;
			}
		}
예제 #40
0
        /// <summary>Returns the validated XML element or attribute's value as the type specified using the <see cref="T:System.Xml.IXmlNamespaceResolver" /> object specified to resolve namespace prefixes.</summary>
        /// <returns>The value of the validated XML element or attribute as the type requested.</returns>
        /// <param name="type">The type to return the validated XML element or attribute's value as.</param>
        /// <param name="nsResolver">The <see cref="T:System.Xml.IXmlNamespaceResolver" /> object used to resolve namespace prefixes.</param>
        /// <exception cref="T:System.FormatException">The validated XML element or attribute's value is not in the correct format for the target type.</exception>
        /// <exception cref="T:System.InvalidCastException">The attempted cast is not valid.</exception>
        /// <exception cref="T:System.OverflowException">The attempted cast resulted in an overflow.</exception>
        public override object ValueAs(Type type, IXmlNamespaceResolver nsResolver)
        {
            XmlTypeCode xmlTypeCode = XmlAtomicValue.XmlTypeCodeFromRuntimeType(type, false);

            switch (xmlTypeCode)
            {
            case XmlTypeCode.Long:
            case XmlTypeCode.UnsignedInt:
                return(this.ValueAsLong);

            case XmlTypeCode.Int:
            case XmlTypeCode.Short:
            case XmlTypeCode.UnsignedShort:
                return(this.ValueAsInt);

            default:
                switch (xmlTypeCode)
                {
                case XmlTypeCode.String:
                    return(this.Value);

                case XmlTypeCode.Boolean:
                    return(this.ValueAsBoolean);

                default:
                    if (xmlTypeCode == XmlTypeCode.Item)
                    {
                        return(this.TypedValue);
                    }
                    if (xmlTypeCode != XmlTypeCode.QName)
                    {
                        throw new NotImplementedException();
                    }
                    return(XmlQualifiedName.Parse(this.Value, nsResolver, true));

                case XmlTypeCode.Float:
                case XmlTypeCode.Double:
                    return(this.ValueAsDouble);

                case XmlTypeCode.DateTime:
                    return(this.ValueAsDateTime);
                }
                break;
            }
        }
예제 #41
0
        protected XmlBaseConverter(XmlTypeCode typeCode)
        {
            switch (typeCode)
            {
            case XmlTypeCode.Item:
                this.clrTypeDefault = XPathItemType;
                break;

            case XmlTypeCode.Node:
                this.clrTypeDefault = XPathNavigatorType;
                break;

            case XmlTypeCode.AnyAtomicType:
                this.clrTypeDefault = XmlAtomicValueType;
                break;
            }
            this.typeCode = typeCode;
        }
        internal override bool IsComparable(XmlSchemaDatatype dtype)
        {
            XmlTypeCode typeCode = this.TypeCode;
            XmlTypeCode code2    = dtype.TypeCode;

            if (typeCode != code2)
            {
                if (GetPrimitiveTypeCode(typeCode) == GetPrimitiveTypeCode(code2))
                {
                    return(true);
                }
                if (!this.IsDerivedFrom(dtype) && !dtype.IsDerivedFrom(this))
                {
                    return(false);
                }
            }
            return(true);
        }
        protected XmlBaseConverter(XmlTypeCode typeCode)
        {
            switch (typeCode)
            {
                case XmlTypeCode.Item:
                    this.clrTypeDefault = XPathItemType;
                    break;

                case XmlTypeCode.Node:
                    this.clrTypeDefault = XPathNavigatorType;
                    break;

                case XmlTypeCode.AnyAtomicType:
                    this.clrTypeDefault = XmlAtomicValueType;
                    break;
            }
            this.typeCode = typeCode;
        }
예제 #44
0
 private XmlTypeCode GetExcelType(XmlTypeCode typeCode)
 {
     //DateTime
     //double
     //string
     //bool
     if (typeCode == XmlTypeCode.DateTime || typeCode == XmlTypeCode.Boolean || typeCode == XmlTypeCode.String || typeCode == XmlTypeCode.Double)
     {
         return(typeCode);
     }
     if (typeCode == XmlTypeCode.Float || typeCode == XmlTypeCode.Decimal)
     {
         return(XmlTypeCode.Double);
     }
     else
     {
         return(XmlTypeCode.String);
     }
 }
 private static Type GetEffectiveType(XmlTypeCode typeCode, XmlSchemaDatatypeVariety variety, GeneratorConfiguration configuration)
 {
     Type result;
     switch (typeCode)
     {
         case XmlTypeCode.AnyAtomicType:
             // union
             result = typeof(string);
             break;
         case XmlTypeCode.AnyUri:
         case XmlTypeCode.Duration:
         case XmlTypeCode.GDay:
         case XmlTypeCode.GMonth:
         case XmlTypeCode.GMonthDay:
         case XmlTypeCode.GYear:
         case XmlTypeCode.GYearMonth:
         case XmlTypeCode.Time:
             result = variety == XmlSchemaDatatypeVariety.List ? typeof(string[]) : typeof(string);
             break;
         case XmlTypeCode.Integer:
         case XmlTypeCode.NegativeInteger:
         case XmlTypeCode.NonNegativeInteger:
         case XmlTypeCode.NonPositiveInteger:
         case XmlTypeCode.PositiveInteger:
             if (configuration.IntegerDataType == null || configuration.IntegerDataType == typeof(string))
                 result = typeof(string);
             else
             {
                 result = configuration.IntegerDataType;
             }
             break;
         default:
             result = null;
             break;
     }
     return result;
 }
예제 #46
0
 /// <include file='doc\XmlSchemaType.uex' path='docs/doc[@for="XmlSchemaType.GetXsdSimpleType"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public static XmlSchemaSimpleType GetBuiltInSimpleType(XmlTypeCode typeCode) {
     return DatatypeImplementation.GetSimpleTypeFromTypeCode(typeCode);
 }
예제 #47
0
        private Exception CheckBuiltInFacets(string s, XmlTypeCode typeCode, bool verifyUri) {
            Exception exception = null;

            switch (typeCode) {

                case XmlTypeCode.AnyUri:
                    if (verifyUri) {
                        Uri uri;
                        exception = XmlConvert.TryToUri(s, out uri);
                    }
                    break;

                case XmlTypeCode.NormalizedString:
                    exception = XmlConvert.TryVerifyNormalizedString(s);
                    break;

                case XmlTypeCode.Token:
                    exception = XmlConvert.TryVerifyTOKEN(s);
                    break;

                case XmlTypeCode.Language:
                    if (s == null || s.Length == 0) {
                        return new XmlSchemaException(Res.Sch_EmptyAttributeValue, string.Empty);
                    }
                    if (!LanguagePattern.IsMatch(s)) {
                        return new XmlSchemaException(Res.Sch_InvalidLanguageId, string.Empty);
                    }
                    break;

                case XmlTypeCode.NmToken:
                    exception = XmlConvert.TryVerifyNMTOKEN(s);
                    break;

                case XmlTypeCode.Name:
                    exception = XmlConvert.TryVerifyName(s);
                    break;

                case XmlTypeCode.NCName:
                case XmlTypeCode.Id:
                case XmlTypeCode.Idref:
                case XmlTypeCode.Entity:
                    exception = XmlConvert.TryVerifyNCName(s);
                    break;
                default:
                    break;
            }
            return exception;
        }
 public QilNode ConvertToType(XmlTypeCode requiredType, QilNode n) {
     switch (requiredType) {
     case XmlTypeCode.String     : return ConvertToString(n);
     case XmlTypeCode.Double     : return ConvertToNumber(n);
     case XmlTypeCode.Boolean    : return ConvertToBoolean(n);
     case XmlTypeCode.Node       : return EnsureNodeSet(n);
     case XmlTypeCode.Item       : return n;
     default                     : Debug.Fail("Unexpected XmlTypeCode: " + requiredType); return null;
     }
 }
 internal static XmlTypeCode GetPrimitiveTypeCode(XmlTypeCode typeCode) {
     XmlSchemaSimpleType currentType = enumToTypeCode[(int)typeCode];
     while (currentType.BaseXmlSchemaType != DatatypeImplementation.AnySimpleType) {
         currentType = currentType.BaseXmlSchemaType as XmlSchemaSimpleType;
         Debug.Assert(currentType != null);
     }
     return currentType.TypeCode;
 }
 internal static XmlSchemaSimpleType GetSimpleTypeFromTypeCode(XmlTypeCode typeCode) {
     return enumToTypeCode[(int) typeCode];
 }
            /// <summary>
            /// Private constructor.  Create methods should be used to create instances.
            /// </summary>
            private ItemType(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType schemaType, bool isNillable, bool isStrict, bool isNotRtf) {
                Debug.Assert(nameTest != null, "nameTest cannot be null");
                Debug.Assert(schemaType != null, "schemaType cannot be null");
                this.code = code;
                this.nameTest = nameTest;
                this.schemaType = schemaType;
                this.isNillable = isNillable;
                this.isStrict = isStrict;
                this.isNotRtf = isNotRtf;

                Debug.Assert(!IsAtomicValue || schemaType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic);

                switch (code) {
                    case XmlTypeCode.Item: this.nodeKinds = XmlNodeKindFlags.Any; break;
                    case XmlTypeCode.Node: this.nodeKinds = XmlNodeKindFlags.Any; break;
                    case XmlTypeCode.Document: this.nodeKinds = XmlNodeKindFlags.Document; break;
                    case XmlTypeCode.Element: this.nodeKinds = XmlNodeKindFlags.Element; break;
                    case XmlTypeCode.Attribute: this.nodeKinds = XmlNodeKindFlags.Attribute; break;
                    case XmlTypeCode.Namespace: this.nodeKinds = XmlNodeKindFlags.Namespace; break;
                    case XmlTypeCode.ProcessingInstruction: this.nodeKinds = XmlNodeKindFlags.PI; break;
                    case XmlTypeCode.Comment: this.nodeKinds = XmlNodeKindFlags.Comment; break;
                    case XmlTypeCode.Text: this.nodeKinds = XmlNodeKindFlags.Text; break;
                    default: this.nodeKinds = XmlNodeKindFlags.None; break;
                }
            }
            //-----------------------------------------------
            // Serialization
            //-----------------------------------------------

            /// <summary>
            /// Serialize the object to BinaryWriter.
            /// </summary>
            public override void GetObjectData(BinaryWriter writer) {
                sbyte code = (sbyte) this.code;

                for (int idx = 0; idx < SpecialBuiltInItemTypes.Length; idx++) {
                    if ((object) this == (object) SpecialBuiltInItemTypes[idx]) {
                        code = (sbyte) ~idx;
                        break;
                    }
                }

                writer.Write(code);

                if (0 <= code) {
                    Debug.Assert((object) this == (object) Create(this.code, this.isStrict), "Unknown type");
                    writer.Write(this.isStrict);
                }
            }
            /// <summary>
            /// Private constructor.  Create methods should be used to create instances.
            /// </summary>
            private ChoiceType(List<XmlQueryType> members) {
                Debug.Assert(members != null && members.Count != 1, "ChoiceType must contain a list with 0 or >1 types.");

                this.members = members;

                // Compute supertype of all member types
                for (int i = 0; i < members.Count; i++) {
                    XmlQueryType t = members[i];
                    Debug.Assert(t.Cardinality == XmlQueryCardinality.One, "ChoiceType member types must be prime types.");

                    // Summarize the union of member types as a single type
                    if (this.code == XmlTypeCode.None) {
                        // None combined with member type is the member type
                        this.code = t.TypeCode;
                        this.schemaType = t.SchemaType;
                    }
                    else if (IsNode && t.IsNode) {
                        // Node combined with node is node
                        if (this.code == t.TypeCode) {
                            // Element or attribute combined with element or attribute can be summarized as element(*, XmlSchemaComplexType.AnyType) or attribute(*, DatatypeImplementation.AnySimpleType)
                            if (this.code == XmlTypeCode.Element)
                                this.schemaType = XmlSchemaComplexType.AnyType;
                            else if (this.code == XmlTypeCode.Attribute)
                                this.schemaType = DatatypeImplementation.AnySimpleType;
                        }
                        else {
                            this.code = XmlTypeCode.Node;
                            this.schemaType = null;
                        }
                    }
                    else if (IsAtomicValue && t.IsAtomicValue) {
                        // Atomic value combined with atomic value is atomic value
                        this.code = XmlTypeCode.AnyAtomicType;
                        this.schemaType = DatatypeImplementation.AnyAtomicType;
                    }
                    else {
                        // Else we'll summarize types as Item
                        this.code = XmlTypeCode.Item;
                        this.schemaType = null;
                    }

                    // Always track union of node kinds
                    this.nodeKinds |= t.NodeKinds;
                }
            }
        /// <summary>
        /// Return true if the type of "item" is a subtype of the type identified by "code".
        /// </summary>
        public bool MatchesXmlType(XPathItem item, XmlTypeCode code) {
            // All atomic type codes appear after AnyAtomicType
            if (code > XmlTypeCode.AnyAtomicType)
                    return !item.IsNode && item.XmlType.TypeCode == code;

            // Handle node code and AnyAtomicType
            switch (code) {
                case XmlTypeCode.AnyAtomicType: return !item.IsNode;
                case XmlTypeCode.Node: return item.IsNode;
                case XmlTypeCode.Item: return true;
                default:
                    if (!item.IsNode)
                        return false;

                    switch (((XPathNavigator) item).NodeType) {
                        case XPathNodeType.Root: return code == XmlTypeCode.Document;
                        case XPathNodeType.Element: return code == XmlTypeCode.Element;
                        case XPathNodeType.Attribute: return code == XmlTypeCode.Attribute;
                        case XPathNodeType.Namespace: return code == XmlTypeCode.Namespace;
                        case XPathNodeType.Text: return code == XmlTypeCode.Text;
                        case XPathNodeType.SignificantWhitespace: return code == XmlTypeCode.Text;
                        case XPathNodeType.Whitespace: return code == XmlTypeCode.Text;
                        case XPathNodeType.ProcessingInstruction: return code == XmlTypeCode.ProcessingInstruction;
                        case XPathNodeType.Comment: return code == XmlTypeCode.Comment;
                    }
                    break;
            }

            Debug.Fail("XmlTypeCode " + code + " was not fully handled.");
            return false;
        }
        /// <summary>
        /// Return true if the type of "seq" is a subtype of a singleton type identified by "code".
        /// </summary>
        public bool MatchesXmlType(IList<XPathItem> seq, XmlTypeCode code) {
            if (seq.Count != 1)
                return false;

            return MatchesXmlType(seq[0], code);
        }
예제 #56
0
 private bool IsIntegralType(XmlTypeCode defaultTypeCode) {
     switch (defaultTypeCode) {
         case XmlTypeCode.Integer:
         case XmlTypeCode.NegativeInteger:
         case XmlTypeCode.NonNegativeInteger:
         case XmlTypeCode.NonPositiveInteger:
         case XmlTypeCode.PositiveInteger:
         case XmlTypeCode.Long:
         case XmlTypeCode.Int:
         case XmlTypeCode.Short:
         case XmlTypeCode.Byte:
         case XmlTypeCode.UnsignedLong:
         case XmlTypeCode.UnsignedInt:
         case XmlTypeCode.UnsignedShort:
         case XmlTypeCode.UnsignedByte:
            return true;
         default:
             return false;
     }
 }
예제 #57
0
        private Exception CheckBuiltInFacets(string s, XmlTypeCode typeCode, bool verifyUri)
        {
            Exception exception = null;

            switch (typeCode) {
                case XmlTypeCode.AnyUri:
                    
                    if (verifyUri) {
                        Uri uri = null;
                        exception = XmlConvertExt.TryToUri(s, out uri);
                    }
                    break;

                case XmlTypeCode.NormalizedString:
                    exception = XmlConvertExt.VerifyNormalizedString(s);
                    break;

                case XmlTypeCode.Token:
                    try
                    {
                        XmlConvert.VerifyTOKEN(s);
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                    break;

                case XmlTypeCode.Language:
                    if (s == null || s.Length == 0)  {
                        exception = new LinqToXsdException();
                    }
                    if (!LanguagePattern.IsMatch(s)) {
                        exception = new LinqToXsdException();
                    }
                    break;

                case XmlTypeCode.NmToken:
                    try
                    {
                        XmlConvert.VerifyNMTOKEN(s);
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                    break;

                case XmlTypeCode.Name:
                    try
                    {
                        XmlConvert.VerifyName(s);
                    }
                    catch(Exception e) {
                        exception = e;
                    }
                    
                    break;

                case XmlTypeCode.NCName:
                case XmlTypeCode.Id:
                case XmlTypeCode.Idref:
                case XmlTypeCode.Entity:
                    try
                    {
                        XmlConvert.VerifyNCName(s);
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                    break;
                default:
                    break;
            }
            return exception;
        }
예제 #58
0
        public void CallCompare(XmlTypeCode code)
        {
            MethodInfo meth = null;

            switch (code)
            {
                case XmlTypeCode.String: meth = XmlILMethods.StrCmp; break;
                case XmlTypeCode.Decimal: meth = XmlILMethods.DecCmp; break;
                default:
                    Debug.Assert(false, "Type " + code + " does not support the equals operation.");
                    break;
            }

            Call(meth);
        }
예제 #59
0
        public void CallArithmeticOp(QilNodeType opType, XmlTypeCode code)
        {
            MethodInfo meth = null;

            switch (code)
            {
                case XmlTypeCode.Int:
                case XmlTypeCode.Integer:
                case XmlTypeCode.Double:
                case XmlTypeCode.Float:
                    switch (opType)
                    {
                        case QilNodeType.Add: Emit(OpCodes.Add); break;
                        case QilNodeType.Subtract: Emit(OpCodes.Sub); break;
                        case QilNodeType.Multiply: Emit(OpCodes.Mul); break;
                        case QilNodeType.Divide: Emit(OpCodes.Div); break;
                        case QilNodeType.Modulo: Emit(OpCodes.Rem); break;
                        case QilNodeType.Negate: Emit(OpCodes.Neg); break;
                        default: Debug.Assert(false, opType + " must be an arithmetic operation."); break;
                    }
                    break;

                case XmlTypeCode.Decimal:
                    switch (opType)
                    {
                        case QilNodeType.Add: meth = XmlILMethods.DecAdd; break;
                        case QilNodeType.Subtract: meth = XmlILMethods.DecSub; break;
                        case QilNodeType.Multiply: meth = XmlILMethods.DecMul; break;
                        case QilNodeType.Divide: meth = XmlILMethods.DecDiv; break;
                        case QilNodeType.Modulo: meth = XmlILMethods.DecRem; break;
                        case QilNodeType.Negate: meth = XmlILMethods.DecNeg; break;
                        default: Debug.Assert(false, opType + " must be an arithmetic operation."); break;
                    }

                    Call(meth);
                    break;

                default:
                    Debug.Assert(false, "The " + opType + " arithmetic operation cannot be performed on values of type " + code + ".");
                    break;
            }
        }
예제 #60
0
        internal string TypeCodeToString(XmlTypeCode typeCode)
        {
            switch (typeCode)
            {
                case XmlTypeCode.None:
                    return "None";
                case XmlTypeCode.Item:
                    return "AnyType";
                case XmlTypeCode.AnyAtomicType:
                    return "AnyAtomicType";
                case XmlTypeCode.String:
                    return "String";
                case XmlTypeCode.Boolean:
                    return "Boolean";
                case XmlTypeCode.Decimal:
                    return "Decimal";
                case XmlTypeCode.Float:
                    return "Float";
                case XmlTypeCode.Double:
                    return "Double";
                case XmlTypeCode.Duration:
                    return "Duration";
                case XmlTypeCode.DateTime:
                    return "DateTime";
                case XmlTypeCode.Time:
                    return "Time";
                case XmlTypeCode.Date:
                    return "Date";
                case XmlTypeCode.GYearMonth:
                    return "GYearMonth";
                case XmlTypeCode.GYear:
                    return "GYear";
                case XmlTypeCode.GMonthDay:
                    return "GMonthDay";
                case XmlTypeCode.GDay:
                    return "GDay";
                case XmlTypeCode.GMonth:
                    return "GMonth";
                case XmlTypeCode.HexBinary:
                    return "HexBinary";
                case XmlTypeCode.Base64Binary:
                    return "Base64Binary";
                case XmlTypeCode.AnyUri:
                    return "AnyUri";
                case XmlTypeCode.QName:
                    return "QName";
                case XmlTypeCode.Notation:
                    return "Notation";
                case XmlTypeCode.NormalizedString:
                    return "NormalizedString";
                case XmlTypeCode.Token:
                    return "Token";
                case XmlTypeCode.Language:
                    return "Language";
                case XmlTypeCode.NmToken:
                    return "NmToken";
                case XmlTypeCode.Name:
                    return "Name";
                case XmlTypeCode.NCName:
                    return "NCName";
                case XmlTypeCode.Id:
                    return "Id";
                case XmlTypeCode.Idref:
                    return "Idref";
                case XmlTypeCode.Entity:
                    return "Entity";
                case XmlTypeCode.Integer:
                    return "Integer";
                case XmlTypeCode.NonPositiveInteger:
                    return "NonPositiveInteger";
                case XmlTypeCode.NegativeInteger:
                    return "NegativeInteger";
                case XmlTypeCode.Long:
                    return "Long";
                case XmlTypeCode.Int:
                    return "Int";
                case XmlTypeCode.Short:
                    return "Short";
                case XmlTypeCode.Byte:
                    return "Byte";
                case XmlTypeCode.NonNegativeInteger:
                    return "NonNegativeInteger";
                case XmlTypeCode.UnsignedLong:
                    return "UnsignedLong";
                case XmlTypeCode.UnsignedInt:
                    return "UnsignedInt";
                case XmlTypeCode.UnsignedShort:
                    return "UnsignedShort";
                case XmlTypeCode.UnsignedByte:
                    return "UnsignedByte";
                case XmlTypeCode.PositiveInteger:
                    return "PositiveInteger";

                default:
                    return typeCode.ToString();
            }
        }