|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Classe DataContractAttribute
Spazio dei nomi: System.Runtime.Serialization
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
Il tipo DataContractAttribute espone i seguenti membri.
| Nome | Descrizione | |
|---|---|---|
![]() ![]() ![]() | DataContractAttribute |
| Nome | Descrizione | |
|---|---|---|
![]() ![]() ![]() | IsReference | |
![]() ![]() ![]() | Name | |
![]() ![]() ![]() | Namespace | |
![]() | TypeId |
| Nome | Descrizione | |
|---|---|---|
![]() ![]() ![]() | Equals | Infrastruttura. |
![]() ![]() ![]() | GetHashCode | |
![]() ![]() ![]() | GetType | |
![]() | IsDefaultAttribute | |
![]() | Match | |
![]() ![]() ![]() | ToString |
| Nome | Descrizione | |
|---|---|---|
![]() ![]() | _Attribute.GetIDsOfNames | |
![]() ![]() | _Attribute.GetTypeInfo | |
![]() ![]() | _Attribute.GetTypeInfoCount | |
![]() ![]() | _Attribute.Invoke |
Attenzione |
|---|
contratti dati
Nota |
|---|
Documenti XML schema e lo strumento di SvcUtil
Riutilizzo dei tipi esistenti
Nota |
|---|
controllare la versione
namespace DataContractAttributeExample { // Set the Name and Namespace properties to new values. [DataContract(Name = "Customer", Namespace = "http://www.contoso.com")] class Person : IExtensibleDataObject { // To implement the IExtensibleDataObject interface, you must also // implement the ExtensionData property. private ExtensionDataObject extensionDataObjectValue; public ExtensionDataObject ExtensionData { get { return extensionDataObjectValue; } set { extensionDataObjectValue = value; } } [DataMember(Name = "CustName")] internal string Name; [DataMember(Name = "CustID")] internal int ID; public Person(string newName, int newID) { Name = newName; ID = newID; } } class Test { public static void Main() { try { WriteObject("DataContractExample.xml"); ReadObject("DataContractExample.xml"); Console.WriteLine("Press Enter to end"); Console.ReadLine(); } catch (SerializationException se) { Console.WriteLine ("The serialization operation failed. Reason: {0}", se.Message); Console.WriteLine(se.Data); Console.ReadLine(); } } public static void WriteObject(string path) { // Create a new instance of the Person class and // serialize it to an XML file. Person p1 = new Person("Mary", 1); // Create a new instance of a StreamWriter // to read and write the data. FileStream fs = new FileStream(path, FileMode.Create); XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(fs); DataContractSerializer ser = new DataContractSerializer(typeof(Person)); ser.WriteObject(writer, p1); Console.WriteLine("Finished writing object."); writer.Close(); fs.Close(); } public static void ReadObject(string path) { // Deserialize an instance of the Person class // from an XML file. First create an instance of the // XmlDictionaryReader. FileStream fs = new FileStream(path, FileMode.OpenOrCreate); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()); // Create the DataContractSerializer instance. DataContractSerializer ser = new DataContractSerializer(typeof(Person)); // Deserialize the data and read it from the instance. Person newPerson = (Person)ser.ReadObject(reader); Console.WriteLine("Reading this object:"); Console.WriteLine(String.Format("{0}, ID: {1}", newPerson.Name, newPerson.ID)); fs.Close(); } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.


