CreateSimpleTypeDef() static private method

static private CreateSimpleTypeDef ( Xml.Schema.Linq.CodeGen.ClrSimpleTypeInfo typeInfo, string>.Dictionary nameMappings, LinqToXsdSettings settings, bool memberOrItemType ) : System.CodeDom.CodeExpression
typeInfo Xml.Schema.Linq.CodeGen.ClrSimpleTypeInfo
nameMappings string>.Dictionary
settings LinqToXsdSettings
memberOrItemType bool
return System.CodeDom.CodeExpression
        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);
        }
示例#2
0
        internal static CodeTypeDeclaration CreateSimpleType(ClrSimpleTypeInfo typeInfo, Dictionary <XmlSchemaObject, string> nameMappings, LinqToXsdSettings settings)
        {
            CodeTypeDeclaration simpleTypeDecl = new CodeTypeDeclaration(typeInfo.clrtypeName)
            {
                TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed
            };
            CodeConstructor privateConst = new CodeConstructor()
            {
                Attributes = MemberAttributes.Private
            };

            simpleTypeDecl.Members.Add(privateConst);
            CodeMemberField typeField = CodeDomHelper.CreateMemberField("TypeDefinition", "Xml.Schema.Linq.SimpleTypeValidator", MemberAttributes.Abstract | MemberAttributes.Final | MemberAttributes.Static | MemberAttributes.FamilyAndAssembly | MemberAttributes.FamilyOrAssembly | MemberAttributes.Public, false);

            typeField.InitExpression = SimpleTypeCodeDomHelper.CreateSimpleTypeDef(typeInfo, nameMappings, settings, false);
            simpleTypeDecl.Members.Add(typeField);
            TypeBuilder.ApplyAnnotations(simpleTypeDecl, typeInfo);
            return(simpleTypeDecl);
        }