internal Exception CheckTotalAndFractionDigits(decimal value, int totalDigits, int fractionDigits, bool checkTotal, bool checkFraction)
        {
            Exception linqToXsdException;
            decimal   maxValue = Xml.Schema.Linq.FacetsChecker.Power(10, totalDigits) - 1;
            int       powerCnt = 0;

            if (value < new decimal(0))
            {
                value = decimal.Negate(value);
            }
            while (decimal.Truncate(value) != value)
            {
                value *= new decimal(10);
                powerCnt++;
            }
            if (checkTotal & (value > maxValue ? true : powerCnt > totalDigits))
            {
                linqToXsdException = new LinqToXsdException();
            }
            else if (!(checkFraction & powerCnt > fractionDigits))
            {
                linqToXsdException = null;
            }
            else
            {
                linqToXsdException = new LinqToXsdException();
            }
            return(linqToXsdException);
        }
Esempio n. 2
0
        internal static Exception VerifyNormalizedString(string str)
        {
            Exception linqToXsdException;

            if (str.IndexOfAny(XmlConvertExt.crt) == -1)
            {
                linqToXsdException = null;
            }
            else
            {
                linqToXsdException = new LinqToXsdException(string.Concat("Failed to Verify Normalized String: ", str));
            }
            return(linqToXsdException);
        }
Esempio n. 3
0
        protected static string ConvertIEnumToString(IEnumerable value)
        {
            StringBuilder strBuilder = new StringBuilder();

            foreach (object o in value)
            {
                if (strBuilder.Length != 0)
                {
                    strBuilder.Append(' ');
                }
                strBuilder.Append((!(o is IEnumerable) || o is string?o.ToString() : LinqToXsdException.ConvertIEnumToString(o as IEnumerable)));
            }
            strBuilder.Insert(0, '(');
            strBuilder.Append(')');
            return(strBuilder.ToString());
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
 protected static string CreateMessage(string facetName, object facetValue, object value)
 {
     return(LinqToXsdException.CreateMessage(facetName, (!(facetValue is IEnumerable) || facetValue is string?facetValue.ToString() : LinqToXsdException.ConvertIEnumToString(facetValue as IEnumerable)), (!(value is IEnumerable) || facetValue is string?value.ToString() : LinqToXsdException.ConvertIEnumToString(value as IEnumerable))));
 }
        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);
        }
 public UnionMemberTypeNotFoundException(object value, UnionSimpleTypeValidator typeDef) : base(LinqToXsdException.CreateMessage("Union Type: No Matching Member Type Was Found. Valid Types ", UnionMemberTypeNotFoundException.GetMemberTypeCodes(typeDef), value))
 {
 }
 public LinqToXsdFacetException(RestrictionFlags flags, object facetValue, object value) : base(LinqToXsdException.CreateMessage(flags.ToString(), facetValue, value))
 {
 }
 public LinqToXsdFixedValueException(object value, object fixedValue) : base(LinqToXsdException.CreateMessage("Checking Fixed Value Failed", fixedValue, value))
 {
 }
        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.QName:
            case XmlTypeCode.Notation:
            {
                break;
            }

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

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

            case XmlTypeCode.Language:
            {
                if ((s == null ? true : s.Length == 0))
                {
                    exception = new LinqToXsdException();
                }
                if (!Xml.Schema.Linq.StringFacetsChecker.LanguagePattern.IsMatch(s))
                {
                    exception = new LinqToXsdException();
                }
                break;
            }

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

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

            case XmlTypeCode.NCName:
            case XmlTypeCode.Id:
            case XmlTypeCode.Idref:
            case XmlTypeCode.Entity:
            {
                try
                {
                    XmlConvert.VerifyNCName(s);
                }
                catch (Exception exception4)
                {
                    exception = exception4;
                }
                break;
            }

            default:
            {
                goto case XmlTypeCode.Notation;
            }
            }
            return(exception);
        }