Exemplo n.º 1
0
        XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access)
        {
            elementName = XmlConvert.EncodeLocalName(elementName);
            XmlMemberMapping[] mapping = new XmlMemberMapping[members.Length];
            for (int n = 0; n < members.Length; n++)
            {
                XmlTypeMapMember mapMem = CreateMapMember(members[n], ns);
                mapping[n] = new XmlMemberMapping(XmlConvert.EncodeLocalName(members[n].MemberName), ns, mapMem, true);
            }
            XmlMembersMapping mps = new XmlMembersMapping(elementName, ns, hasWrapperElement, writeAccessors, mapping);

            mps.RelatedMaps = relatedMaps;
            mps.Format      = SerializationFormat.Encoded;
            Type[] extraTypes = includedTypes != null ? (Type[])includedTypes.ToArray(typeof(Type)) : null;
            mps.Source = new MembersSerializationSource(elementName, hasWrapperElement, members, writeAccessors, false, null, extraTypes);
            return(mps);
        }
Exemplo n.º 2
0
        void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType)
        {
            ClassMap cmap = (ClassMap)xmlMembersMapping.ObjectMap;

            if (xmlMembersMapping.HasWrapperElement && exportEnclosingType)
            {
                XmlSchema            schema = GetSchema(xmlMembersMapping.Namespace);
                XmlSchemaComplexType stype  = new XmlSchemaComplexType();

                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, null, stype.Attributes, out particle, out anyAttribute);
                stype.Particle     = particle;
                stype.AnyAttribute = anyAttribute;

                if (encodedFormat)
                {
                    stype.Name = xmlMembersMapping.ElementName;
                    schema.Items.Add(stype);
                }
                else
                {
                    XmlSchemaElement selem = new XmlSchemaElement();
                    selem.Name       = xmlMembersMapping.ElementName;
                    selem.SchemaType = stype;
                    schema.Items.Add(selem);
                }
            }
            else
            {
                ICollection members = cmap.ElementMembers;
                if (members != null)
                {
                    foreach (XmlTypeMapMemberElement member in members)
                    {
                        if (member is XmlTypeMapMemberAnyElement && member.TypeData.IsListType)
                        {
                            XmlSchema         mschema = GetSchema(xmlMembersMapping.Namespace);
                            XmlSchemaParticle par     = GetSchemaArrayElement(mschema, member.ElementInfo);
                            if (par is XmlSchemaAny)
                            {
                                XmlSchemaComplexType ct = FindComplexType(mschema.Items, "any");
                                if (ct != null)
                                {
                                    continue;
                                }

                                ct         = new XmlSchemaComplexType();
                                ct.Name    = "any";
                                ct.IsMixed = true;
                                XmlSchemaSequence seq = new XmlSchemaSequence();
                                ct.Particle = seq;
                                seq.Items.Add(par);
                                mschema.Items.Add(ct);
                                continue;
                            }
                        }


                        XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo)member.ElementInfo [0];
                        XmlSchema             schema;

                        if (encodedFormat)
                        {
                            schema = GetSchema(xmlMembersMapping.Namespace);
                            ImportNamespace(schema, XmlSerializer.EncodingNamespace);
                        }
                        else
                        {
                            schema = GetSchema(einfo.Namespace);
                        }


                        XmlSchemaElement exe = FindElement(schema.Items, einfo.ElementName);
                        XmlSchemaElement elem;

                        XmlSchemaObjectContainer container = null;
                        // In encoded format, the schema elements are not needed
                        if (!encodedFormat)
                        {
                            container = new XmlSchemaObjectContainer(schema);
                        }

                        Type memType = member.GetType();
                        if (member is XmlTypeMapMemberFlatList)
                        {
                            throw new InvalidOperationException("Unwrapped arrays not supported as parameters");
                        }
                        else if (memType == typeof(XmlTypeMapMemberElement))
                        {
                            elem = (XmlSchemaElement)GetSchemaElement(schema,
                                                                      einfo, member.DefaultValue, false, container);
                        }
                        else
                        {
                            elem = (XmlSchemaElement)GetSchemaElement(schema,
                                                                      einfo, false, container);
                        }

                        if (exe != null)
                        {
                            if (exe.SchemaTypeName.Equals(elem.SchemaTypeName))
                            {
                                schema.Items.Remove(elem);
                            }
                            else
                            {
                                string s = "The XML element named '" + einfo.ElementName + "' ";
                                s += "from namespace '" + schema.TargetNamespace + "' references distinct types " + elem.SchemaTypeName.Name + " and " + exe.SchemaTypeName.Name + ". ";
                                s += "Use XML attributes to specify another XML name or namespace for the element or types.";
                                throw new InvalidOperationException(s);
                            }
                        }
                    }
                }
            }

            CompileSchemas();
        }
Exemplo n.º 3
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     ExportMembersMapping(xmlMembersMapping, true);
 }
Exemplo n.º 4
0
 public string ExportAnyType(XmlMembersMapping members)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 public XmlQualifiedName ExportTypeMapping(XmlMembersMapping xmlMembersMapping)
 {
     throw new NotImplementedException();
 }
        protected virtual object ReadMessage(XmlMembersMapping typeMap)
        {
            object[] parameters = new object[typeMap.Count];

            if (typeMap.HasWrapperElement)
            {
                // bug #79988: out parameters need to be initialized if they
                // are value types
                ArrayList members = ((ClassMap)typeMap.ObjectMap).AllMembers;
                for (int n = 0; n < members.Count; n++)
                {
                    XmlTypeMapMember mem = (XmlTypeMapMember)members [n];
                    if (!mem.IsReturnValue && mem.TypeData.IsValueType)
                    {
                        SetMemberValueFromAttr(mem, parameters, CreateInstance(
                                                   mem.TypeData.Type), true);
                    }
                }

                if (_format == SerializationFormat.Encoded)
                {
                    while (Reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        string root = Reader.GetAttribute("root", XmlSerializer.EncodingNamespace);
                        if (root == null || System.Xml.XmlConvert.ToBoolean(root))
                        {
                            break;
                        }
                        ReadReferencedElement();
                        Reader.MoveToContent();
                    }
                }

                while (Reader.NodeType != System.Xml.XmlNodeType.EndElement &&
                       // it could be an empty root element
                       Reader.ReadState == ReadState.Interactive)
                {
                    if (Reader.IsStartElement(typeMap.ElementName, typeMap.Namespace) ||
                        _format == SerializationFormat.Encoded)
                    {
                        ReadAttributeMembers((ClassMap)typeMap.ObjectMap, parameters, true);
                        if (Reader.IsEmptyElement)
                        {
                            Reader.Skip();
                            Reader.MoveToContent();
                            continue;
                        }
                        Reader.ReadStartElement();
                        ReadMembers((ClassMap)typeMap.ObjectMap, parameters, true, false);
                        ReadEndElement();
                        break;
                    }
                    else
                    {
                        UnknownNode(null);
                    }

                    Reader.MoveToContent();
                }
            }
            else
            {
                ReadMembers((ClassMap)typeMap.ObjectMap, parameters, true, _format == SerializationFormat.Encoded);
            }

            if (_format == SerializationFormat.Encoded)
            {
                ReadReferencedElements();
            }

            return(parameters);
        }
Exemplo n.º 7
0
        public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
        {
            CodeTypeDeclaration dummyClass = new CodeTypeDeclaration();

            ExportMembersMapCode(dummyClass, (ClassMap)xmlMembersMapping.ObjectMap, xmlMembersMapping.Namespace, null);
        }
Exemplo n.º 8
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping,
                                  bool exportEnclosingType)
 {
     _exporter.ExportMembersMapping(xmlMembersMapping, exportEnclosingType);
 }
Exemplo n.º 9
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     _exporter.ExportMembersMapping(xmlMembersMapping, false);
 }
Exemplo n.º 10
0
 public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
 {
     codeGenerator.ExportMembersMapping(xmlMembersMapping);
 }