예제 #1
0
        internal override Exception CheckValueFacets(TimeSpan value, SimpleTypeValidator type)
        {
            Exception linqToXsdFacetException;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if ((facets == null ? false : facets.HasValueFacets))
            {
                Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                XmlSchemaDatatype datatype             = type.DataType;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                {
                    if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxInclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MaxInclusive, typeof(TimeSpan))) > 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxInclusive, facets.MaxInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxExclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MaxExclusive, typeof(TimeSpan))) >= 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MaxExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinInclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MinInclusive, typeof(TimeSpan))) < 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MinInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinExclusive) != 0)
                {
                    if (TimeSpan.Compare(value, (TimeSpan)datatype.ChangeType(facets.MinExclusive, typeof(TimeSpan))) <= 0)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MinExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                linqToXsdFacetException = null;
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }
예제 #2
0
        protected override bool IsEqual(XElement element, T value)
        {
            string stringValue = element.Value;

            if (schemaDatatype.ChangeType(stringValue, typeof(T)).Equals(value))
            {
                return(true);
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Extends ChangeType so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// xmlschemadatatype.ChangeType<int>(value, namespaceResolver);
        /// </example>
        /// </summary>
        public static T ChangeType <T>(this XmlSchemaDatatype xmlschemadatatype, Object value, System.Xml.IXmlNamespaceResolver namespaceResolver)
        {
            if (xmlschemadatatype == null)
            {
                throw new ArgumentNullException("xmlschemadatatype");
            }

            return((T)xmlschemadatatype.ChangeType(value, typeof(T), namespaceResolver));
        }
예제 #4
0
        /// <summary>
        /// Extends ChangeType so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// xmlschemadatatype.ChangeType<int>(value);
        /// </example>
        /// </summary>
        public static T ChangeType <T>(this XmlSchemaDatatype xmlschemadatatype, Object value)
        {
            if (xmlschemadatatype == null)
            {
                throw new ArgumentNullException("xmlschemadatatype");
            }

            return((T)xmlschemadatatype.ChangeType(value, typeof(T)));
        }
예제 #5
0
 internal static T ParseValue <T>(string value, XElement element, XmlSchemaDatatype datatype)
 {
     if (datatype.TypeCode == XmlTypeCode.QName || datatype.TypeCode == XmlTypeCode.NCName)
     {
         return((T)datatype.ParseValue(value, NameTable, new XNamespaceResolver(element)));
     }
     else
     {
         return((T)datatype.ChangeType(value, typeof(T)));
     }
 }
예제 #6
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);
        }
예제 #7
0
        internal override bool MatchEnumeration(object value, ArrayList enumeration, XmlSchemaDatatype datatype)
        {
            bool flag = this.MatchEnumeration((double)datatype.ChangeType(value, typeof(double)), enumeration, datatype);

            return(flag);
        }
        internal override Exception CheckValueFacets(object value, SimpleTypeValidator type)
        {
            Exception exception;

            if ((type.RestrictionFacets == null ? false : type.RestrictionFacets.HasValueFacets))
            {
                XmlSchemaDatatype datatype    = type.DataType;
                string            stringValue = null;
                stringValue = (type.DataType.TypeCode != XmlTypeCode.AnyUri ? (string)datatype.ChangeType(value, XTypedServices.typeOfString) : ((Uri)datatype.ChangeType(value, typeof(Uri))).OriginalString);
                exception   = this.CheckValueFacets(stringValue, type);
            }
            else
            {
                exception = null;
            }
            return(exception);
        }
        internal override Exception CheckValueFacets(decimal value, SimpleTypeValidator type)
        {
            Exception linqToXsdFacetException;

            Xml.Schema.Linq.RestrictionFacets facets = type.RestrictionFacets;
            if ((facets == null ? false : facets.HasValueFacets))
            {
                Xml.Schema.Linq.RestrictionFlags flags = facets.Flags;
                XmlSchemaDatatype datatype             = type.DataType;
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.Enumeration) != 0)
                {
                    if (!this.MatchEnumeration(value, facets.Enumeration, datatype))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.Enumeration, facets.Enumeration, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.FractionDigits) != 0)
                {
                    if (base.CheckTotalAndFractionDigits(value, 29, facets.FractionDigits, false, true) != null)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.FractionDigits, (object)facets.FractionDigits, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxExclusive) != 0)
                {
                    if (value >= (decimal)datatype.ChangeType(facets.MaxExclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxExclusive, facets.MaxExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MaxInclusive) != 0)
                {
                    if (value > (decimal)datatype.ChangeType(facets.MaxInclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MaxInclusive, facets.MaxInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinExclusive) != 0)
                {
                    if (value <= (decimal)datatype.ChangeType(facets.MinExclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MinExclusive, facets.MinExclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.MinInclusive) != 0)
                {
                    if (value < (decimal)datatype.ChangeType(facets.MinInclusive, typeof(decimal)))
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.MinInclusive, facets.MinInclusive, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                if ((int)(flags & Xml.Schema.Linq.RestrictionFlags.TotalDigits) != 0)
                {
                    if (base.CheckTotalAndFractionDigits(value, Convert.ToInt32(facets.TotalDigits), 0, true, false) != null)
                    {
                        linqToXsdFacetException = new LinqToXsdFacetException(Xml.Schema.Linq.RestrictionFlags.TotalDigits, (object)facets.TotalDigits, (object)value);
                        return(linqToXsdFacetException);
                    }
                }
                linqToXsdFacetException = null;
            }
            else
            {
                linqToXsdFacetException = null;
            }
            return(linqToXsdFacetException);
        }