예제 #1
0
        protected override void GenerateArrayElement(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, string defaultNamespace, bool forceUseMemberName)
        {
            XmlTypeMapElementInfo    einfo = (XmlTypeMapElementInfo)member.ElementInfo[0];
            CodeAttributeDeclaration att   = new CodeAttributeDeclaration("Mono.System.Xml.Serialization.XmlArray");

            if (forceUseMemberName || (einfo.ElementName != member.Name))
            {
                att.Arguments.Add(GetArg("ElementName", einfo.ElementName));
            }
            if (einfo.Namespace != defaultNamespace)
            {
                att.Arguments.Add(GetArg("Namespace", einfo.Namespace));
            }
            if (einfo.Form == XmlSchemaForm.Unqualified)
            {
                att.Arguments.Add(MapCodeGenerator.GetEnumArg("Form", "Mono.System.Xml.Schema.XmlSchemaForm", einfo.Form.ToString()));
            }
            if (einfo.IsNullable)
            {
                att.Arguments.Add(GetArg("IsNullable", true));
            }
            if (att.Arguments.Count > 0)
            {
                attributes.Add(att);
            }
        }
예제 #2
0
 public void AddMappingMetadata(CodeAttributeDeclarationCollection metadata, XmlTypeMapping mapping, string ns)
 {
     if ((mapping.TypeData.SchemaType == SchemaTypes.Primitive ||
          mapping.TypeData.SchemaType == SchemaTypes.Array) &&
         mapping.Namespace != XmlSchema.Namespace)
     {
         CodeAttributeDeclaration ratt = new CodeAttributeDeclaration("Mono.System.Xml.Serialization.XmlRoot");
         ratt.Arguments.Add(MapCodeGenerator.GetArg(mapping.ElementName));
         ratt.Arguments.Add(MapCodeGenerator.GetArg("Namespace", mapping.Namespace));
         ratt.Arguments.Add(MapCodeGenerator.GetArg("IsNullable", mapping.IsNullable));
         metadata.Add(ratt);
     }
 }
예제 #3
0
        public void AddMappingMetadata(CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, string ns, bool forceUseMemberName)
        {
            CodeAttributeDeclaration att;
            TypeData memType = member.TypeMapMember.TypeData;

            if (member.Any)
            {
                XmlTypeMapElementInfoList list = (XmlTypeMapElementInfoList)((XmlTypeMapMemberElement)member.TypeMapMember).ElementInfo;
                foreach (XmlTypeMapElementInfo info in list)
                {
                    if (info.IsTextElement)
                    {
                        metadata.Add(new CodeAttributeDeclaration("Mono.System.Xml.Serialization.XmlText"));
                    }
                    else
                    {
                        att = new CodeAttributeDeclaration("Mono.System.Xml.Serialization.XmlAnyElement");
                        if (!info.IsUnnamedAnyElement)
                        {
                            att.Arguments.Add(MapCodeGenerator.GetArg("Name", info.ElementName));
                            if (info.Namespace != ns)
                            {
                                att.Arguments.Add(MapCodeGenerator.GetArg("Namespace", member.Namespace));
                            }
                        }
                        metadata.Add(att);
                    }
                }
            }
            else if (member.TypeMapMember is XmlTypeMapMemberList)
            {
                // Array parameter
                XmlTypeMapMemberList list = member.TypeMapMember as XmlTypeMapMemberList;
                ListMap listMap           = (ListMap)list.ListTypeMapping.ObjectMap;

                codeGenerator.AddArrayAttributes(metadata, list, ns, forceUseMemberName);
                codeGenerator.AddArrayItemAttributes(metadata, listMap, memType.ListItemTypeData, list.Namespace, 0);
            }
            else if (member.TypeMapMember is XmlTypeMapMemberElement)
            {
                codeGenerator.AddElementMemberAttributes((XmlTypeMapMemberElement)member.TypeMapMember, ns, metadata, forceUseMemberName);
            }
            else if (member.TypeMapMember is XmlTypeMapMemberAttribute)
            {
                codeGenerator.AddAttributeMemberAttributes((XmlTypeMapMemberAttribute)member.TypeMapMember, ns, metadata, forceUseMemberName);
            }
            else
            {
                throw new NotSupportedException("Schema type not supported");
            }
        }
예제 #4
0
        protected override void GenerateArrayItemAttributes(CodeAttributeDeclarationCollection attributes, ListMap listMap, TypeData type, XmlTypeMapElementInfo ainfo, string defaultName, string defaultNamespace, int nestingLevel)
        {
            bool needsType = (listMap.ItemInfo.Count > 1) ||
                             (ainfo.TypeData.FullTypeName != type.FullTypeName && !listMap.IsMultiArray);

            CodeAttributeDeclaration att = new CodeAttributeDeclaration("Mono.System.Xml.Serialization.XmlArrayItem");

            if (ainfo.ElementName != defaultName)
            {
                att.Arguments.Add(GetArg("ElementName", ainfo.ElementName));
            }
            if (ainfo.Namespace != defaultNamespace && ainfo.Namespace != XmlSchema.Namespace)
            {
                att.Arguments.Add(GetArg("Namespace", ainfo.Namespace));
            }
            if (needsType)
            {
                att.Arguments.Add(GetTypeArg("Type", ainfo.TypeData.FullTypeName));
            }
            if (!ainfo.IsNullable)
            {
                att.Arguments.Add(GetArg("IsNullable", false));
            }
            if (ainfo.Form == XmlSchemaForm.Unqualified)
            {
                att.Arguments.Add(MapCodeGenerator.GetEnumArg("Form", "Mono.System.Xml.Schema.XmlSchemaForm", ainfo.Form.ToString()));
            }
            if (att.Arguments.Count > 0 && nestingLevel > 0)
            {
                att.Arguments.Add(GetArg("NestingLevel", nestingLevel));
            }

            if (att.Arguments.Count > 0)
            {
                attributes.Add(att);
            }
        }