SoapDuration 类

定义

提供在 TimeSpan 与 XSD duration 格式的字符串之间进行序列化和反序列化的静态方法。Provides static methods for the serialization and deserialization of TimeSpan to a string that is formatted as 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 字符串之间进行转换 durationThe following code example shows how to use the methods in the SoapDuration class to convert between a TimeSpan object and an XSD duration string.

#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 数据类型参考For more information about XSD data types, see the XML Data Types Reference.

构造函数

SoapDuration()

创建 SoapDuration 的实例。Creates an instance of SoapDuration.

属性

XsdType

获取当前 SOAP 类型的 XML 架构定义语言 (XSD)。Gets the XML Schema definition language (XSD) of the current SOAP type.

方法

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Parse(String)

将指定的 String 转换为 TimeSpan 对象。Converts the specified String into a TimeSpan object.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
ToString(TimeSpan)

TimeSpan 的形式返回指定的 String 对象。Returns the specified TimeSpan object as a String.

适用于