System.Xml.Serialization.SoapElementAttribute Class

Assembly: System.Xml.dll
Namespace: System.Xml.Serialization
Summary
Specifies that the public member value be serialized by the XmlSerializer as an encoded SOAP XML element.
C# Syntax:
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
public class SoapElementAttribute : Attribute
Remarks
The SoapElementAttribute class belongs to a family of attributes that controls how the XmlSerializer serializes, or deserializes, an object as encoded SOAP XML. The resulting XML conforms to section 5 of the World Wide Web Consortium (www.w3.org) document, "Simple Object Access Protocol (SOAP) 1.1". For a complete list of similar attributes, see the conceptual topic at MSDN: attributesthatcontrolsoapencodedserialization.

To serialize an object as an encoded SOAP message, you must construct the XmlSerializer using an XmlTypeMapping created with the SoapReflectionImporter.ImportTypeMapping method of the SoapReflectionImporter class.

Apply the SoapElementAttribute to a public field to direct the XmlSerializer to serialize the field as an encoded SOAP XML element. You can specify an alternative name for the attribute by setting the SoapAttributeAttribute.AttributeName property. Set the SoapAttributeAttribute.DataType property if the attribute must be given a specific XML schema definition (XSD) data type. If the attribute belongs to a specific XML namespace, set the SoapAttributeAttribute.Namespace property.

For more information about using attributes, see the conceptual topic at MSDN: extendingmetadatausingattributes.

Example
The following example serializes an instance of a class named Transportation that contains a field named Vehicle . A SoapElementAttribute is applied to the field. When the field is serialized, the XML element name is "Wheels" instead of "Vehicle". The SerializeOverride method creates a SoapElementAttribute and sets the SoapAttributes.SoapElement property of a SoapAttributes to the SoapElementAttribute. The SoapAttributes is added to a SoapAttributeOverrides that is used to create an XmlTypeMapping. An XmlSerializer is constructed with the XmlTypeMapping, and an instance of the Transportation class is again serialized. Because the SoapElementAttribute is used to override the serialization, the generated XML element name is now "Truck" instead of "Wheels".
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;
public class Transportation
{
   // The SoapElementAttribute specifies that the
   // generated XML element name will be "Wheels"
   // instead of "Vehicle".
   [SoapElement("Wheels")]
   public string Vehicle;
   [SoapElement(DataType = "dateTime")]
   public DateTime CreationDate;
   [SoapElement(IsNullable = true)]
   public Thing thing;
   
}

public class Thing{ 
   [SoapElement(IsNullable=true)] public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("SoapElementOriginal.xml");
      t.SerializeOverride("SoapElementOverride.xml");
      Console.WriteLine("Finished writing two XML files.");
   }

   // 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);
   }

   public void SerializeOverride(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer ser = CreateSoapOverrider();

      // Create the object and serialize it.
      Transportation myTransportation = 
      new Transportation();

      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate=DateTime.Now;
      myTransportation.thing = new Thing();

      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
   public void SerializeObject(string filename){
      // Create an XmlSerializer instance.
      XmlSerializer ser = new XmlSerializer(typeof(Transportation));
      Transportation myTransportation = 
      new Transportation();
      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate = DateTime.Now;
      myTransportation.thing = new Thing();
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
}

    
See also:
System.Xml.Serialization Namespace

System.Xml.Serialization.SoapElementAttribute Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the SoapElementAttribute class.
ctor #2 Overloaded:
.ctor(string elementName)

Initializes a new instance of the SoapElementAttribute class and specifies the name of the XML element.
Public Properties
DataType Read-write

Gets or sets the XML Schema definition language (XSD) data type of the generated XML element.
ElementName Read-write

Gets or sets the name of the generated XML element.
IsNullable Read-write

Gets or sets a value indicating whether the XmlSerializer should serialize a member that is set to null into the xsi:nil attribute set to true.
TypeId
(inherited from System.Attribute)
Read-only

See base class member description: System.Attribute.TypeId


When implemented in a derived class, gets a unique identifier for this Attribute.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Attribute)
See base class member description: System.Attribute.GetHashCode


Returns the hash code for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
IsDefaultAttribute
(inherited from System.Attribute)
See base class member description: System.Attribute.IsDefaultAttribute


When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class.
Match
(inherited from System.Attribute)
See base class member description: System.Attribute.Match


When overridden in a derived class, returns a value indicating whether this instance equals a specified object.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Serialization.SoapElementAttribute Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the SoapElementAttribute class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public SoapElementAttribute();
Example
The following example serializes an instance of a class named Transportation that contains a field named Vehicle . A SoapElementAttribute is applied to the field. When the field is serialized, the XML element name is "Wheels" instead of "Vehicle". The SerializeOverride method creates a SoapElementAttribute and sets the SoapAttributes.SoapElement property of a SoapAttributes to the SoapElementAttribute. The SoapAttributes is added to a SoapAttributeOverrides that is used to create an XmlTypeMapping. An XmlSerializer is constructed with the XmlTypeMapping, and an instance of the Transportation class is again serialized. Because the SoapElementAttribute is used to override the serialization, the generated XML element name is now "Truck" instead of "Wheels".
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;
public class Transportation
{
   // The SoapElementAttribute specifies that the
   // generated XML element name will be "Wheels"
   // instead of "Vehicle".
   [SoapElement("Wheels")]
   public string Vehicle;
   [SoapElement(DataType = "dateTime")]
   public DateTime CreationDate;
   [SoapElement(IsNullable = true)]
   public Thing thing;
   
}

public class Thing{ 
   [SoapElement(IsNullable=true)] public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("SoapElementOriginal.xml");
      t.SerializeOverride("SoapElementOverride.xml");
      Console.WriteLine("Finished writing two XML files.");
   }

   // 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);
   }

   public void SerializeOverride(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer ser = CreateSoapOverrider();

      // Create the object and serialize it.
      Transportation myTransportation = 
      new Transportation();

      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate=DateTime.Now;
      myTransportation.thing = new Thing();

      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
   public void SerializeObject(string filename){
      // Create an XmlSerializer instance.
      XmlSerializer ser = new XmlSerializer(typeof(Transportation));
      Transportation myTransportation = 
      new Transportation();
      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate = DateTime.Now;
      myTransportation.thing = new Thing();
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
}

    

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the SoapElementAttribute class and specifies the name of the XML element.
C# Syntax:
public SoapElementAttribute(
   string elementName
);
Parameters:

elementName

The XML element name of the serialized member.

Example
The following example serializes an instance of a class named Transportation that contains a field named Vehicle . A SoapElementAttribute is applied to the field. When the field is serialized, the XML element name is "Wheels" instead of "Vehicle". The SerializeOverride method creates a SoapElementAttribute and sets the SoapAttributes.SoapElement property of a SoapAttributes to the SoapElementAttribute. The SoapAttributes is added to a SoapAttributeOverrides that is used to create an XmlTypeMapping. An XmlSerializer is constructed with the XmlTypeMapping, and an instance of the Transportation class is again serialized. Because the SoapElementAttribute is used to override the serialization, the generated XML element name is now "Truck" instead of "Wheels".
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;
public class Transportation
{
   // The SoapElementAttribute specifies that the
   // generated XML element name will be "Wheels"
   // instead of "Vehicle".
   [SoapElement("Wheels")]
   public string Vehicle;
   [SoapElement(DataType = "dateTime")]
   public DateTime CreationDate;
   [SoapElement(IsNullable = true)]
   public Thing thing;
   
}

public class Thing{ 
   [SoapElement(IsNullable=true)] public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("SoapElementOriginal.xml");
      t.SerializeOverride("SoapElementOverride.xml");
      Console.WriteLine("Finished writing two XML files.");
   }

   // 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);
   }

   public void SerializeOverride(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer ser = CreateSoapOverrider();

      // Create the object and serialize it.
      Transportation myTransportation = 
      new Transportation();

      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate=DateTime.Now;
      myTransportation.thing = new Thing();

      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
   public void SerializeObject(string filename){
      // Create an XmlSerializer instance.
      XmlSerializer ser = new XmlSerializer(typeof(Transportation));
      Transportation myTransportation = 
      new Transportation();
      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate = DateTime.Now;
      myTransportation.thing = new Thing();
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
}

    

Return to top


Property: DataType (read-write)
Summary
Gets or sets the XML Schema definition language (XSD) data type of the generated XML element.
C# Syntax:
public string DataType {get; set;}
Remarks
The following table lists the XML Schema simple data types with their .NET equivalents.

For the XML Schema base64Binary and hexBinary data types, use an array of Byte structures, and apply a SoapElementAttribute with the SoapAttributeAttribute.DataType set to "base64Binary" or "hexBinary", as appropriate. For the XML Schema time and date data types, use the DateTime type and apply the SoapElementAttribute with the SoapElementAttribute.DataType set to "date" or "time".

For every XML Schema data type that is mapped to a string, apply the SoapElementAttribute with its SoapElementAttribute.DataType property set to the XML Schema type. Note that this will not change the serialization format, only the schema for the member.



Note The property is case-sensitive, so you must set it exactly to one of the XML Schema data types.

Note Passing binary data as an XML element is more efficient then passing it as an XML attribute.

For more information about XML data types, see the World Wide Web Consortium (www.w3.org) document, "XML Schema Part 2: Datatypes".



XSD data type .NET data type
anyURI String
base64Binary Array of Byte objects
boolean Boolean
byte SByte
date DateTime
dateTime DateTime
decimal Decimal
double Double
ENTITY String
ENTITIES String
float Single
gDay String
gMonth String
gMonthDay String
gYear String
gYearMonth String
hexBinary Array of Byte objects
ID String
IDREF String
IDREFS String
int Int32
long Int64
Name String
NCName String
negativeInteger String
NMTOKEN String
NMTOKENS String
normalizedString String
nonNegativeInteger String
nonPositiveInteger String
NOTATION String
positiveInteger String
QName XmlQualifiedName
recurringDate String
duration String
string String
short Int16
time DateTime
token String
unsignedByte Byte
unsignedInt UInt32
unsignedLong UInt64
unsignedShort UInt16
Example
The following example serializes an instance of a class named Transportation that contains a field named Vehicle . A SoapElementAttribute is applied to the field. When the field is serialized, the XML element name is "Wheels" instead of "Vehicle". The SerializeOverride method creates a SoapElementAttribute and sets the SoapAttributes.SoapElement property of a SoapAttributes to the SoapElementAttribute. The SoapAttributes is added to a SoapAttributeOverrides that is used to create an XmlTypeMapping. An XmlSerializer is constructed with the XmlTypeMapping, and an instance of the Transportation class is again serialized. Because the SoapElementAttribute is used to override the serialization, the generated XML element name is now "Truck" instead of "Wheels".
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;
public class Transportation
{
   // The SoapElementAttribute specifies that the
   // generated XML element name will be "Wheels"
   // instead of "Vehicle".
   [SoapElement("Wheels")]
   public string Vehicle;
   [SoapElement(DataType = "dateTime")]
   public DateTime CreationDate;
   [SoapElement(IsNullable = true)]
   public Thing thing;
   
}

public class Thing{ 
   [SoapElement(IsNullable=true)] public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("SoapElementOriginal.xml");
      t.SerializeOverride("SoapElementOverride.xml");
      Console.WriteLine("Finished writing two XML files.");
   }

   // 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);
   }

   public void SerializeOverride(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer ser = CreateSoapOverrider();

      // Create the object and serialize it.
      Transportation myTransportation = 
      new Transportation();

      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate=DateTime.Now;
      myTransportation.thing = new Thing();

      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
   public void SerializeObject(string filename){
      // Create an XmlSerializer instance.
      XmlSerializer ser = new XmlSerializer(typeof(Transportation));
      Transportation myTransportation = 
      new Transportation();
      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate = DateTime.Now;
      myTransportation.thing = new Thing();
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
}

    

Return to top


Property: ElementName (read-write)
Summary
Gets or sets the name of the generated XML element.
C# Syntax:
public string ElementName {get; set;}
Example
The following example serializes an instance of a class named Transportation that contains a field named Vehicle . A SoapElementAttribute is applied to the field. When the field is serialized, the XML element name is "Wheels" instead of "Vehicle". The SerializeOverride method creates a SoapElementAttribute and sets the SoapAttributes.SoapElement property of a SoapAttributes to the SoapElementAttribute. The SoapAttributes is added to a SoapAttributeOverrides that is used to create an XmlTypeMapping. An XmlSerializer is constructed with the XmlTypeMapping, and an instance of the Transportation class is again serialized. Because the SoapElementAttribute is used to override the serialization, the generated XML element name is now "Truck" instead of "Wheels".
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;
public class Transportation
{
   // The SoapElementAttribute specifies that the
   // generated XML element name will be "Wheels"
   // instead of "Vehicle".
   [SoapElement("Wheels")]
   public string Vehicle;
   [SoapElement(DataType = "dateTime")]
   public DateTime CreationDate;
   [SoapElement(IsNullable = true)]
   public Thing thing;
   
}

public class Thing{ 
   [SoapElement(IsNullable=true)] public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("SoapElementOriginal.xml");
      t.SerializeOverride("SoapElementOverride.xml");
      Console.WriteLine("Finished writing two XML files.");
   }

   // 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);
   }

   public void SerializeOverride(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer ser = CreateSoapOverrider();

      // Create the object and serialize it.
      Transportation myTransportation = 
      new Transportation();

      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate=DateTime.Now;
      myTransportation.thing = new Thing();

      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
   public void SerializeObject(string filename){
      // Create an XmlSerializer instance.
      XmlSerializer ser = new XmlSerializer(typeof(Transportation));
      Transportation myTransportation = 
      new Transportation();
      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate = DateTime.Now;
      myTransportation.thing = new Thing();
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
}

    

Return to top


Property: IsNullable (read-write)
Summary
Gets or sets a value indicating whether the XmlSerializer should serialize a member that is set to null into the xsi:nil attribute set to true.
C# Syntax:
public bool IsNullable {get; set;}
Remarks
The XML schema specification for structures allows an XML document to explicitly signal that an element's content is missing. Such an element contains the attribute xsi:nil set to true. For more information, see the World Wide Web Consortium (www.w3.org) specification named "XML Schema Part 1: Structures".

If the SoapElementAttribute.IsNullable property is set to true, the xsi:nil attribute is generated for class members that have been set to null. For example, if you set a field named MyStringArray to null, the XmlSerializer generates the following XML code.

              <MyStringArray xsi:nil = "true" />
            

If the XmlElementAttribute.IsNullable property is false, no XML element is generated.



Note You cannot apply the XmlElementAttribute.IsNullable property to a member typed as a value type because a value type cannot contain null.

Return to top


Property: TypeId (read-only)
Inherited
See base class member description: System.Attribute.TypeId

Summary
When implemented in a derived class, gets a unique identifier for this Attribute.
C# Syntax:
public virtual object TypeId {get;}
Remarks
As implemented, this identifier is merely the Type of the attribute. However, it is intended that the unique identifier be used to identify two attributes of the same type.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~SoapElementAttribute();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Attribute.GetHashCode

Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: IsDefaultAttribute()
Inherited
See base class member description: System.Attribute.IsDefaultAttribute

Summary
When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class.
C# Syntax:
public virtual bool IsDefaultAttribute();
Return Value:
true if this instance is the default attribute for the class; otherwise, false.
Remarks
The default implementation of this class returns false, and must be implemented in the derived class to be useful to that class.

The implementation of this method in a derived class compares the value of this instance to a standard, default value obtained by some means, then returns a Boolean value that indicates whether the value of this instance is equal to the standard. The standard value is typically coded as a constant in the implementation, or stored programmatically in a field used by the implementation.

Return to top


Method: Match(
   object obj
)
Inherited
See base class member description: System.Attribute.Match

Summary
When overridden in a derived class, returns a value indicating whether this instance equals a specified object.
C# Syntax:
public virtual bool Match(
   object obj
);
Parameters:

obj

An Object to compare with this instance of Attribute.

Return Value:
true if this instance equals obj; otherwise, false.
Remarks
This method determines if one Attribute equals another. Its default implementation is the same as Attribute.Equals, which performs a value and reference comparison. Override this method to implement support for attribute values, such as flags or bitfields, that consist of components that are meaningful in themselves. For example, consider an attribute whose value is a binary field divided into a bitfield of flags. Two instances of this attribute have one flag in set in common while all the other flags differ. The Equal method cannot determine that the two instances have the same flag set, but the Match method can.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.