コード例 #1
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);
    }
コード例 #2
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));
    }
コード例 #3
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);
    }
コード例 #4
0
        public void ElementNameDefault()
        {
            SoapElementAttribute attr = new SoapElementAttribute();

            Assert.AreEqual(string.Empty, attr.ElementName, "#1");

            attr.ElementName = null;
            Assert.AreEqual(string.Empty, attr.ElementName, "#2");
        }
コード例 #5
0
 /// <include file='doc\SoapAttributes.uex' path='docs/doc[@for="SoapAttributes.SoapAttributes1"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapAttributes(ICustomAttributeProvider provider)
 {
     object[] attrs = provider.GetCustomAttributes(false);
     for (int i = 0; i < attrs.Length; i++)
     {
         if (attrs[i] is SoapIgnoreAttribute || attrs[i] is ObsoleteAttribute)
         {
             _soapIgnore = true;
             break;
         }
         else if (attrs[i] is SoapElementAttribute)
         {
             _soapElement = (SoapElementAttribute)attrs[i];
         }
         else if (attrs[i] is SoapAttributeAttribute)
         {
             _soapAttribute = (SoapAttributeAttribute)attrs[i];
         }
         else if (attrs[i] is SoapTypeAttribute)
         {
             _soapType = (SoapTypeAttribute)attrs[i];
         }
         else if (attrs[i] is SoapEnumAttribute)
         {
             _soapEnum = (SoapEnumAttribute)attrs[i];
         }
         else if (attrs[i] is DefaultValueAttribute)
         {
             _soapDefaultValue = ((DefaultValueAttribute)attrs[i]).Value;
         }
     }
     if (_soapIgnore)
     {
         _soapElement      = null;
         _soapAttribute    = null;
         _soapType         = null;
         _soapEnum         = null;
         _soapDefaultValue = null;
     }
 }
コード例 #6
0
        public void IsNullableDefault()
        {
            SoapElementAttribute attr = new SoapElementAttribute();

            Assert.AreEqual(false, attr.IsNullable);
        }