Inheritance: SimpleTypeValidator
        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;
                    }
                }
            }
        }
        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);
        }
        private static List <string> GetMemberTypeCodes(UnionSimpleTypeValidator typeDef)
        {
            List <string> codes = new List <string>();

            foreach (SimpleTypeValidator type in typeDef.MemberTypes)
            {
                codes.Add(type.DataType.TypeCode.ToString());
            }

            return(codes);
        }
        private static List <string> GetMemberTypeCodes(UnionSimpleTypeValidator typeDef)
        {
            List <string> codes = new List <string>();

            SimpleTypeValidator[] memberTypes = typeDef.MemberTypes;
            for (int i = 0; i < (int)memberTypes.Length; i++)
            {
                SimpleTypeValidator type = memberTypes[i];
                codes.Add(type.DataType.TypeCode.ToString());
            }
            return(codes);
        }
        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);
        }
 public UnionMemberTypeNotFoundException(object value, UnionSimpleTypeValidator typeDef)
     : base(CreateMessage("Union Type: No Matching Member Type Was Found. Valid Types ",
                          GetMemberTypeCodes(typeDef), value))
 {
 }
Beispiel #7
0
        private static List<string> GetMemberTypeCodes(UnionSimpleTypeValidator typeDef) {
            List<string> codes = new List<string>();

            foreach (SimpleTypeValidator type in typeDef.MemberTypes)
            {
                codes.Add(type.DataType.TypeCode.ToString());
            }

            return codes;
        }
Beispiel #8
0
 public UnionMemberTypeNotFoundException(object value, UnionSimpleTypeValidator typeDef)
     : base(CreateMessage("Union Type: No Matching Member Type Was Found. Valid Types ",
        GetMemberTypeCodes(typeDef), value)) {
 }