ApplyAnnotations() static private method

static private ApplyAnnotations ( CodeTypeMember typeDecl, List annotations, List typeAnnotations ) : CodeTypeMember
typeDecl System.CodeDom.CodeTypeMember
annotations List
typeAnnotations List
return System.CodeDom.CodeTypeMember
Beispiel #1
0
        private CodeTypeDeclaration ProcessType(ClrContentTypeInfo typeInfo, string parentIdentifier, bool globalType)
        {
            SetFullTypeName(typeInfo, parentIdentifier);

            if (globalType)
            {
                currentNamespace = typeInfo.clrtypeNs;
            }

            //Build type using TypeBuilder
            typeBuilder = GetTypeBuilder();
            typeBuilder.CreateTypeDeclaration(typeInfo);
            ProcessProperties(typeInfo.Content, typeInfo.Annotations);
            typeBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
            typeBuilder.ImplementInterfaces(settings.EnableServiceReference);
            typeBuilder.ApplyAnnotations(typeInfo);
            if (globalType)
            {
                if (typeInfo.typeOrigin == SchemaOrigin.Fragment)
                {
                    typeBuilder.AddTypeToTypeManager(typeDictionaryAddStatements, Constants.TypeDictionaryField);
                }
                else
                {
                    typeBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, Constants.ElementDictionaryField);
                }
            }

            CodeTypeDeclaration builtType = typeBuilder.TypeDeclaration;

            ProcessNestedTypes(typeInfo.NestedTypes, builtType, typeInfo.clrFullTypeName);
            return(builtType);
        }
Beispiel #2
0
        internal override CodeConstructor CreateFunctionalConstructor(List <ClrAnnotation> annotations)
        {
            CodeConstructor functionalConstructor = this.declItemsInfo.functionalConstructor;

            if ((functionalConstructor == null ? false : functionalConstructor.Parameters.Count > 0))
            {
                TypeBuilder.ApplyAnnotations(functionalConstructor, annotations, null);
                this.decl.Members.Add(functionalConstructor);
            }
            return(functionalConstructor);
        }
        internal override CodeConstructor CreateFunctionalConstructor(List <ClrAnnotation> annotations)
        {
            CodeConstructor constructor = CodeDomHelper.CreateConstructor(MemberAttributes.Public);

            if (this.clrTypeInfo.IsSubstitutionMember())
            {
                constructor.BaseConstructorArgs.Add(new CodePrimitiveExpression(true));
            }
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(this.innerTypeName), "content"));
            CodeStatementCollection statements = constructor.Statements;

            CodeExpression[] codeVariableReferenceExpression = new CodeExpression[] { new CodeVariableReferenceExpression("content") };
            statements.Add(CodeDomHelper.CreateMethodCall(null, "SetInnerType", codeVariableReferenceExpression));
            TypeBuilder.ApplyAnnotations(constructor, annotations, null);
            this.decl.Members.Add(constructor);
            return(constructor);
        }
        internal override void CreateDefaultConstructor(List <ClrAnnotation> annotations)
        {
            CodeMemberField typeField             = CodeDomHelper.CreateMemberField(this.memberName, this.innerTypeName, MemberAttributes.Private, false);
            CodeFieldReferenceExpression fieldRef = CodeDomHelper.CreateFieldReference("this", this.memberName);
            CodeConstructor emptyConstructor      = CodeDomHelper.CreateConstructor(MemberAttributes.Public);

            if ((this.innerTypeAttributes & TypeAttributes.Abstract) != TypeAttributes.NotPublic)
            {
                emptyConstructor.Statements.Add(new CodeThrowExceptionStatement(new CodeObjectCreateExpression("InvalidOperationException", new CodeExpression[0])));
            }
            else
            {
                CodeStatementCollection statements = emptyConstructor.Statements;
                CodeExpression[]        codeObjectCreateExpression = new CodeExpression[] { new CodeObjectCreateExpression(typeField.Type, new CodeExpression[0]) };
                statements.Add(CodeDomHelper.CreateMethodCall(null, "SetInnerType", codeObjectCreateExpression));
            }
            CodeConstructor dummyConstructor = null;

            if (this.clrTypeInfo.IsSubstitutionHead)
            {
                dummyConstructor = CodeDomHelper.CreateConstructor(MemberAttributes.Family);
                dummyConstructor.Parameters.Add(new CodeParameterDeclarationExpression("System.Boolean", "setNull"));
                this.decl.Members.Add(dummyConstructor);
            }
            if (this.clrTypeInfo.IsSubstitutionMember())
            {
                emptyConstructor.BaseConstructorArgs.Add(new CodePrimitiveExpression(true));
                if (dummyConstructor != null)
                {
                    dummyConstructor.BaseConstructorArgs.Add(new CodePrimitiveExpression(true));
                }
            }
            TypeBuilder.ApplyAnnotations(emptyConstructor, annotations, null);
            this.decl.Members.Add(typeField);
            this.decl.Members.Add(emptyConstructor);
            this.decl.Members.Add(this.CreateUntypedProperty(fieldRef));
            this.decl.Members.Add(this.InnerTypeProperty());
            this.decl.Members.Add(this.SetInnerType());
            if (this.clrTypeInfo.IsSubstitutionHead)
            {
                this.decl.Members.Add(this.SetSubstitutionMember());
            }
        }
Beispiel #5
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);
        }
Beispiel #6
0
        internal override CodeConstructor CreateFunctionalConstructor(List <ClrAnnotation> annotations)
        {
            string            parameterName = "content";
            CodeConstructor   constructor   = CodeDomHelper.CreateConstructor(MemberAttributes.Public);
            CodeTypeReference returnType    = null;

            if (!this.isSchemaList)
            {
                returnType = new CodeTypeReference(this.simpleTypeName);
            }
            else
            {
                CodeTypeReference[] codeTypeReference = new CodeTypeReference[] { new CodeTypeReference(this.simpleTypeName) };
                returnType = new CodeTypeReference("IList", codeTypeReference);
            }
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(returnType, parameterName));
            constructor.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(CodeDomHelper.This(), "TypedValue"), new CodeVariableReferenceExpression(parameterName)));
            TypeBuilder.ApplyAnnotations(constructor, annotations, null);
            this.decl.Members.Add(constructor);
            return(constructor);
        }
Beispiel #7
0
        private CodeTypeDeclaration ProcessType(ClrContentTypeInfo typeInfo, string parentIdentifier, bool globalType)
        {
            SetFullTypeName(typeInfo, parentIdentifier);

            if(globalType) {
                currentNamespace = typeInfo.clrtypeNs;
            }
            //Build type using TypeBuilder
            typeBuilder = GetTypeBuilder();
            typeBuilder.CreateTypeDeclaration(typeInfo);
            ProcessProperties(typeInfo.Content, typeInfo.Annotations);
            typeBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
            typeBuilder.ImplementInterfaces(settings.EnableServiceReference);
            typeBuilder.ApplyAnnotations(typeInfo);
            if (globalType) {
                if (typeInfo.typeOrigin == SchemaOrigin.Fragment) {
                    typeBuilder.AddTypeToTypeManager(typeDictionaryAddStatements, Constants.TypeDictionaryField);
                }
                else {
                    typeBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, Constants.ElementDictionaryField);
                }
            }
            CodeTypeDeclaration builtType = typeBuilder.TypeDeclaration;
            ProcessNestedTypes(typeInfo.NestedTypes, builtType, typeInfo.clrFullTypeName);
            return builtType;
        }
Beispiel #8
0
 internal static void ApplyAnnotations(CodeTypeMember typeDecl, ClrTypeInfo typeInfo)
 {
     TypeBuilder.ApplyAnnotations(typeDecl, typeInfo.Annotations, null);
 }
Beispiel #9
0
 internal static void ApplyAnnotations(CodeMemberProperty propDecl, ClrBasePropertyInfo propInfo, List <ClrAnnotation> typeAnnotations)
 {
     TypeBuilder.ApplyAnnotations(propDecl, propInfo.Annotations, typeAnnotations);
 }
Beispiel #10
0
 internal void ApplyAnnotations(ClrTypeInfo typeInfo)
 {
     TypeBuilder.ApplyAnnotations(this.decl, typeInfo);
 }
Beispiel #11
0
 internal virtual void CreateDefaultConstructor(List <ClrAnnotation> annotations)
 {
     this.decl.Members.Add(TypeBuilder.ApplyAnnotations(CodeDomHelper.CreateConstructor(MemberAttributes.Public), annotations, null));
 }
Beispiel #12
0
 internal virtual void ApplyAnnotations(CodeMemberProperty propDecl, List <ClrAnnotation> typeAnnotations)
 {
     TypeBuilder.ApplyAnnotations(propDecl, this, typeAnnotations);
 }