예제 #1
0
        private void ExportProperty(CodeTypeDeclaration codeClass, MemberMapping member, CodeIdentifiers memberScope)
        {
            string fieldName = memberScope.AddUnique(CodeExporter.MakeFieldName(member.Name), member);
            string fieldType = member.GetTypeName(CodeProvider);
            // need to create a private field
            CodeMemberField field = new CodeMemberField(fieldType, fieldName);

            field.Attributes = MemberAttributes.Private;
            codeClass.Members.Add(field);

            CodeMemberProperty prop = CreatePropertyDeclaration(field, member.Name, fieldType);

            prop.Comments.Add(new CodeCommentStatement(ResXml.XmlRemarks, true));
            AddMemberMetadata(prop.CustomAttributes, member, false);
            codeClass.Members.Add(prop);

            if (member.CheckSpecified != SpecifiedAccessor.None)
            {
                field            = new CodeMemberField(typeof(bool).FullName, fieldName + "Specified");
                field.Attributes = MemberAttributes.Private;
                codeClass.Members.Add(field);

                prop = CreatePropertyDeclaration(field, member.Name + "Specified", typeof(bool).FullName);
                prop.Comments.Add(new CodeCommentStatement(ResXml.XmlRemarks, true));
                CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(SoapIgnoreAttribute).FullName);
                prop.CustomAttributes.Add(attribute);
                codeClass.Members.Add(prop);
            }
        }
예제 #2
0
        private CodeTypeDeclaration ExportStruct(StructMapping mapping)
        {
            if (mapping.TypeDesc.IsRoot)
            {
                ExportRoot(mapping, typeof(SoapIncludeAttribute));
                return(null);
            }
            if (!mapping.IncludeInSchema)
            {
                return(null);
            }

            string className = mapping.TypeDesc.Name;
            string baseName  = mapping.TypeDesc.BaseTypeDesc == null ? string.Empty : mapping.TypeDesc.BaseTypeDesc.Name;

            CodeTypeDeclaration codeClass = new CodeTypeDeclaration(className);

            codeClass.IsPartial = CodeProvider.Supports(GeneratorSupport.PartialTypes);
            codeClass.Comments.Add(new CodeCommentStatement(ResXml.XmlRemarks, true));

            CodeNamespace.Types.Add(codeClass);

            if (baseName != null && baseName.Length > 0)
            {
                codeClass.BaseTypes.Add(baseName);
            }
            else
            {
                AddPropertyChangedNotifier(codeClass);
            }

            codeClass.TypeAttributes |= TypeAttributes.Public;
            if (mapping.TypeDesc.IsAbstract)
            {
                codeClass.TypeAttributes |= TypeAttributes.Abstract;
            }

            CodeExporter.AddIncludeMetadata(codeClass.CustomAttributes, mapping, typeof(SoapIncludeAttribute));

            if (GenerateProperties)
            {
                for (int i = 0; i < mapping.Members.Length; i++)
                {
                    ExportProperty(codeClass, mapping.Members[i], mapping.Scope);
                }
            }
            else
            {
                for (int i = 0; i < mapping.Members.Length; i++)
                {
                    ExportMember(codeClass, mapping.Members[i]);
                }
            }
            for (int i = 0; i < mapping.Members.Length; i++)
            {
                EnsureTypesExported(mapping.Members[i].Elements, null);
            }

            if (mapping.BaseMapping != null)
            {
                ExportType(mapping.BaseMapping);
            }

            ExportDerivedStructs(mapping);
            CodeGenerator.ValidateIdentifiers(codeClass);
            return(codeClass);
        }