TryParseString() private method

private TryParseString ( object value, NameTable nameTable, Xml.Schema.Linq.XNamespaceResolver resolver, string &parsedString ) : Exception
value object
nameTable System.Xml.NameTable
resolver Xml.Schema.Linq.XNamespaceResolver
parsedString string
return System.Exception
示例#1
0
        internal override Exception TryParseValue(object value, NameTable nameTable, XNamespaceResolver resolver, out SimpleTypeValidator matchingType, out object typedValue)
        {
            Exception unionMemberTypeNotFoundException;

            typedValue   = null;
            matchingType = null;
            if (value != null)
            {
                object typedMemberValue = null;
                SimpleTypeValidator[] simpleTypeValidatorArray = this.memberTypes;
                int num = 0;
                while (num < (int)simpleTypeValidatorArray.Length)
                {
                    if (simpleTypeValidatorArray[num].TryParseValue(value, nameTable, resolver, out matchingType, out typedMemberValue) != null)
                    {
                        num++;
                    }
                    else
                    {
                        break;
                    }
                }
                if (typedMemberValue != null)
                {
                    Exception e = null;
                    if ((base.RestrictionFacets == null ? false : base.RestrictionFacets.HasLexicalFacets))
                    {
                        string parsedString = null;
                        e = matchingType.TryParseString(value, nameTable, resolver, out parsedString);
                        if (e == null)
                        {
                            e = this.facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this);
                        }
                    }
                    if (e == null)
                    {
                        e = this.facetsChecker.CheckValueFacets(typedMemberValue, this);
                    }
                    if (e == null)
                    {
                        typedValue = typedMemberValue;
                        unionMemberTypeNotFoundException = null;
                    }
                    else
                    {
                        unionMemberTypeNotFoundException = e;
                    }
                }
                else
                {
                    unionMemberTypeNotFoundException = new UnionMemberTypeNotFoundException(value, this);
                }
            }
            else
            {
                unionMemberTypeNotFoundException = new ArgumentNullException("Argument value should not be null.");
            }
            return(unionMemberTypeNotFoundException);
        }
        internal override Exception TryParseValue(object value,
                                                  NameTable nameTable,
                                                  XNamespaceResolver resolver,
                                                  out SimpleTypeValidator matchingType,
                                                  out object typedValue)
        {
            typedValue   = null;
            matchingType = null;
            if (value == null)
            {
                return(new ArgumentNullException("Argument value should not be null."));
            }

            object typedMemberValue = null;

            foreach (SimpleTypeValidator memberType in memberTypes)
            {
                if (memberType.TryParseValue(value, nameTable, resolver, out matchingType, out typedMemberValue) ==
                    null)
                {
                    break;
                }
            }

            if (typedMemberValue == null)
            {
                return(new UnionMemberTypeNotFoundException(value, this));
            }
            else
            {
                Exception e = null;
                if (RestrictionFacets != null && RestrictionFacets.HasLexicalFacets)
                {
                    string parsedString = null;
                    e = matchingType.TryParseString(value, nameTable, resolver, out parsedString);
                    if (e == null)
                    {
                        e = facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this);
                    }
                }

                if (e == null)
                {
                    e = facetsChecker.CheckValueFacets(typedMemberValue, this);
                }
                if (e != null)
                {
                    return(e);
                }
                else
                {
                    typedValue = typedMemberValue;
                    return(null);
                }
            }
        }
        internal override Exception TryParseString(object value,
                                                   NameTable nameTable,
                                                   XNamespaceResolver resolver,
                                                   out string parsedString)
        {
            parsedString = value as string;

            if (parsedString != null)
            {
                return(null);
            }

            IEnumerable list = value as IEnumerable;

            if (list == null)
            {
                return(new InvalidCastException());
            }

            StringBuilder bldr = new StringBuilder();

            foreach (object o in list)
            {
                // Separate values by single space character
                if (bldr.Length != 0)
                {
                    bldr.Append(' ');
                }

                // Append string value of next item in the list
                string    s  = null;
                Exception ie = itemType.TryParseString(o, nameTable, resolver, out s);
                if (ie == null)
                {
                    bldr.Append(s);
                }
                else
                {
                    return(ie);
                }
            }

            parsedString = bldr.ToString();


            return(null);
        }
示例#4
0
        internal override Exception TryParseValue(object value,
                                        NameTable nameTable,
                                        XNamespaceResolver resolver,
                                        out SimpleTypeValidator matchingType, 
                                        out object typedValue) {
            typedValue = null;
            matchingType = null;
            if (value == null) return new ArgumentNullException("Argument value should not be null.");
                      
            object typedMemberValue = null;
            foreach (SimpleTypeValidator memberType in memberTypes) {
                if (memberType.TryParseValue(value, nameTable, resolver, out matchingType, out typedMemberValue) == null)  {
                    break;
                }
            }

            if (typedMemberValue == null) {
                return new UnionMemberTypeNotFoundException(value, this);
            }
            else {
                Exception e = null;
                if (RestrictionFacets != null && RestrictionFacets.HasLexicalFacets) {
                    string parsedString = null;
                    e = matchingType.TryParseString(value, nameTable, resolver, out parsedString);
                    if (e == null) e = facetsChecker.CheckLexicalFacets(ref parsedString, value, nameTable, resolver, this);
                }
                
                if (e == null) e = facetsChecker.CheckValueFacets(typedMemberValue, this);
                if (e != null) return e;
                else {
                    typedValue = typedMemberValue;
                    return null;
                }
            }
                
        }