Поделиться через


SoapDuration Класс

Определение

Предоставляет статические методы сериализации и десериализации TimeSpan в строку, отформатированную как XSD duration.

public ref class SoapDuration sealed
public sealed class SoapDuration
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class SoapDuration
type SoapDuration = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type SoapDuration = class
Public NotInheritable Class SoapDuration
Наследование
SoapDuration
Атрибуты

Примеры

В следующем примере кода показано, как использовать методы в SoapDuration классе для преобразования между TimeSpan объектом и строкой XSD duration .

#using <System.dll>
#using <System.Runtime.Remoting.dll>
using namespace System;
using namespace System::Runtime::Remoting::Metadata::W3cXsd2001;

int main()
{
   // Parse an XSD duration to create a TimeSpan object.
   // This is a duration of 2 years, 3 months, 9 days, 12 hours,
   // 35 minutes, 20 seconds, and 10 milliseconds.
   String^ xsdDuration = L"P2Y3M9DT12H35M20.0100000S";
   TimeSpan timeSpan = SoapDuration::Parse( xsdDuration );
   Console::WriteLine( L"The time span contains {0} days.",
      timeSpan.Days );
   Console::WriteLine( L"The time span contains {0} hours.",
      timeSpan.Hours );
   Console::WriteLine( L"The time span contains {0} minutes.",
      timeSpan.Minutes );
   Console::WriteLine( L"The time span contains {0} seconds.",
      timeSpan.Seconds );

   // Serialize a TimeSpan object as an XSD duration string.
   // This object represents a time span of 399 days, 12 hours,
   // 35 minutes, 20 seconds, and 10 milliseconds.
   TimeSpan duration = TimeSpan(399,12,35,20,10);
   Console::WriteLine( L"The duration in XSD format is {0}.",
      SoapDuration::ToString( duration ) );

   // Print the XSD type string of the SoapDuration class.
   Console::WriteLine( L"The XSD type of SoapDuration is {0}.",
      SoapDuration::XsdType );
}
using System;
using System.Runtime.Remoting.Metadata.W3cXsd2001;

public class Demo
{
    public static void Main(string[] args)
    {
        // Parse an XSD duration to create a TimeSpan object.
        // This is a duration of 2 years, 3 months, 9 days, 12 hours,
        // 35 minutes, 20 seconds, and 10 milliseconds.
        string xsdDuration = "P2Y3M9DT12H35M20.0100000S";
        TimeSpan timeSpan = SoapDuration.Parse(xsdDuration);
        Console.WriteLine("The time span contains {0} days.",
            timeSpan.Days);
        Console.WriteLine("The time span contains {0} hours.",
            timeSpan.Hours);
        Console.WriteLine("The time span contains {0} minutes.",
            timeSpan.Minutes);
        Console.WriteLine("The time span contains {0} seconds.",
            timeSpan.Seconds);

        // Serialize a TimeSpan object as an XSD duration string.
        // This object represents a time span of 399 days, 12 hours,
        // 35 minutes, 20 seconds, and 10 milliseconds.
        TimeSpan duration = new TimeSpan(399, 12, 35, 20, 10);
        Console.WriteLine("The duration in XSD format is {0}.",
            SoapDuration.ToString(duration));

        // Print the XSD type string of the SoapDuration class.
        Console.WriteLine("The XSD type of SoapDuration is {0}.",
            SoapDuration.XsdType);
    }
}

Комментарии

Дополнительные сведения о типах данных XSD см. в справочнике по типам данных XML.

Конструкторы

SoapDuration()

Создает экземпляр класса SoapDuration.

Свойства

XsdType

Получает язык определения XML-схемы (XSD) текущего типа SOAP.

Методы

Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
Parse(String)

Преобразует заданный String в объект TimeSpan.

ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)
ToString(TimeSpan)

Возвращает указанный объект TimeSpan в виде объекта String.

Применяется к