System.Xml.Schema.Numeric10FacetsChecker.CheckTotalAndFractionDigits C# (CSharp) Méthode

CheckTotalAndFractionDigits() private méthode

private CheckTotalAndFractionDigits ( decimal value, int totalDigits, int fractionDigits, bool checkTotal, bool checkFraction ) : Exception
value decimal
totalDigits int
fractionDigits int
checkTotal bool
checkFraction bool
Résultat System.Exception
        internal Exception CheckTotalAndFractionDigits(decimal value, int totalDigits, int fractionDigits, bool checkTotal, bool checkFraction) {
            decimal maxValue = FacetsChecker.Power(10, totalDigits) - 1; //(decimal)Math.Pow(10, totalDigits) - 1 ;
            int powerCnt = 0;
            if (value < 0) {
                value = Decimal.Negate(value); //Need to compare maxValue allowed against the absolute value
            }
            while (Decimal.Truncate(value) != value) { //Till it has a fraction
                value = value * 10;
                powerCnt++;
            }
        
            if (checkTotal && (value > maxValue || powerCnt > totalDigits)) {
                return new XmlSchemaException(Res.Sch_TotalDigitsConstraintFailed, string.Empty);
            }
            if (checkFraction && powerCnt > fractionDigits) {
                return new XmlSchemaException(Res.Sch_FractionDigitsConstraintFailed, string.Empty);
            }
            return null;
        }
    }

Usage Example

Exemple #1
0
        public override object ParseValue(string s, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr)
        {
            Exception exception;

            try
            {
                Numeric10FacetsChecker facetsChecker = this.FacetsChecker as Numeric10FacetsChecker;
                decimal num = XmlConvert.ToDecimal(s);
                exception = facetsChecker.CheckTotalAndFractionDigits(num, 0x12, 4, true, true);
                if (exception == null)
                {
                    return(num);
                }
            }
            catch (XmlSchemaException exception2)
            {
                throw exception2;
            }
            catch (Exception exception3)
            {
                throw new XmlSchemaException(Res.GetString("Sch_InvalidValue", new object[] { s }), exception3);
            }
            throw exception;
        }