internal static ClrSimpleTypeInfo CreateSimpleTypeInfo(XmlSchemaType type)
        {
            ClrSimpleTypeInfo typeInfo = null;

            Debug.Assert(type.Datatype != null);
            switch (type.Datatype.Variety)
            {
            case XmlSchemaDatatypeVariety.Atomic:
            {
                typeInfo = new AtomicSimpleTypeInfo(type);
                break;
            }

            case XmlSchemaDatatypeVariety.List:
            {
                typeInfo = new ListSimpleTypeInfo(type);
                break;
            }

            case XmlSchemaDatatypeVariety.Union:
            {
                typeInfo = new UnionSimpleTypeInfo(type);
                break;
            }
            }
            return(typeInfo);
        }
Ejemplo n.º 2
0
        public static void GetCreateUnionValueExpression(object value,
                                                         UnionSimpleTypeInfo unionDef,
                                                         CodeExpressionCollection collection)
        {
            Debug.Assert(unionDef != null);

            //Use reflection to get real value and type from "value", which is an XsdSimpleValue
            object typedValue = value.GetType().InvokeMember("TypedValue",
                                                             BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
                                                             null,
                                                             value,
                                                             null,
                                                             CultureInfo.InvariantCulture);

            CodeExpressionCollection dummy = new CodeExpressionCollection();

            ClrSimpleTypeInfo matchingType = null;

            foreach (ClrSimpleTypeInfo type in unionDef.MemberTypes)
            {
                try
                {
                    GetCreateValueExpression(typedValue, type, dummy);
                    matchingType = type;
                    break;
                }
                catch (Exception)
                {
                    continue;
                }
            }

            Debug.Assert(matchingType != null);
            GetCreateValueExpression(typedValue, matchingType, collection);
        }
Ejemplo n.º 3
0
        internal static CodeExpression MaterializeSimpleTypeDef(
            ClrSimpleTypeInfo typeInfo,
            Dictionary <XmlSchemaObject, string> nameMappings,
            LinqToXsdSettings settings)
        {
            CodeObjectCreateExpression simpleTypeCreate = null;
            CodeExpressionCollection   expressions      = null;

            switch (typeInfo.Variety)
            {
            case XmlSchemaDatatypeVariety.Atomic:
                simpleTypeCreate = new CodeObjectCreateExpression(
                    Constants.AtomicSimpleTypeValidator);
                expressions = simpleTypeCreate.Parameters;
                expressions.Add(CreateGetBuiltInSimpleType(typeInfo.TypeCode));
                expressions.Add(CreateFacets(typeInfo));
                break;

            case XmlSchemaDatatypeVariety.List:
                simpleTypeCreate = new CodeObjectCreateExpression(
                    Constants.ListSimpleTypeValidator);
                expressions = simpleTypeCreate.Parameters;
                expressions.Add(CreateGetBuiltInSimpleType(typeInfo.TypeCode));
                expressions.Add(CreateFacets(typeInfo));

                ListSimpleTypeInfo listType = typeInfo as ListSimpleTypeInfo;
                ClrSimpleTypeInfo  itemType = listType.ItemType;
                expressions.Add(CreateSimpleTypeDef(
                                    itemType, nameMappings, settings, true));
                break;

            case XmlSchemaDatatypeVariety.Union:
                simpleTypeCreate = new CodeObjectCreateExpression(
                    Constants.UnionSimpleTypeValidator);
                expressions = simpleTypeCreate.Parameters;
                expressions.Add(CreateGetBuiltInSimpleType(typeInfo.TypeCode));
                expressions.Add(CreateFacets(typeInfo));

                UnionSimpleTypeInfo       unionType        = typeInfo as UnionSimpleTypeInfo;
                CodeArrayCreateExpression memberTypeCreate =
                    new CodeArrayCreateExpression();
                memberTypeCreate.CreateType = new CodeTypeReference(
                    Constants.SimpleTypeValidator);
                foreach (ClrSimpleTypeInfo st in unionType.MemberTypes)
                {
                    memberTypeCreate.Initializers.Add(CreateSimpleTypeDef(
                                                          st, nameMappings, settings, true));
                }
                expressions.Add(memberTypeCreate);
                break;
            }
            return(simpleTypeCreate);
        }
        internal static CodeExpression MaterializeSimpleTypeDef(ClrSimpleTypeInfo typeInfo, Dictionary <XmlSchemaObject, string> nameMappings, LinqToXsdSettings settings)
        {
            CodeObjectCreateExpression simpleTypeCreate = null;
            CodeExpressionCollection   expressions      = null;

            switch (typeInfo.Variety)
            {
            case XmlSchemaDatatypeVariety.Atomic:
            {
                simpleTypeCreate = new CodeObjectCreateExpression("Xml.Schema.Linq.AtomicSimpleTypeValidator", new CodeExpression[0]);
                expressions      = simpleTypeCreate.Parameters;
                expressions.Add(SimpleTypeCodeDomHelper.CreateGetBuiltInSimpleType(typeInfo.TypeCode));
                expressions.Add(SimpleTypeCodeDomHelper.CreateFacets(typeInfo));
                break;
            }

            case XmlSchemaDatatypeVariety.List:
            {
                simpleTypeCreate = new CodeObjectCreateExpression("Xml.Schema.Linq.ListSimpleTypeValidator", new CodeExpression[0]);
                expressions      = simpleTypeCreate.Parameters;
                expressions.Add(SimpleTypeCodeDomHelper.CreateGetBuiltInSimpleType(typeInfo.TypeCode));
                expressions.Add(SimpleTypeCodeDomHelper.CreateFacets(typeInfo));
                ClrSimpleTypeInfo itemType = (typeInfo as ListSimpleTypeInfo).ItemType;
                expressions.Add(SimpleTypeCodeDomHelper.CreateSimpleTypeDef(itemType, nameMappings, settings, true));
                break;
            }

            case XmlSchemaDatatypeVariety.Union:
            {
                simpleTypeCreate = new CodeObjectCreateExpression("Xml.Schema.Linq.UnionSimpleTypeValidator", new CodeExpression[0]);
                expressions      = simpleTypeCreate.Parameters;
                expressions.Add(SimpleTypeCodeDomHelper.CreateGetBuiltInSimpleType(typeInfo.TypeCode));
                expressions.Add(SimpleTypeCodeDomHelper.CreateFacets(typeInfo));
                UnionSimpleTypeInfo       unionType        = typeInfo as UnionSimpleTypeInfo;
                CodeArrayCreateExpression memberTypeCreate = new CodeArrayCreateExpression()
                {
                    CreateType = new CodeTypeReference("Xml.Schema.Linq.SimpleTypeValidator")
                };
                ClrSimpleTypeInfo[] memberTypes = unionType.MemberTypes;
                for (int i = 0; i < (int)memberTypes.Length; i++)
                {
                    ClrSimpleTypeInfo st = memberTypes[i];
                    memberTypeCreate.Initializers.Add(SimpleTypeCodeDomHelper.CreateSimpleTypeDef(st, nameMappings, settings, true));
                }
                expressions.Add(memberTypeCreate);
                break;
            }
            }
            return(simpleTypeCreate);
        }
        public static void GetCreateUnionValueExpression(object value, UnionSimpleTypeInfo unionDef, CodeExpressionCollection collection)
        {
            Debug.Assert(unionDef != null);
            object typedValue = value.GetType().InvokeMember("TypedValue", BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty, null, value, null, CultureInfo.InvariantCulture);
            CodeExpressionCollection dummy        = new CodeExpressionCollection();
            ClrSimpleTypeInfo        matchingType = null;

            ClrSimpleTypeInfo[] memberTypes = unionDef.MemberTypes;
            for (int i = 0; i < (int)memberTypes.Length; i++)
            {
                ClrSimpleTypeInfo type = memberTypes[i];
                try
                {
                    SimpleTypeCodeDomHelper.GetCreateValueExpression(typedValue, type, dummy);
                    matchingType = type;
                    break;
                }
                catch (Exception exception)
                {
                }
            }
            Debug.Assert(matchingType != null);
            SimpleTypeCodeDomHelper.GetCreateValueExpression(typedValue, matchingType, collection);
        }
Ejemplo n.º 6
0
        public static void GetCreateUnionValueExpression(
            object value,
            UnionSimpleTypeInfo unionDef,
            CodeExpressionCollection collection)
        {
            Debug.Assert(unionDef != null);

            //Use reflection to get real value and type from "value", which is an XsdSimpleValue
            object typedValue = value.GetType().InvokeMember("TypedValue",
               BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
               null,
               value,
               null,
               CultureInfo.InvariantCulture);

            CodeExpressionCollection dummy = new CodeExpressionCollection();

            ClrSimpleTypeInfo matchingType = null;
            foreach (ClrSimpleTypeInfo type in unionDef.MemberTypes)
            {
                try
                {
                    GetCreateValueExpression(typedValue, type, dummy);
                    matchingType = type;
                    break;
                }
                catch (Exception)
                {
                    continue;
                }
            }
            Debug.Assert(matchingType != null);
            GetCreateValueExpression(typedValue, matchingType, collection);
        }
Ejemplo n.º 7
0
        internal static ClrSimpleTypeInfo CreateSimpleTypeInfo(XmlSchemaType type)
        {
             ClrSimpleTypeInfo typeInfo = null;

             Debug.Assert(type.Datatype != null);
             switch (type.Datatype.Variety)
             {
                 case XmlSchemaDatatypeVariety.Atomic: typeInfo = new AtomicSimpleTypeInfo(type);
                     break;
                 case XmlSchemaDatatypeVariety.List: typeInfo = new ListSimpleTypeInfo(type);
                     break;
                 case XmlSchemaDatatypeVariety.Union: typeInfo = new UnionSimpleTypeInfo(type);
                     break;
                 default:
                     break;
             }
             return typeInfo;
         }