Edytuj

Udostępnij za pośrednictwem


XmlTypeMapping.TypeName Property

Definition

Gets the type name of the mapped object.

public:
 property System::String ^ TypeName { System::String ^ get(); };
public string TypeName { get; }
member this.TypeName : string
Public ReadOnly Property TypeName As String

Property Value

The type name of the mapped object.

Examples

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Collections;
using namespace System::Xml;
using namespace System::Text;

public ref class Thing
{
public:
   String^ ThingName;
};

[SoapType("TheGroup","http://www.cohowinery.com")]
public ref class Group
{
public:
   String^ GroupName;
   array<Thing^>^Things;

   [SoapElement(DataType="language")]
   static String^ Lang = "en";

   [SoapElement(DataType="integer")]
   String^ MyNumber;

   [SoapElement(DataType="duration")]
   static String^ ReDate = "8/31/01";
};

void GetMap( String^ filename )
{
   // Create an XmlSerializer instance.
   SoapReflectionImporter^ sri = gcnew SoapReflectionImporter;
   XmlTypeMapping^ map = sri->ImportTypeMapping( Group::typeid );
   Console::WriteLine( "ElementName: {0}", map->ElementName );
   Console::WriteLine( "Namespace: {0}", map->Namespace );
   Console::WriteLine( "TypeFullName: {0}", map->TypeFullName );
   Console::WriteLine( "TypeName: {0}", map->TypeName );
   XmlSerializer^ ser = gcnew XmlSerializer( map );
   Group^ xGroup = gcnew Group;
   xGroup->GroupName = "MyCar";
   xGroup->MyNumber = "5454";
   xGroup->Things = gcnew array<Thing^>(2); // {new Thing(), new Thing()};
   xGroup->Things[ 0 ] = gcnew Thing;
   xGroup->Things[ 1 ] = gcnew Thing;

   // To write the outer wrapper, use an XmlTextWriter.
   XmlTextWriter^ writer = gcnew XmlTextWriter( filename,Encoding::UTF8 );
   writer->Formatting = Formatting::Indented;
   writer->WriteStartElement( "wrapper" );
   ser->Serialize( writer, xGroup );
   writer->WriteEndElement();
   writer->Close();
}

int main()
{
   GetMap( "MyMap.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;

namespace Company{

[SoapType("TheGroup", "http://www.cohowinery.com")]
public class Group
{
   public string GroupName;
   public Thing[] Things;
   [SoapElement(DataType = "language")]
   public string Lang = "en";
   [SoapElement(DataType = "integer")]
   public string MyNumber;

   [SoapElement(DataType = "duration")]
   public string ReDate = "8/31/01";
}

public class Thing{ 
   public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();

      t.GetMap("MyMap.xml");
   }

   public void GetMap(string filename){
      // Create an XmlSerializer instance.
      XmlTypeMapping map = new SoapReflectionImporter().ImportTypeMapping(typeof(Group));
      Console.WriteLine("ElementName: " + map.ElementName);
      Console.WriteLine("Namespace: " + map.Namespace);
      Console.WriteLine("TypeFullName: " + map.TypeFullName);
      Console.WriteLine("TypeName: " + map.TypeName);
      XmlSerializer ser = new XmlSerializer(map);
      Group xGroup=  new Group();
      xGroup.GroupName= "MyCar";
      xGroup.MyNumber= 5454.ToString();
      xGroup.Things = new Thing[]{new Thing(), new Thing()};
      // To write the outer wrapper, use an XmlTextWriter.
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, xGroup);
      writer.WriteEndElement();
      writer.Close();
   }
}
}
Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections
Imports System.Xml
Imports System.Text


Namespace Company
    
<SoapType("TheGroup", "http://www.cohowinery.com")> _
Public Class Group

   ' The SoapElementAttribute specifies that the
   ' generated XML element name will be "Wheels"
   ' instead of "Vehicle".
   Public GroupName As String 
   public Things() As  Thing
   <SoapElement(DataType:= "language")> _
   Public Lang As String = "en"
   <SoapElement(DataType:= "integer")> _
   Public MyNumber As String 

   <SoapElement(DataType:= "duration")> _
   Public ReDate As String  = "8/31/01"
End Class

Public Class Thing 
   Public ThingName As String 
End Class

Public Class Test
   Shared Sub Main()
   
      Dim t As Test = new Test()

      t.GetMap("MyMap.xml")
   End Sub


   public Sub GetMap(filename As string )
      ' Create an XmlSerializer instance.
      Dim map As XmlTypeMapping = new SoapReflectionImporter().ImportTypeMapping(GetType(Group))
      Console.WriteLine("ElementName: " + map.ElementName)
      Console.WriteLine("Namespace: " + map.Namespace)
      Console.WriteLine("TypeFullName: " + map.TypeFullName)
      Console.WriteLine("TypeName: " + map.TypeName)
      Dim ser As XmlSerializer= new XmlSerializer(map)
      Dim xGroup As Group =  new Group()
      xGroup.GroupName= "MyCar"
      xGroup.MyNumber= 5454.ToString()
      xGroup.Things = new Thing(){new Thing(), new Thing()}
      ' To write the outer wrapper, use an XmlTextWriter.
      Dim writer As XmlTextWriter =  _
      new XmlTextWriter(filename, Encoding.UTF8)
      writer.Formatting = Formatting.Indented
      writer.WriteStartElement("wrapper")
      ser.Serialize(writer, xGroup)
      writer.WriteEndElement()
      writer.Close()
   End Sub
End Class

End namespace

Remarks

The type name is the class name of the mapped object.

You can also see the fully qualified name by examining the TypeFullName property.

Applies to