Ejemplo n.º 1
0
 public void AddComplexRestrictedContentType(XmlSchemaComplexType wrappingType, ClrTypeReference wrappingTypeRef) 
 {
     string identifier = NameGenerator.MakeValidIdentifier(wrappingType.Name);
     AnonymousType at = new AnonymousType();
     at.identifier = identifier;
     at.typeRefence = wrappingTypeRef;
     at.wrappingType = wrappingType;
     anonymousTypes.Add(at);
 }
Ejemplo n.º 2
0
 private ClrTypeReference BuildTypeReference(
     XmlSchemaObject schemaObject,
     XmlQualifiedName typeQName,
     bool anonymousType,
     bool setVariety)
 {
     string typeName = typeQName.Name;
     string typeNs = typeQName.Namespace;
     if (!anonymousType)
     {
         typeNs = configSettings.GetClrNamespace(typeNs);
     }
     ClrTypeReference typeRef = new ClrTypeReference(
         typeName, typeNs, schemaObject, anonymousType, setVariety);
     return typeRef;
 }
Ejemplo n.º 3
0
 public void AddAnonymousType(string identifier, XmlSchemaElement parentElement, ClrTypeReference parentElementTypeRef)
 {
     AnonymousType at = new AnonymousType();
     at.identifier = identifier;
     at.typeRefence = parentElementTypeRef;
     at.parentElement = parentElement;
     anonymousTypes.Add(at);
 }
Ejemplo n.º 4
0
        public void AddComplexRestrictedContentType(XmlSchemaComplexType wrappingType, ClrTypeReference wrappingTypeRef)
        {
            string        identifier = NameGenerator.MakeValidIdentifier(wrappingType.Name);
            AnonymousType at         = new AnonymousType();

            at.identifier   = identifier;
            at.typeRefence  = wrappingTypeRef;
            at.wrappingType = wrappingType;
            anonymousTypes.Add(at);
        }
Ejemplo n.º 5
0
 private ClrPropertyInfo InitializeTypedValuePropertyInfo(ClrTypeInfo typeInfo, ClrPropertyInfo typedValPropertyInfo, ClrTypeReference innerType)
 {
     if (typedValPropertyInfo == null) {
         typedValPropertyInfo = new ClrPropertyInfo(Constants.SInnerTypePropertyName, string.Empty, Constants.SInnerTypePropertyName, Occurs.One);
         typedValPropertyInfo.Origin = SchemaOrigin.Text;
     }
     else {
         typedValPropertyInfo.Reset();
     }
     typedValPropertyInfo.TypeReference = innerType;
     if (typeInfo.IsSubstitutionMember()) {
         typedValPropertyInfo.IsNew = true;
     }
     typedValPropertyInfo.UpdateTypeReference(currentFullTypeName, currentNamespace, nameMappings);
     return typedValPropertyInfo;
 }
        private ClrPropertyInfo BuildComplexTypeTextProperty(XmlSchemaElement parentElement,
                                                             XmlSchemaComplexType schemaType)
        {
            Debug.Assert(schemaType != null);
            Debug.Assert(schemaType.GetContentType() == XmlSchemaContentType.TextOnly);

            ClrPropertyInfo textProperty = new ClrPropertyInfo(Constants.SInnerTypePropertyName, string.Empty,
                                                               Constants.SInnerTypePropertyName, Occurs.One);

            textProperty.Origin = SchemaOrigin.Text;
            ClrTypeReference typeRef   = null;
            bool             anonymous = false;

            //Could be derived by restriction or extension
            //If first time extension, make the base simple type as the type reference
            XmlSchemaType baseType = schemaType.BaseXmlSchemaType;

            if (baseType is XmlSchemaSimpleType)
            {
                typeRef   = BuildTypeReference(baseType, baseType.QualifiedName, false, true);
                anonymous = false;
                if (!textPropInheritanceTracker.ContainsKey(schemaType))
                {
                    textPropInheritanceTracker.Add(schemaType, textProperty);
                }
            }
            else if (schemaType.HasFacetRestrictions())
            {
                //Derived by restriction, represents the content type with restrictions as a local type
                //Make the base simple type as the type reference so that we know if it is a list, union or atomic
                XmlSchemaSimpleType st = schemaType.GetBaseSimpleType();
                Debug.Assert(st != null);
                typeRef          = BuildTypeReference(st, st.QualifiedName, true, true);
                typeRef.Validate = true;
                anonymous        = true;

                //Also get its base complex type and see if we need to override the content property
                ClrPropertyInfo baseProp = null;
                if (textPropInheritanceTracker.TryGetValue(baseType, out baseProp))
                {
                    textProperty.IsOverride = true;
                    if (!baseProp.IsOverride)
                    {
                        baseProp.IsVirtual = true;
                    }
                }
            }
            else
            {
                return(null);
            }

            if (anonymous)
            {
                //anonymous type, fixed up the name later, treat complex type with restrictions as an anonymous type
                //because we need to generate a type to encapsualte these restrictions
                if (parentElement != null)
                {
                    string identifier = localSymbolTable.AddLocalElement(parentElement);
                    localSymbolTable.AddAnonymousType(identifier, parentElement, typeRef);
                }
                else
                {
                    localSymbolTable.AddComplexRestrictedContentType(schemaType, typeRef);
                }
            }

            textProperty.TypeReference = typeRef;

            return(textProperty);
        }
        private ClrPropertyInfo BuildProperty(XmlSchemaElement elem, bool fromBaseType)
        {
            string identifierName = localSymbolTable.AddLocalElement(elem);

            XmlSchemaType    schemaType     = elem.ElementSchemaType;
            XmlQualifiedName schemaTypeName = schemaType.QualifiedName;
            string           schemaName     = elem.QualifiedName.Name;
            string           schemaNs       = elem.QualifiedName.Namespace;
            string           clrNs          = elem.FormResolved() == XmlSchemaForm.Qualified
                ? configSettings.GetClrNamespace(schemaNs)
                : string.Empty;


            SchemaOrigin    typeRefOrigin = SchemaOrigin.Fragment;
            bool            isTypeRef     = false;
            bool            anonymousType = schemaTypeName.IsEmpty ? true : false;
            XmlSchemaObject schemaObject  = schemaType;

            ArrayList substitutionMembers = null;

            if (elem.IsGlobal())
            {
                substitutionMembers = IsSubstitutionGroupHead(elem);
                schemaTypeName      = elem.QualifiedName;
                isTypeRef           = true;
                typeRefOrigin       = SchemaOrigin.Element;
                schemaObject        =
                    schemas.GlobalElements
                    [schemaTypeName];     //For ref, get the element decl SOM object, as nameMappings are keyed off the SOM object
                anonymousType = false;
            }

            ClrTypeReference typeRef = BuildTypeReference(schemaObject, schemaTypeName, anonymousType, true);

            typeRef.Origin    = typeRefOrigin;
            typeRef.IsTypeRef = isTypeRef;
            if (anonymousType && !fromBaseType)
            {
                //to fixup later.
                localSymbolTable.AddAnonymousType(identifierName, elem, typeRef);
            }

            ClrPropertyInfo propertyInfo =
                new ClrPropertyInfo(identifierName, schemaNs, schemaName, GetOccurence(elem));

            propertyInfo.Origin        = SchemaOrigin.Element;
            propertyInfo.FromBaseType  = fromBaseType;
            propertyInfo.TypeReference = typeRef;
            propertyInfo.ClrNamespace  = clrNs;

            //SetFixedDefaultValue(elem, propertyInfo);

            if (substitutionMembers != null)
            {
                propertyInfo.SubstitutionMembers = substitutionMembers;
            }

            //BuildAnnotationInformation(propertyInfo, elem);
            return(propertyInfo);
            //Place it in the element's namespace, maybe element's parent type's namespace?
        }
Ejemplo n.º 8
0
        public void AddComplexRestrictedContentType(XmlSchemaComplexType wrappingType, ClrTypeReference wrappingTypeRef)
        {
            string        identifier = NameGenerator.MakeValidIdentifier(wrappingType.Name, this.ConfigSettings.NameMangler2);
            AnonymousType at         = new AnonymousType()
            {
                identifier   = identifier,
                typeRefence  = wrappingTypeRef,
                wrappingType = wrappingType
            };

            this.anonymousTypes.Add(at);
        }
        internal void ElementsToTypes()
        {
            bool isRoot            = false;
            int  rootElementsCount = schemas.GlobalElements.Count;

            foreach (XmlSchemaElement elem in schemas.GlobalElements.Values)
            {
                SymbolEntry   symbol       = symbolTable.AddElement(elem);
                XmlSchemaType schemaType   = elem.ElementSchemaType;
                string        xsdNamespace = elem.QualifiedName.Namespace;

                ClrTypeInfo      typeInfo    = null;
                XmlSchemaElement headElement = null;
                if (!elem.SubstitutionGroup.IsEmpty)
                {
                    headElement = (XmlSchemaElement)schemas.GlobalElements[elem.SubstitutionGroup];
                }

                if (schemaType.IsGlobal())
                {
                    //Global elem with global type, generate wrapper class for the element
                    bool hasBaseContentType      = headElement != null && headElement.ElementSchemaType == schemaType;
                    ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo(hasBaseContentType);
                    ClrTypeReference   typeDef   = BuildTypeReference(schemaType, schemaType.QualifiedName, false, true);
                    //Save the fixed/default value of the element
                    wtypeInfo.InnerType = typeDef;
                    typeInfo            = wtypeInfo;
                    typeInfo.baseType   =
                        headElement; //If element is member of substitutionGroup, add derivation step
                }
                else
                {
                    ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo();
                    localSymbolTable.Init(symbol.identifierName);
                    ctypeInfo.baseType =
                        headElement; //If element is member of substitutionGroup, add derivation step
                    BuildProperties(elem, schemaType, ctypeInfo);
                    BuildNestedTypes(ctypeInfo);
                    typeInfo = ctypeInfo;
                }

                if (!isRoot)
                {
                    if (rootElementsCount == 1 || CheckUnhandledAttributes(elem))
                    {
                        typeInfo.IsRoot = true;
                        isRoot          = true;
                    }
                }

                typeInfo.IsSubstitutionHead = IsSubstitutionGroupHead(elem) != null;
                typeInfo.IsAbstract         = elem.IsAbstract;
                typeInfo.clrtypeName        = symbol.identifierName;
                typeInfo.clrtypeNs          = symbol.clrNamespace;
                typeInfo.schemaName         = symbol.symbolName;
                typeInfo.schemaNs           = xsdNamespace;

                typeInfo.typeOrigin = SchemaOrigin.Element;

                BuildAnnotationInformation(typeInfo, schemaType);
                binding.Types.Add(typeInfo);
            }
        }
        private void ProcessWrapperTypes()
        {
            List <CodeTypeDeclaration> types;

            if (this.wrapperRootElements != null)
            {
                XWrapperTypedElementBuilder wrapperBuilder    = new XWrapperTypedElementBuilder();
                XSimpleTypedElementBuilder  simpleTypeBuilder = new XSimpleTypedElementBuilder();
                TypeBuilder     builder = null;
                ClrPropertyInfo typedValPropertyInfo = null;
                foreach (ClrWrapperTypeInfo typeInfo in this.wrapperRootElements)
                {
                    this.SetFullTypeName(typeInfo, null);
                    ClrTypeReference innerType = typeInfo.InnerType;
                    if (!innerType.IsSimpleType)
                    {
                        string innerTypeName                    = null;
                        string innerTypeFullName                = innerType.GetClrFullTypeName(typeInfo.clrtypeNs, this.nameMappings, out innerTypeName);
                        string innerTypeNs                      = innerType.Namespace;
                        CodeTypeDeclaration innerTypeDecl       = this.GetCodeTypeDeclaration(innerTypeName, this.GetCodeNamespace(innerTypeNs));
                        TypeAttributes      innerTypeAttributes = TypeAttributes.NotPublic;
                        if (innerTypeDecl != null)
                        {
                            innerTypeAttributes = innerTypeDecl.TypeAttributes;
                        }
                        else if (innerTypeName != "XTypedElement")
                        {
                            continue;
                        }
                        this.currentNamespace = typeInfo.clrtypeNs;
                        wrapperBuilder.Init(innerTypeFullName, innerTypeNs, innerTypeAttributes);
                        wrapperBuilder.CreateTypeDeclaration(typeInfo);
                        wrapperBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
                        wrapperBuilder.ApplyAnnotations(typeInfo);
                        wrapperBuilder.AddTypeToTypeManager(CodeDomTypesGenerator.elementDictionaryAddStatements, CodeDomTypesGenerator.wrapperDictionaryAddStatements);
                        if (!typeInfo.HasBaseContentType)
                        {
                            ClrWrappingPropertyInfo wrappingPropertyInfo = null;
                            if (innerTypeName != "XTypedElement")
                            {
                                wrappingPropertyInfo = new ClrWrappingPropertyInfo();
                                foreach (CodeTypeMember member in innerTypeDecl.Members)
                                {
                                    CodeMemberProperty memberProperty = member as CodeMemberProperty;
                                    if (this.ForwardProperty(memberProperty))
                                    {
                                        wrappingPropertyInfo.Init(memberProperty);
                                        wrapperBuilder.CreateProperty(wrappingPropertyInfo, typeInfo.Annotations);
                                    }
                                }
                            }
                        }
                        builder = wrapperBuilder;
                    }
                    else
                    {
                        typedValPropertyInfo = this.InitializeTypedValuePropertyInfo(typeInfo, typedValPropertyInfo, innerType);
                        simpleTypeBuilder.Init(typedValPropertyInfo.ClrTypeName, innerType.IsSchemaList);
                        simpleTypeBuilder.CreateTypeDeclaration(typeInfo);
                        simpleTypeBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
                        typedValPropertyInfo.SetFixedDefaultValue(typeInfo);
                        simpleTypeBuilder.CreateProperty(typedValPropertyInfo, typeInfo.Annotations);
                        simpleTypeBuilder.AddTypeToTypeManager(CodeDomTypesGenerator.elementDictionaryAddStatements, "elementDictionary");
                        simpleTypeBuilder.ApplyAnnotations(typeInfo);
                        builder = simpleTypeBuilder;
                    }
                    builder.ImplementInterfaces(this.settings.EnableServiceReference);
                    this.codeNamespace = this.GetCodeNamespace(typeInfo.clrtypeNs);
                    this.codeNamespace.Types.Add(builder.TypeDeclaration);
                    this.codeNamespace = this.GetCodeNamespace(typeInfo.clrtypeNs);
                    if (!this.xroots.TryGetValue(this.codeNamespace, out types))
                    {
                        types = new List <CodeTypeDeclaration>();
                        this.xroots.Add(this.codeNamespace, types);
                    }
                    types.Add(builder.TypeDeclaration);
                }
            }
        }
Ejemplo n.º 11
0
        public void AddAnonymousType(string identifier, XmlSchemaElement parentElement, ClrTypeReference parentElementTypeRef)
        {
            AnonymousType at = new AnonymousType()
            {
                identifier    = identifier,
                typeRefence   = parentElementTypeRef,
                parentElement = parentElement
            };

            this.anonymousTypes.Add(at);
        }
 private ClrPropertyInfo InitializeTypedValuePropertyInfo(ClrTypeInfo typeInfo, ClrPropertyInfo typedValPropertyInfo, ClrTypeReference innerType)
 {
     if (typedValPropertyInfo != null)
     {
         typedValPropertyInfo.Reset();
     }
     else
     {
         typedValPropertyInfo = new ClrPropertyInfo("TypedValue", string.Empty, "TypedValue", Occurs.One)
         {
             Origin = SchemaOrigin.Text
         };
     }
     typedValPropertyInfo.TypeReference = innerType;
     if (typeInfo.IsSubstitutionMember())
     {
         typedValPropertyInfo.IsNew = true;
     }
     typedValPropertyInfo.UpdateTypeReference(this.currentFullTypeName, this.currentNamespace, this.nameMappings);
     return(typedValPropertyInfo);
 }
Ejemplo n.º 13
0
        private ClrPropertyInfo InitializeTypedValuePropertyInfo(ClrTypeInfo typeInfo,
                                                                 ClrPropertyInfo typedValPropertyInfo, ClrTypeReference innerType)
        {
            if (typedValPropertyInfo == null)
            {
                typedValPropertyInfo = new ClrPropertyInfo(Constants.SInnerTypePropertyName, string.Empty,
                                                           Constants.SInnerTypePropertyName, Occurs.One, settings);
                typedValPropertyInfo.Origin = SchemaOrigin.Text;
            }
            else
            {
                typedValPropertyInfo.Reset();
            }

            typedValPropertyInfo.TypeReference = innerType;
            if (typeInfo.IsSubstitutionMember())
            {
                typedValPropertyInfo.IsNew = true;
            }

            typedValPropertyInfo.UpdateTypeReference(currentFullTypeName, currentNamespace, nameMappings);
            return(typedValPropertyInfo);
        }
Ejemplo n.º 14
0
        private void ProcessWrapperTypes()
        {
            if (wrapperRootElements == null)
            {
                //No Globalelements with global types
                return;
            }

            XWrapperTypedElementBuilder wrapperBuilder    = new XWrapperTypedElementBuilder(settings);
            XSimpleTypedElementBuilder  simpleTypeBuilder = new XSimpleTypedElementBuilder(settings);

            TypeBuilder     builder = null;
            ClrPropertyInfo typedValPropertyInfo = null;

            foreach (ClrWrapperTypeInfo typeInfo in wrapperRootElements)
            {
                SetFullTypeName(typeInfo, null);
                ClrTypeReference innerType = typeInfo.InnerType;
                if (innerType.IsSimpleType)
                {
                    typedValPropertyInfo = InitializeTypedValuePropertyInfo(typeInfo, typedValPropertyInfo, innerType);
                    simpleTypeBuilder.Init(typedValPropertyInfo.ClrTypeName, innerType.IsSchemaList);
                    simpleTypeBuilder.CreateTypeDeclaration(typeInfo);
                    simpleTypeBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
                    typedValPropertyInfo.SetFixedDefaultValue(typeInfo);
                    simpleTypeBuilder.CreateProperty(typedValPropertyInfo, typeInfo.Annotations);
                    simpleTypeBuilder.AddTypeToTypeManager(elementDictionaryAddStatements,
                                                           Constants.ElementDictionaryField);
                    simpleTypeBuilder.ApplyAnnotations(typeInfo);
                    builder = simpleTypeBuilder;
                }
                else
                {
                    string innerTypeName     = null;
                    string innerTypeFullName =
                        innerType.GetClrFullTypeName(typeInfo.clrtypeNs, nameMappings, out innerTypeName);
                    string innerTypeNs = innerType.Namespace;

                    CodeNamespace       innerTypeCodeNamespace = GetCodeNamespace(innerTypeNs);
                    CodeTypeDeclaration innerTypeDecl          = GetCodeTypeDeclaration(innerTypeName, innerTypeCodeNamespace);
                    TypeAttributes      innerTypeAttributes    = TypeAttributes.Class;
                    if (innerTypeDecl != null)
                    {
                        innerTypeAttributes = innerTypeDecl.TypeAttributes;
                    }
                    else if (innerTypeName != Constants.XTypedElement)
                    {
                        continue;
                    }

                    currentNamespace = typeInfo.clrtypeNs;
                    wrapperBuilder.Init(innerTypeFullName, innerTypeNs, innerTypeAttributes);
                    wrapperBuilder.CreateTypeDeclaration(typeInfo);
                    wrapperBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
                    wrapperBuilder.ApplyAnnotations(typeInfo);
                    wrapperBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, wrapperDictionaryAddStatements);

                    if (!typeInfo.HasBaseContentType)
                    {
                        //Add innerType properties only if the wrapper's type is not the same as the substitutionGroup head type
                        ClrWrappingPropertyInfo wrappingPropertyInfo = null;
                        //Create forwarding properties
                        if (innerTypeName != Constants.XTypedElement)
                        {
                            //If the wrapped type is xs:anyType, no forwarding properties to create
                            wrappingPropertyInfo = new ClrWrappingPropertyInfo();

                            foreach (CodeTypeMember member in innerTypeDecl.Members)
                            {
                                CodeMemberProperty memberProperty = member as CodeMemberProperty;
                                if (ForwardProperty(memberProperty))
                                {
                                    //Do not forward over TypeManager, SchemaName etc
                                    wrappingPropertyInfo.Init(memberProperty);
                                    wrapperBuilder.CreateProperty(wrappingPropertyInfo, typeInfo.Annotations);
                                }
                            }
                        }
                    }

                    builder = wrapperBuilder;
                }

                builder.ImplementInterfaces(settings.EnableServiceReference);
                codeNamespace = GetCodeNamespace(typeInfo.clrtypeNs);
                codeNamespace.Types.Add(builder.TypeDeclaration);

                List <CodeTypeDeclaration> types;
                codeNamespace = GetCodeNamespace(typeInfo.clrtypeNs);

                if (!xroots.TryGetValue(codeNamespace, out types))
                {
                    types = new List <CodeTypeDeclaration>();
                    xroots.Add(codeNamespace, types);
                }

                types.Add(builder.TypeDeclaration);
            }
        }
        private ClrPropertyInfo BuildComplexTypeTextProperty(XmlSchemaElement parentElement, XmlSchemaComplexType schemaType)
        {
            string          identifier;
            ClrPropertyInfo clrPropertyInfo;

            Debug.Assert(schemaType != null);
            Debug.Assert(schemaType.GetContentType() == XmlSchemaContentType.TextOnly);
            ClrPropertyInfo textProperty = new ClrPropertyInfo("TypedValue", string.Empty, "TypedValue", Occurs.One)
            {
                Origin = SchemaOrigin.Text
            };
            ClrTypeReference typeRef   = null;
            bool             anonymous = false;
            XmlSchemaType    baseType  = schemaType.BaseXmlSchemaType;

            if (!(baseType is XmlSchemaSimpleType))
            {
                if (schemaType.HasFacetRestrictions())
                {
                    goto Label1;
                }
                clrPropertyInfo = null;
                return(clrPropertyInfo);
            }
            else
            {
                typeRef   = this.BuildTypeReference(baseType, baseType.QualifiedName, false, true);
                anonymous = false;
                if (!this.textPropInheritanceTracker.ContainsKey(schemaType))
                {
                    this.textPropInheritanceTracker.Add(schemaType, textProperty);
                }
            }
            if (anonymous)
            {
                if (parentElement == null)
                {
                    this.localSymbolTable.AddComplexRestrictedContentType(schemaType, typeRef);
                }
                else
                {
                    identifier = this.localSymbolTable.AddLocalElement(parentElement);
                    this.localSymbolTable.AddAnonymousType(identifier, parentElement, typeRef);
                }
            }
            textProperty.TypeReference = typeRef;
            clrPropertyInfo            = textProperty;
            return(clrPropertyInfo);

Label1:
            XmlSchemaSimpleType st = schemaType.GetBaseSimpleType();

            Debug.Assert(st != null);
            typeRef          = this.BuildTypeReference(st, st.QualifiedName, true, true);
            typeRef.Validate = true;
            anonymous        = true;
            ClrPropertyInfo baseProp = null;

            if (this.textPropInheritanceTracker.TryGetValue(baseType, out baseProp))
            {
                textProperty.IsOverride = true;
                if (!baseProp.IsOverride)
                {
                    baseProp.IsVirtual = true;
                }
            }
            if (anonymous)
            {
                if (parentElement == null)
                {
                    this.localSymbolTable.AddComplexRestrictedContentType(schemaType, typeRef);
                }
                else
                {
                    identifier = this.localSymbolTable.AddLocalElement(parentElement);
                    this.localSymbolTable.AddAnonymousType(identifier, parentElement, typeRef);
                }
            }
            textProperty.TypeReference = typeRef;
            clrPropertyInfo            = textProperty;
            return(clrPropertyInfo);
        }
Ejemplo n.º 16
0
        public void AddAnonymousType(string identifier, XmlSchemaElement parentElement, ClrTypeReference parentElementTypeRef)
        {
            AnonymousType at = new AnonymousType();

            at.identifier    = identifier;
            at.typeRefence   = parentElementTypeRef;
            at.parentElement = parentElement;
            anonymousTypes.Add(at);
        }