本文整理汇总了C#中System.Xml.Serialization.SoapAttributeOverrides.Item属性的典型用法代码示例。如果您正苦于以下问题:C# SoapAttributeOverrides.Item属性的具体用法?C# SoapAttributeOverrides.Item怎么用?C# SoapAttributeOverrides.Item使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Xml.Serialization.SoapAttributeOverrides
的用法示例。
在下文中一共展示了SoapAttributeOverrides.Item属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
// The name of this type will be overridden using
// the SoapTypeAttribute.
public class Group
{
public string GroupName;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeOverride("GetSoapAttributes2.xml");
}
public void SerializeOverride(string filename)
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Create an instance of the class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.GroupName = ".NET";
// Serialize the class, and close the TextWriter.
overRideSerializer.Serialize(writer, myGroup);
writer.Close();
}
private XmlSerializer CreateOverrideSerializer()
{
SoapAttributeOverrides mySoapAttributeOverrides =
new SoapAttributeOverrides();
SoapAttributes mySoapAttributes = new SoapAttributes();
SoapTypeAttribute mySoapType = new SoapTypeAttribute();
mySoapType.TypeName= "Team";
mySoapAttributes.SoapType = mySoapType;
// Add the SoapAttributes to the
// mySoapAttributeOverridesrides object.
mySoapAttributeOverrides.Add(typeof(Group), mySoapAttributes);
// Get the SoapAttributes with the Item property.
SoapAttributes thisSoapAtts =
mySoapAttributeOverrides[typeof(Group)];
Console.WriteLine("New serialized type name: " +
thisSoapAtts.SoapType.TypeName);
// 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: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class Group
{
// Override the serialization of this member.
public string GroupName;
}
public class Run
{
public static void Main()
{
Run test = new Run();
test.SerializeOverride("GetSoapAttributes.xml");
}
public void SerializeOverride(string filename)
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Create an instance of the class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.GroupName = ".NET";
// Serialize the class, and close the TextWriter.
overRideSerializer.Serialize(writer, myGroup);
writer.Close();
}
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;
}
}