コード例 #1
0
    // Return an XmlSerializer used for overriding.
    public XmlSerializer CreateSoapOverrider()
    {
        // Create the SoapAttributes and SoapAttributeOverrides objects.
        SoapAttributes soapAttrs = new SoapAttributes();

        SoapAttributeOverrides soapOverrides =
            new SoapAttributeOverrides();

        /* Create an SoapElementAttribute to override
         * the Vehicles property. */
        SoapElementAttribute soapElement1 =
            new SoapElementAttribute("Truck");

        // Set the SoapElement to the object.
        soapAttrs.SoapElement = soapElement1;

        /* Add the SoapAttributes to the SoapAttributeOverrides,
         * specifying the member to override. */
        soapOverrides.Add(typeof(Transportation), "Vehicle", soapAttrs);

        // Create the XmlSerializer, and return it.
        XmlTypeMapping myTypeMapping = (new SoapReflectionImporter
                                            (soapOverrides)).ImportTypeMapping(typeof(Transportation));

        return(new XmlSerializer(myTypeMapping));
    }
コード例 #2
0
ファイル: attadd.cs プロジェクト: winxxp/samples
    private XmlSerializer CreateOverrideSerializer()
    {
        SoapAttributeOverrides mySoapAttributeOverrides =
            new SoapAttributeOverrides();
        SoapAttributes mySoapAttributes = new SoapAttributes();

        SoapElementAttribute mySoapElement = new SoapElementAttribute();

        mySoapElement.ElementName    = "TeamName";
        mySoapAttributes.SoapElement = mySoapElement;
        // Add the SoapAttributes to the
        // mySoapAttributeOverridesrides object.
        mySoapAttributeOverrides.Add(typeof(Group), "GroupName",
                                     mySoapAttributes);
        // Get the SoapAttributes with the Item property.
        SoapAttributes thisSoapAtts =
            mySoapAttributeOverrides[typeof(Group), "GroupName"];

        Console.WriteLine("New serialized element name: " +
                          thisSoapAtts.SoapElement.ElementName);

        // Create an XmlTypeMapping that is used to create an instance
        // of the XmlSerializer. Then return the XmlSerializer object.
        XmlTypeMapping myMapping = (new SoapReflectionImporter(
                                        mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));

        XmlSerializer ser = new XmlSerializer(myMapping);

        return(ser);
    }
コード例 #3
0
    private XmlSerializer CreateOverrideSerializer()
    {
        // Create and return an XmlSerializer instance used to
        // override and create SOAP messages.
        SoapAttributeOverrides mySoapAttributeOverrides =
            new SoapAttributeOverrides();
        SoapAttributes soapAtts = new SoapAttributes();

        // Override the SoapTypeAttribute.
        SoapTypeAttribute soapType = new SoapTypeAttribute();

        soapType.TypeName        = "Team";
        soapType.IncludeInSchema = false;
        soapType.Namespace       = "http://www.microsoft.com";
        soapAtts.SoapType        = soapType;

        mySoapAttributeOverrides.Add(typeof(Group), soapAtts);

        // Create an XmlTypeMapping that is used to create an instance
        // of the XmlSerializer. Then return the XmlSerializer object.
        XmlTypeMapping myMapping = (new SoapReflectionImporter(
                                        mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));

        XmlSerializer ser = new XmlSerializer(myMapping);

        return(ser);
    }
コード例 #4
0
ファイル: soapattributeex2.cs プロジェクト: ruo2012/samples-1
    private XmlSerializer CreateOverrideSerializer()
    {
        SoapAttributeOverrides mySoapAttributeOverrides =
            new SoapAttributeOverrides();
        SoapAttributes mySoapAttributes = new SoapAttributes();
        // Create a new SoapAttributeAttribute to override the
        // one applied to the Group class. The resulting XML
        // stream will use the new namespace and attribute name.
        SoapAttributeAttribute mySoapAttribute =
            new SoapAttributeAttribute();

        mySoapAttribute.AttributeName = "TeamName";
        // Change the Namespace.
        mySoapAttribute.Namespace = "http://www.cohowinery.com";

        mySoapAttributes.SoapAttribute = mySoapAttribute;
        mySoapAttributeOverrides.
        Add(typeof(Group), "GroupName", mySoapAttributes);

        XmlTypeMapping myMapping = (new SoapReflectionImporter
                                        (mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));

        XmlSerializer ser = new XmlSerializer(myMapping);

        return(ser);
    }
コード例 #5
0
        public SoapTypeSerializationSource(Type type, SoapAttributeOverrides attributeOverrides, string namspace, Type[] includedTypes)
            : base(namspace, includedTypes)
        {
            this.attributeOverrides = attributeOverrides;

            this.type = type;
        }
コード例 #6
0
    private XmlSerializer CreateOverrideSerializer()
    {
        SoapAttributeOverrides mySoapAttributeOverrides =
            new SoapAttributeOverrides();
        SoapAttributes soapAtts = new SoapAttributes();

        SoapElementAttribute mySoapElement = new SoapElementAttribute();

        mySoapElement.ElementName = "xxxx";
        soapAtts.SoapElement      = mySoapElement;
        mySoapAttributeOverrides.Add(typeof(Group), "PostitiveInt",
                                     soapAtts);

        // Override the IgnoreThis property.
        SoapIgnoreAttribute myIgnore = new SoapIgnoreAttribute();

        soapAtts            = new SoapAttributes();
        soapAtts.SoapIgnore = false;
        mySoapAttributeOverrides.Add(typeof(Group), "IgnoreThis",
                                     soapAtts);

        // Override the GroupType enumeration.
        soapAtts = new SoapAttributes();
        SoapEnumAttribute xSoapEnum = new SoapEnumAttribute();

        xSoapEnum.Name    = "Over1000";
        soapAtts.SoapEnum = xSoapEnum;

        // Add the SoapAttributes to the
        // mySoapAttributeOverridesrides object.
        mySoapAttributeOverrides.Add(typeof(GroupType), "A",
                                     soapAtts);

        // Create second enumeration and add it.
        soapAtts          = new SoapAttributes();
        xSoapEnum         = new SoapEnumAttribute();
        xSoapEnum.Name    = "ZeroTo1000";
        soapAtts.SoapEnum = xSoapEnum;
        mySoapAttributeOverrides.Add(typeof(GroupType), "B",
                                     soapAtts);

        // Override the Group type.
        soapAtts = new SoapAttributes();
        SoapTypeAttribute soapType = new SoapTypeAttribute();

        soapType.TypeName = "Team";
        soapAtts.SoapType = soapType;
        mySoapAttributeOverrides.Add(typeof(Group), soapAtts);

        // Create an XmlTypeMapping that is used to create an instance
        // of the XmlSerializer. Then return the XmlSerializer object.
        XmlTypeMapping myMapping = (new SoapReflectionImporter(
                                        mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));

        XmlSerializer ser = new XmlSerializer(myMapping);

        return(ser);
    }
コード例 #7
0
 /// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.SoapReflectionImporter3"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides, string defaultNamespace)
 {
     if (defaultNamespace == null)
     {
         defaultNamespace = String.Empty;
     }
     if (attributeOverrides == null)
     {
         attributeOverrides = new SoapAttributeOverrides();
     }
     _attributeOverrides = attributeOverrides;
     _defaultNs          = defaultNamespace;
     _typeScope          = new TypeScope();
     _modelScope         = new ModelScope(_typeScope);
 }
コード例 #8
0
        public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides, string defaultNamespace)
        {
            if (defaultNamespace == null)
            {
                initialDefaultNamespace = String.Empty;
            }
            else
            {
                initialDefaultNamespace = defaultNamespace;
            }

            if (attributeOverrides == null)
            {
                this.attributeOverrides = new SoapAttributeOverrides();
            }
            else
            {
                this.attributeOverrides = attributeOverrides;
            }
        }
コード例 #9
0
    private XmlSerializer CreateOverrideSerializer()
    {
        SoapAttributeOverrides mySoapAttributeOverrides =
            new SoapAttributeOverrides();
        SoapAttributes soapAtts = new SoapAttributes();
        // Create a new DefaultValueAttribute object for the GroupName
        // property.
        DefaultValueAttribute newDefault =
            new DefaultValueAttribute("Team1");

        soapAtts.SoapDefaultValue = newDefault;

        mySoapAttributeOverrides.Add(typeof(Group), "GroupName",
                                     soapAtts);

        // Create an XmlTypeMapping that is used to create an instance
        // of the XmlSerializer. Then return the XmlSerializer object.
        XmlTypeMapping myMapping = (new SoapReflectionImporter(
                                        mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));

        XmlSerializer ser = new XmlSerializer(myMapping);

        return(ser);
    }
コード例 #10
0
    private void SerializeOverride(string fileName)
    {
        SoapAttributeOverrides soapOver = new SoapAttributeOverrides();
        SoapAttributes         SoapAtts = new SoapAttributes();

        // Add a SoapEnumAttribute for the GroupType.A enumerator.
        // Instead of 'A'  it will be "West".
        SoapEnumAttribute soapEnum = new SoapEnumAttribute("West");

        // Override the "A" enumerator.
        SoapAtts.SoapEnum = soapEnum;
        soapOver.Add(typeof(GroupType), "A", SoapAtts);

        // Add another SoapEnumAttribute for the GroupType.B enumerator.
        // Instead of //B// it will be "East".
        SoapAtts          = new SoapAttributes();
        soapEnum          = new SoapEnumAttribute();
        soapEnum.Name     = "East";
        SoapAtts.SoapEnum = soapEnum;
        soapOver.Add(typeof(GroupType), "B", SoapAtts);

        // Create an XmlSerializer used for overriding.
        XmlTypeMapping map =
            new SoapReflectionImporter(soapOver).
            ImportTypeMapping(typeof(Group));
        XmlSerializer ser     = new XmlSerializer(map);
        Group         myGroup = new Group();

        myGroup.GroupName = ".NET";
        myGroup.Grouptype = GroupType.B;
        // Writing the file requires a TextWriter.
        TextWriter writer = new StreamWriter(fileName);

        ser.Serialize(writer, myGroup);
        writer.Close();
    }
コード例 #11
0
 /// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.SoapReflectionImporter2"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides) : this(attributeOverrides, null)
 {
 }
コード例 #12
0
 public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides, string defaultNamespace)
 {
 }
コード例 #13
0
 public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides)
 {
 }
コード例 #14
0
        public static string ObjectToXmlString_second(Object _object, Type objType)
        {
            // Create and return an XmlSerializer instance used to
            // override and create SOAP messages.
            SoapAttributeOverrides mySoapAttributeOverrides = new SoapAttributeOverrides();
            SoapAttributes         soapAtts = new SoapAttributes();

            // Override the SoapTypeAttribute.
            SoapTypeAttribute soapType = new SoapTypeAttribute();

            //soapType.TypeName = "Team";
            soapType.IncludeInSchema = false;
            //soapType.Namespace = "http://www.microsoft.com";

            // https://docs.microsoft.com/en-us/dotnet/api/system.xml.serialization.soaptypeattribute.includeinschema?view=netframework-4.8
            // https://docs.microsoft.com/en-us/dotnet/standard/data/xml/
            // https://stackoverflow.com/questions/1729711/prevent-xmlserializer-from-emitting-xsitype-on-inherited-types/1730412#1730412
            // https://stackoverflow.com/questions/1729711/prevent-xmlserializer-from-emitting-xsitype-on-inherited-types/1730412
            // https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/dkwy2d72(v=vs.100)
            // https://csharp.hotexamples.com/examples/System.Xml/XmlWriterSettings/-/php-xmlwritersettings-class-examples.html

            //mySoapAttributeOverrides.Add(typeof(QuoteData), soapAtts);

            mySoapAttributeOverrides.Add(objType, soapAtts);


            // Serializes a class named Group as a SOAP message.
            XmlTypeMapping myTypeMapping =
                new SoapReflectionImporter(mySoapAttributeOverrides).ImportTypeMapping(objType);


            XmlSerializer mySerializer = new XmlSerializer(myTypeMapping);
            //XmlSerializer mySerializer = new XmlSerializer(objType);

            XmlWriterSettings settings = new XmlWriterSettings();


            // this removes <?xml version="1.0" encoding="utf-16"?>
            //settings.ConformanceLevel = ConformanceLevel.Document;
            //settings.ConformanceLevel = ConformanceLevel.Auto;

            settings.OmitXmlDeclaration = true;

            settings.Indent = false;

            // this removes <?xml version="1.0" encoding="utf-16"?>
            //settings.OmitXmlDeclaration = true;

            settings.NewLineChars    = string.Empty;
            settings.NewLineHandling = NewLineHandling.None;

            string xmlStr = string.Empty;

            using (StringWriter stringWriter = new StringWriter())
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
                {
                    mySerializer.Serialize(xmlWriter, _object);

                    xmlStr = stringWriter.ToString();
                    xmlWriter.Close();
                }
                stringWriter.Close();
            }

            return(xmlStr);
        }
 public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides, string defaultNamespace)
 {
 }
 public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides)
 {
 }