TryParseValue() private method

private TryParseValue ( object value, NameTable nameTable, Xml.Schema.Linq.XNamespaceResolver resolver, SimpleTypeValidator &matchingType, object &typedValue ) : Exception
value object
nameTable System.Xml.NameTable
resolver Xml.Schema.Linq.XNamespaceResolver
matchingType SimpleTypeValidator
typedValue object
return System.Exception
コード例 #1
0
        private static object ParseUnionValue(string value, XElement element, XName itemXName,
                                              SimpleTypeValidator typeDef, ContainerType containerType)
        {
            //Parse the string value based on the member types
            UnionSimpleTypeValidator unionDef = typeDef as UnionSimpleTypeValidator;

            Debug.Assert(unionDef != null);
            SimpleTypeValidator matchingType = null;
            object    typedValue;
            Exception e = unionDef.TryParseValue(value, NameTable, new XNamespaceResolver(element), out matchingType,
                                                 out typedValue);

            ListSimpleTypeValidator listType = matchingType as ListSimpleTypeValidator;

            if (listType != null)
            {
                SimpleTypeValidator itemType = listType.ItemType;
                return(new XListContent <object>((IList)typedValue, element, itemXName, containerType,
                                                 itemType.DataType));
            }

            Debug.Assert(e == null);

            return(typedValue);
        }
コード例 #2
0
        private void SetUnionCatchAll(object value,
                                      string propertyName,
                                      XTypedElement container,
                                      XName itemXName,
                                      SimpleTypeValidator typeDef,
                                      SchemaOrigin origin)
        {
            UnionSimpleTypeValidator unionDef = typeDef as UnionSimpleTypeValidator;

            Debug.Assert(unionDef != null);
            SimpleTypeValidator matchingType = null;
            object    typedValue;
            Exception e = unionDef.TryParseValue(value,
                                                 XTypedServices.NameTable,
                                                 new XNamespaceResolver(container.GetUntyped()),
                                                 out matchingType,
                                                 out typedValue);

            if (e != null)
            {
                throw new LinqToXsdException(propertyName, e.Message);
            }
            else
            {
                if (matchingType is ListSimpleTypeValidator)
                {
                    ListSimpleTypeValidator listType = matchingType as ListSimpleTypeValidator;
                    switch (origin)
                    {
                    case SchemaOrigin.Element:
                        SetListElement(itemXName, value, listType.ItemType.DataType);
                        break;

                    case SchemaOrigin.Text:
                        SetListValue(value, listType.ItemType.DataType);
                        break;

                    case SchemaOrigin.Attribute:
                        SetListAttribute(itemXName, value, listType.ItemType.DataType);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (origin)
                    {
                    case SchemaOrigin.Element: SetElement(itemXName, value, matchingType.DataType); break;

                    case SchemaOrigin.Text: SetValue(value, matchingType.DataType); break;

                    case SchemaOrigin.Attribute: SetAttribute(itemXName, value, matchingType.DataType); break;

                    default: break;
                    }
                }
            }
        }
コード例 #3
0
        private static object ParseUnionValue(string value, XElement element, XName itemXName, SimpleTypeValidator typeDef, ContainerType containerType)
        {
            object typedValue;
            object objs;
            UnionSimpleTypeValidator unionDef = typeDef as UnionSimpleTypeValidator;

            Debug.Assert(unionDef != null);
            SimpleTypeValidator     matchingType = null;
            Exception               e            = unionDef.TryParseValue(value, XTypedServices.NameTable, new XNamespaceResolver(element), out matchingType, out typedValue);
            ListSimpleTypeValidator listType     = matchingType as ListSimpleTypeValidator;

            if (listType == null)
            {
                Debug.Assert(e == null);
                objs = typedValue;
            }
            else
            {
                SimpleTypeValidator itemType = listType.ItemType;
                objs = new XListContent <object>((IList)typedValue, element, itemXName, containerType, itemType.DataType);
            }
            return(objs);
        }