XAttribute.Explicit Operator

Definicja

Przeciążenia

Explicit(XAttribute to Nullable<Int64>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Int64.

Explicit(XAttribute to Nullable<Single>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Single.

Explicit(XAttribute to Nullable<TimeSpan>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> TimeSpan.

Explicit(XAttribute to Nullable<UInt32>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> UInt32.

Explicit(XAttribute to Nullable<UInt64>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> UInt64.

Explicit(XAttribute to TimeSpan)

Rzutuj wartość tej XAttribute wartości na wartość TimeSpan.

Explicit(XAttribute to String)

Rzutuj wartość tej XAttribute wartości na wartość String.

Explicit(XAttribute to Nullable<Int32>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Int32.

Explicit(XAttribute to UInt32)

Rzutowanie wartości tej XAttribute wartości na wartość UInt32.

Explicit(XAttribute to UInt64)

Rzutowanie wartości tej XAttribute wartości na wartość UInt64.

Explicit(XAttribute to Single)

Rzutuj wartość tej XAttribute wartości na wartość Single.

Explicit(XAttribute to Nullable<Guid>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Guid.

Explicit(XAttribute to Nullable<Decimal>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Decimal.

Explicit(XAttribute to Decimal)

Rzutuj wartość tej XAttribute wartości na wartość Decimal.

Explicit(XAttribute to Nullable<DateTimeOffset>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> DateTimeOffset.

Explicit(XAttribute to Nullable<DateTime>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> DateTime.

Explicit(XAttribute to Nullable<Boolean>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Boolean.

Explicit(XAttribute to Int64)

Rzutuj wartość tej XAttribute wartości na wartość Int64.

Explicit(XAttribute to Int32)

Rzutuj wartość tej XAttribute wartości na wartość Int32.

Explicit(XAttribute to Guid)

Rzutuj wartość tej XAttribute wartości na wartość Guid.

Explicit(XAttribute to Double)

Rzutuj wartość tej XAttribute wartości na wartość Double.

Explicit(XAttribute to Nullable<Double>)

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Double.

Explicit(XAttribute to DateTimeOffset)

Rzutuj wartość tej XAttribute wartości na wartość DateTimeOffset.

Explicit(XAttribute to DateTime)

Rzutuj wartość tej XAttribute wartości na wartość DateTime.

Explicit(XAttribute to Boolean)

Rzutowanie wartości tej XAttribute wartości na wartość Boolean.

Explicit(XAttribute to Nullable<Int64>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Int64.

public:
 static explicit operator Nullable<long>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator long? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator long? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<int64>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of Long)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .Int64

Zwraca

Nullable<Int64>

Int64 Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Int64 wartości.

Przykłady

Poniższy przykład tworzy atrybut z długą zawartością całkowitą. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu Int64.

XElement root = new XElement("Root",   
    new XAttribute("Att", 9223372036854775807)  
);  
long? value = (long?)root.Attribute("Att");  
Console.WriteLine("Nullable long: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att="9223372036854775807"/>  
Dim value As Nullable(Of Long) = CType(root.Attribute("Att"), Nullable(Of Long))  
Console.WriteLine("Nullable long: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable long: value=9223372036854775807  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<Single>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Single.

public:
 static explicit operator Nullable<float>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator float? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator float? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<single>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of Single)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Nullable<T> .Single

Zwraca

Nullable<Single>

Single Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Single wartości.

Przykłady

Poniższy przykład tworzy atrybut z pojedynczą precyzją zawartości zmiennoprzecinkowe. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu Single.

XElement root = new XElement("Root",   
    new XAttribute("Att", 3.402823e38)  
);  
float? value = (float?)root.Attribute("Att");  
Console.WriteLine("Nullable Single: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att="3.402823E+38"/>  
Dim value As Nullable(Of Single) = CType(root.Attribute("Att"), Nullable(Of Single))  
Console.WriteLine("Nullable Single: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable Single: value=3.402823E+38  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<TimeSpan>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> TimeSpan.

public:
 static explicit operator Nullable<TimeSpan>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator TimeSpan? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator TimeSpan? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<TimeSpan>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of TimeSpan)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .TimeSpan

Zwraca

Nullable<TimeSpan>

TimeSpan Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej TimeSpan wartości.

Przykłady

Poniższy przykład tworzy atrybut z zawartością przedziału czasu. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu TimeSpan.

XElement root = new XElement("Root",  
    new XAttribute("Att", new TimeSpan(1, 5, 30))  
);  
TimeSpan? value = (TimeSpan?)root.Attribute("Att");  
Console.WriteLine("Nullable TimeSpan: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att=<%= New TimeSpan(1, 5, 30) %>/>  
Dim value As Nullable(Of TimeSpan) = CType(root.Attribute("Att"), Nullable(Of TimeSpan))  
Console.WriteLine("Nullable TimeSpan: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable TimeSpan: value=01:05:30  

Uwagi

Przestrzeń wartości atrybutu lub elementu zawierającego zawartość przedziału czasu jest ściśle powiązana z zawartością czasu trwania, zgodnie z opisem w iso 8601. Podczas tworzenia atrybutu lub elementu zawierającego zawartość przedziału czasu wartości atrybutu lub elementu są formatowane zgodnie ze specyfikacją W3C. Aby uzyskać więcej informacji, zobacz specyfikację W3C.

Zachowanie jest opóźniony podczas rzutowania do elementu Nullable<T> z atrybutu TimeSpan lub elementu. Nawet jeśli wartość atrybutu lub elementu nie jest sformatowana dokładnie zgodnie ze specyfikacją W3C, wartość jest odpowiednio konwertowana na wartość Nullable<T> .TimeSpan

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<UInt32>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> UInt32.

public:
 static explicit operator Nullable<System::UInt32>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator uint? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator uint? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<uint32>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of UInteger)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .UInt32

Zwraca

Nullable<UInt32>

UInt32 Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej UInt32 wartości.

Przykłady

Poniższy przykład tworzy atrybut z niepodpisaną zawartością całkowitą. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu UInt32.

XElement root = new XElement("Root",   
    new XAttribute("Att", 4294967295)  
);  
uint? value = (uint?)root.Attribute("Att");  
Console.WriteLine("Nullable uint: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att="4294967295"/>  
Dim value As Nullable(Of UInteger) = CType(root.Attribute("Att"), Nullable(Of UInteger))  
Console.WriteLine("Nullable uint: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable uint: value=4294967295  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<UInt64>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> UInt64.

public:
 static explicit operator Nullable<System::UInt64>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator ulong? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator ulong? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<uint64>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of ULong)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .UInt64

Zwraca

Nullable<UInt64>

UInt64 Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej UInt64 wartości.

Przykłady

Poniższy przykład tworzy atrybut z niepodpisaną długą zawartością całkowitą. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu UInt64.

XElement root = new XElement("Root",   
    new XAttribute("Att", 9223372036854775807)  
);  
ulong? value = (ulong?)root.Attribute("Att");  
Console.WriteLine("Nullable ulong: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att="9223372036854775807"/>  
Dim value As Nullable(Of ULong) = CType(root.Attribute("Att"), Nullable(Of ULong))  
Console.WriteLine("Nullable ulong: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable ulong: value=9223372036854775807  

Zobacz też

Dotyczy

Explicit(XAttribute to TimeSpan)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość TimeSpan.

public:
 static explicit operator TimeSpan(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator TimeSpan (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> TimeSpan
Public Shared Narrowing Operator CType (attribute As XAttribute) As TimeSpan

Parametry

attribute
XAttribute

Rzutowanie XAttribute do TimeSpan.

Zwraca

TimeSpan

Obiekt TimeSpan , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej TimeSpan wartości.

Parametr attribute to null.

Przykłady

Poniższy przykład tworzy atrybut z zawartością przedziału czasu. Następnie pobiera wartość przez rzutowanie do TimeSpanelementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", new TimeSpan(1, 5, 30))  
);  
TimeSpan value = (TimeSpan)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att=<%= New TimeSpan(1, 5, 30) %>/>  
Dim value As TimeSpan = CType(root.Attribute("Att"), TimeSpan)  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=01:05:30  

Uwagi

Przestrzeń wartości atrybutu lub elementu zawierającego zawartość przedziału czasu jest ściśle powiązana z zawartością czasu trwania, zgodnie z opisem w iso 8601. Podczas tworzenia atrybutu lub elementu zawierającego zawartość przedziału czasu wartości atrybutu lub elementu są formatowane zgodnie ze specyfikacją W3C. Aby uzyskać więcej informacji, zobacz specyfikację W3C.

Zachowanie jest opóźniony podczas rzutowania do TimeSpan elementu z atrybutu lub elementu. Nawet jeśli atrybut lub wartość elementu nie jest sformatowana dokładnie zgodnie ze specyfikacją TimeSpanW3C, wartość jest odpowiednio konwertowana na wartość .

Zobacz też

Dotyczy

Explicit(XAttribute to String)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość String.

public:
 static explicit operator System::String ^(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator string (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator string? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> string
Public Shared Narrowing Operator CType (attribute As XAttribute) As String

Parametry

attribute
XAttribute

Rzutowanie XAttribute do String.

Zwraca

String

Obiekt String , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Przykłady

Poniższy przykład tworzy atrybut z zawartością ciągu. Następnie pobiera wartość przez rzutowanie do Stringelementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", "attribute content")  
);  
XAttribute att = root.Attribute("Att");  
string str = (string)att;  
Console.WriteLine("(string)att={0}", str);  
Dim root As XElement = <Root Att="attribute content"/>  
Dim att As XAttribute = root.Attribute("Att")  
Dim str As String = CStr(att)  
Console.WriteLine("(string)att={0}", str)  

Ten przykład generuje następujące wyniki:

(string)att=attribute content  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<Int32>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Int32.

public:
 static explicit operator Nullable<int>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator int? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator int? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<int>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of Integer)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .Int32

Zwraca

Nullable<Int32>

Int32 Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Przykłady

Poniższy przykład tworzy atrybut z zawartością całkowitą. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu Int32.

XElement root = new XElement("Root",   
    new XAttribute("Att", 2147483647)  
);  
int? value = (int?)root.Attribute("Att");  
Console.WriteLine("Nullable int: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att="2147483647"/>  
Dim value As Nullable(Of Integer) = CType(root.Attribute("Att"), Nullable(Of Integer))  
Console.WriteLine("Nullable int: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable int: value=2147483647  

Zobacz też

Dotyczy

Explicit(XAttribute to UInt32)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutowanie wartości tej XAttribute wartości na wartość UInt32.

public:
 static explicit operator System::UInt32(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator uint (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> uint32
Public Shared Narrowing Operator CType (attribute As XAttribute) As UInteger

Parametry

attribute
XAttribute

Rzutowanie XAttribute do UInt32.

Zwraca

UInt32

Element UInt32 zawierający zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej UInt32 wartości.

Parametr attribute to null.

Przykłady

Poniższy przykład tworzy atrybut z niepodpisaną zawartością całkowitą. Następnie pobiera wartość przez rzutowanie do UInt32elementu .

XElement root = new XElement("Root",   
    new XAttribute("Att", 4294967295)  
);  
uint value = (uint)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att="4294967295"/>  
Dim value As UInteger = CUInt(root.Attribute("Att"))  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=4294967295  

Zobacz też

Dotyczy

Explicit(XAttribute to UInt64)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutowanie wartości tej XAttribute wartości na wartość UInt64.

public:
 static explicit operator System::UInt64(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator ulong (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> uint64
Public Shared Narrowing Operator CType (attribute As XAttribute) As ULong

Parametry

attribute
XAttribute

Rzutowanie XAttribute do UInt64.

Zwraca

UInt64

Element UInt64 zawierający zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej UInt64 wartości.

Parametr attribute to null.

Przykłady

Poniższy przykład tworzy atrybut z niepodpisaną długą zawartością całkowitą. Następnie pobiera wartość przez rzutowanie do UInt64elementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", 1844674407370955161)  
);  
ulong value = (ulong)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att="1844674407370955161"/>  
Dim value As ULong = CULng(root.Attribute("Att"))  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=1844674407370955161  

Zobacz też

Dotyczy

Explicit(XAttribute to Single)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość Single.

public:
 static explicit operator float(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator float (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> single
Public Shared Narrowing Operator CType (attribute As XAttribute) As Single

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Single.

Zwraca

Single

Obiekt Single , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Single wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z pojedynczą precyzją zawartości zmiennoprzecinkowe. Następnie pobiera wartość przez rzutowanie do Singleelementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", 3.402823e38)  
);  
float value = (float)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att="3.402823E+38"/>  
Dim value As Single = CSng(root.Attribute("Att"))  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=3.402823E+38  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<Guid>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Guid.

public:
 static explicit operator Nullable<Guid>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator Guid? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator Guid? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<Guid>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of Guid)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .Guid

Zwraca

Nullable<Guid>

Guid Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Guid wartości.

Przykłady

Poniższy przykład tworzy atrybut z zawartością identyfikatora GUID. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu Guid.

XElement root = new XElement("Root",  
    new XAttribute("Att", new Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730"))  
);  
Guid? value = (Guid?)root.Attribute("Att");  
Console.WriteLine("Nullable Guid: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att=<%= New Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730") %>/>  
Dim value As Nullable(Of Guid) = CType(root.Attribute("Att"), Nullable(Of Guid))  
Console.WriteLine("Nullable Guid: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable Guid: value=3c1cc55b-baff-4b7a-9d17-077af3aa5730  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<Decimal>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Decimal.

public:
 static explicit operator Nullable<System::Decimal>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator decimal? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator decimal? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<decimal>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of Decimal)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Nullable<T> .Decimal

Zwraca

Nullable<Decimal>

Decimal Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Decimal wartości.

Przykłady

Poniższy przykład tworzy atrybut z zawartością dziesiętną. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu Decimal.

XElement root = new XElement("Root",  
    new XAttribute("Att", "79228162514264337593543950335")  
);  
decimal? value = (decimal?)root.Attribute("Att");  
Console.WriteLine("Nullable decimal: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att="79228162514264337593543950335"/>  
Dim value As Nullable(Of Decimal) = CType(root.Attribute("Att"), Nullable(Of Decimal))  
Console.WriteLine("Nullable decimal: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable decimal: value=79228162514264337593543950335  

Zobacz też

Dotyczy

Explicit(XAttribute to Decimal)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość Decimal.

public:
 static explicit operator System::Decimal(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator decimal (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> decimal
Public Shared Narrowing Operator CType (attribute As XAttribute) As Decimal

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Decimal.

Zwraca

Decimal

Obiekt Decimal , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Decimal wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z wartością dziesiętną. Następnie pobiera wartość atrybutu przez rzutowanie do Decimalelementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", "79228162514264337593543950335")  
);  
decimal value = (decimal)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att="79228162514264337593543950335"/>  
Dim value As Decimal = CDec(root.Attribute("Att"))  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=79228162514264337593543950335  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<DateTimeOffset>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> DateTimeOffset.

public:
 static explicit operator Nullable<DateTimeOffset>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<DateTimeOffset>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of DateTimeOffset)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .DateTimeOffset

Zwraca

Nullable<DateTimeOffset>

DateTimeOffset Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej DateTimeOffset wartości.

Przykłady

Poniższy przykład tworzy atrybut z datą i godziną jako zawartością. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu DateTimeOffset.

XElement root = new XElement("Root",  
    new XAttribute("Att", new DateTimeOffset(new DateTime(2006, 10, 6, 12, 30, 0)))  
);  
DateTimeOffset? value = (DateTimeOffset?)root.Attribute("Att");  
Console.WriteLine("Nullable DateTimeOffset: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = _  
    <Root  
        Att=<%= New DateTimeOffset(New DateTime(2006, 10, 6, 12, 30, 0)) %>/>  
Dim value As Nullable(Of DateTimeOffset) = CType(root.Attribute("Att"), Nullable(Of DateTimeOffset))  
Console.WriteLine("Nullable DateTimeOffset: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable DateTimeOffset: value=10/6/2006 12:30:00 PM -07:00  

Uwagi

Ten operator konwersji używa XmlConvert klasy do przeprowadzenia konwersji.

Dotyczy

Explicit(XAttribute to Nullable<DateTime>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> DateTime.

public:
 static explicit operator Nullable<DateTime>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator DateTime? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator DateTime? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<DateTime>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of DateTime)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do obiektu typu Nullable<T> .DateTime

Zwraca

Nullable<DateTime>

DateTime Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej DateTime wartości.

Przykłady

Poniższy przykład tworzy atrybut z datą i godziną jako zawartością. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu DateTime.

XElement root = new XElement("Root",  
    new XAttribute("Att", new DateTime(2006, 10, 6, 12, 30, 0))  
);  
DateTime? value = (DateTime?)root.Attribute("Att");  
Console.WriteLine("Nullable DateTime: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att=<%= New DateTime(2006, 10, 6, 12, 30, 0) %>/>  
Dim value As Nullable(Of DateTime) = CType(root.Attribute("Att"), Nullable(Of DateTime))  
Console.WriteLine("Nullable DateTime: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable DateTime: value=10/6/2006 12:30:00 PM  

Uwagi

Przestrzeń wartości atrybutu lub elementu zawierającego zawartość daty i godziny jest ściśle powiązana z datami i godzinami opisanymi w standardzie ISO 8601. Podczas tworzenia atrybutu lub elementu zawierającego zawartość daty i godziny wartości atrybutu lub elementu są formatowane zgodnie ze specyfikacją W3C. Aby uzyskać więcej informacji, zobacz specyfikację W3C.

Zachowanie jest opóźniony podczas rzutowania do elementu Nullable<T> z atrybutu DateTime lub elementu. Nawet jeśli wartość atrybutu lub elementu nie jest sformatowana dokładnie zgodnie ze specyfikacją W3C, wartość jest odpowiednio konwertowana na wartość Nullable<T> .DateTime

Ten operator konwersji używa CultureInfo.InvariantCulture metody do konwersji z obiektu DateTime.

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<Boolean>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Boolean.

public:
 static explicit operator Nullable<bool>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator bool? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator bool? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<bool>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of Boolean)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Nullable<T> .Boolean

Zwraca

Nullable<Boolean>

Boolean Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Boolean wartości.

Przykłady

Poniższy przykład tworzy atrybut z zawartością logiczną. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu Boolean.

XElement root = new XElement("Root",   
    new XAttribute("BoolValue1", true),  
    new XAttribute("BoolValue2", false)  
);  
bool? bool1 = (bool?)root.Attribute("BoolValue1");  
bool? bool2 = (bool?)root.Attribute("BoolValue2");  
Console.WriteLine("Nullable boolean: BoolValue1={0}", bool1);  
Console.WriteLine("Nullable boolean: BoolValue2={0}", bool2);  
Dim root As XElement = <Root BoolValue1="true" BoolValue2="false"/>  
Dim bool1 As Nullable(Of Boolean) = CType(root.Attribute("BoolValue1"), Nullable(Of Boolean))  
Dim bool2 As Nullable(Of Boolean) = CType(root.Attribute("BoolValue2"), Nullable(Of Boolean))  
Console.WriteLine("Nullable boolean: BoolValue1={0}", bool1)  
Console.WriteLine("Nullable boolean: BoolValue2={0}", bool2)  

Ten przykład generuje następujące wyniki:

Nullable boolean: BoolValue1=True  
Nullable boolean: BoolValue2=False  

Uwagi

Podczas konwersji na Boolean z atrybutu lub elementu dozwolone wartości to "0", "1" i dowolny ciąg, który generuje wartość "true" lub "false" po przycinaniu i konwersji na małe litery.

Zobacz też

Dotyczy

Explicit(XAttribute to Int64)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość Int64.

public:
 static explicit operator long(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator long (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> int64
Public Shared Narrowing Operator CType (attribute As XAttribute) As Long

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Int64.

Zwraca

Int64

Obiekt Int64 , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Int64 wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z długą liczbą całkowitą jako zawartością. Następnie pobiera wartość atrybutu przez rzutowanie do Int64elementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", 9223372036854775807)  
);  
long value = (long)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att="9223372036854775807"/>  
Dim value As Long = CLng(root.Attribute("Att"))  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=9223372036854775807  

Zobacz też

Dotyczy

Explicit(XAttribute to Int32)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość Int32.

public:
 static explicit operator int(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator int (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> int
Public Shared Narrowing Operator CType (attribute As XAttribute) As Integer

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Int32.

Zwraca

Int32

Obiekt Int32 , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Int32 wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z liczbą całkowitą jako zawartością. Następnie pobiera wartość przez rzutowanie do Int32elementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", 2147483647)  
);  
int value = (int)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att="2147483647"/>  
Dim value As Integer = CInt(root.Attribute("Att"))  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=2147483647  

Zobacz też

Dotyczy

Explicit(XAttribute to Guid)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość Guid.

public:
 static explicit operator Guid(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator Guid (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Guid
Public Shared Narrowing Operator CType (attribute As XAttribute) As Guid

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Guid.

Zwraca

Guid

Obiekt Guid , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Guid wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z identyfikatorem GUID jako zawartością. Następnie pobiera wartość przez rzutowanie do Guidelementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", new Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730"))  
);  
Guid value = (Guid)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att=<%= New Guid("3c1cc55b-baff-4b7a-9d17-077af3aa5730") %>/>  
Dim value As Guid = CType(root.Attribute("Att"), Guid)  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=3c1cc55b-baff-4b7a-9d17-077af3aa5730  

Zobacz też

Dotyczy

Explicit(XAttribute to Double)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość Double.

public:
 static explicit operator double(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator double (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> double
Public Shared Narrowing Operator CType (attribute As XAttribute) As Double

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Double.

Zwraca

Double

Obiekt Double , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Double wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z zawartością Double . Następnie pobiera wartość przez rzutowanie do Doubleelementu .

XElement root = new XElement("Root",  
    new XAttribute("Att", 1.79769313486231e308)  
);  
double value = (double)root.Attribute("Att");  
Console.WriteLine("value={0}", value);  
Dim root As XElement = <Root Att="1.79769313486231E+308"/>  
Dim value As Double = CDbl(root.Attribute("Att"))  
Console.WriteLine("value={0}", value)  

Ten przykład generuje następujące wyniki:

value=1.79769313486231E+308  

Zobacz też

Dotyczy

Explicit(XAttribute to Nullable<Double>)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość typu Nullable<T> Double.

public:
 static explicit operator Nullable<double>(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator double? (System.Xml.Linq.XAttribute attribute);
[System.CLSCompliant(false)]
public static explicit operator double? (System.Xml.Linq.XAttribute? attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> Nullable<double>
Public Shared Narrowing Operator CType (attribute As XAttribute) As Nullable(Of Double)

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Nullable<T> .Double

Zwraca

Nullable<Double>

Double Element Nullable<T> , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Double wartości.

Przykłady

Poniższy przykład tworzy atrybut z podwójną precyzją zawartości zmiennoprzecinkowe. Następnie pobiera wartość przez rzutowanie do Nullable<T> elementu Double.

XElement root = new XElement("Root",  
    new XAttribute("Att", 1.79769313486231e308)  
);  
double? value = (double?)root.Attribute("Att");  
Console.WriteLine("Nullable double: value={0}", value == null ? "null" : value.ToString());  
Dim root As XElement = <Root Att="1.79769313486231E+308"/>  
Dim value As Nullable(Of Double) = CType(root.Attribute("Att"), Nullable(Of Double))  
Console.WriteLine("Nullable double: value={0}", IIf(value.HasValue, value.ToString(), "null"))  

Ten przykład generuje następujące wyniki:

Nullable double: value=1.79769313486231E+308  

Zobacz też

Dotyczy

Explicit(XAttribute to DateTimeOffset)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość DateTimeOffset.

public:
 static explicit operator DateTimeOffset(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator DateTimeOffset (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> DateTimeOffset
Public Shared Narrowing Operator CType (attribute As XAttribute) As DateTimeOffset

Parametry

attribute
XAttribute

Rzutowanie XAttribute do DateTimeOffset.

Zwraca

DateTimeOffset

Obiekt DateTimeOffset , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej DateTimeOffset wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z zawartością daty i godziny. Następnie rzutuje ją, aby DateTimeOffset pobrać wartość.

XElement root = new XElement("Root",  
    new XAttribute("Att", new DateTimeOffset(new DateTime(2006, 10, 6, 12, 30, 0)))  
);  
Console.WriteLine(root);  

// casting from a strictly formatted XML attribute  
DateTimeOffset dt = (DateTimeOffset)root.Attribute("Att");  
Console.WriteLine("dt={0}", dt);  
Dim root As XElement = _  
    <Root  
        Att=<%= New DateTimeOffset(New DateTime(2006, 10, 6, 12, 30, 0)) %>/>  
Console.WriteLine(root)  

' casting from a strictly formatted XML attribute  
Dim dt As DateTimeOffset = CType(root.Attribute("Att"), DateTimeOffset)  
Console.WriteLine("dt={0}", dt)  

Ten przykład generuje następujące wyniki:

<Root Att="2006-10-06T12:30:00-07:00" />  
dt=10/6/2006 12:30:00 PM -07:00  

Uwagi

Ten operator konwersji używa XmlConvert klasy do przeprowadzenia konwersji.

Zobacz też

Dotyczy

Explicit(XAttribute to DateTime)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutuj wartość tej XAttribute wartości na wartość DateTime.

public:
 static explicit operator DateTime(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator DateTime (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> DateTime
Public Shared Narrowing Operator CType (attribute As XAttribute) As DateTime

Parametry

attribute
XAttribute

Rzutowanie XAttribute do DateTime.

Zwraca

DateTime

Obiekt DateTime , który zawiera zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej DateTime wartości.

Parametr attribute ma wartość null.

Przykłady

Poniższy przykład tworzy atrybut z zawartością daty i godziny. Następnie rzutuje ją, aby DateTime pobrać wartość.

// Behavior is strict when formatting an XML element or attribute from a DateTime,  
// but behavior is lax when casting to a DateTime from an element or attribute.  

XElement root = new XElement("Root",  
    new XAttribute("Att", new DateTime(2006, 10, 6, 12, 30, 0))  
);  
Console.WriteLine(root);  

// casting from a strictly formatted XML attribute  
DateTime dt = (DateTime)root.Attribute("Att");  
Console.WriteLine("dt={0}", dt);  
Console.WriteLine("-----");  

// if root is formatted in some different way than the standard ISO 8601, if at all possible,  
// the value is appropriately converted to DateTime  

XAttribute dtAtt = new XAttribute("OrderDate", "October 6, 2006");  
Console.WriteLine(dtAtt);  
DateTime orderDate = (DateTime)dtAtt;  
Console.WriteLine("OrderDate={0:d}", orderDate);  
' Behavior is strict when formatting an XML element or attribute from a DateTime,  
' but behavior is lax when casting to a DateTime from an element or attribute.  
Dim root As XElement = <Root Att=<%= New DateTime(2006, 10, 6, 12, 30, 0) %>/>  

Console.WriteLine(root)  

' casting from a strictly formatted XML attribute  
Dim dt As DateTime = CType(root.Attribute("Att"), DateTime)  
Console.WriteLine("dt={0}", dt)  
Console.WriteLine("-----")  

' if root is formatted in some different way than the standard ISO 8601, if at all possible,  
' the value is appropriately converted to DateTime  
Dim dtAtt As XAttribute = New XAttribute("OrderDate", "October 6, 2006")  
Console.WriteLine(dtAtt)  
Dim orderDate As DateTime = CType(dtAtt, DateTime)  
Console.WriteLine("OrderDate={0:d}", orderDate)  

Ten przykład generuje następujące wyniki:

<Root Att="2006-10-06T12:30:00" />  
dt=10/6/2006 12:30:00 PM  
-----  
OrderDate="October 6, 2006"  
OrderDate=10/6/2006  

Uwagi

Przestrzeń wartości atrybutu lub elementu zawierającego zawartość daty i godziny jest ściśle powiązana z datami i godzinami opisanymi w standardzie ISO 8601. Podczas tworzenia atrybutu lub elementu zawierającego zawartość daty i godziny wartości atrybutu lub elementu są formatowane zgodnie ze specyfikacją W3C. Aby uzyskać więcej informacji, zobacz specyfikację W3C.

Zachowanie jest opóźniony podczas rzutowania do DateTime elementu z atrybutu lub elementu. Nawet jeśli wartość atrybutu lub elementu nie jest sformatowana dokładnie zgodnie ze specyfikacją DateTimeW3C, wartość jest odpowiednio konwertowana na wartość .

Ten operator konwersji używa CultureInfo.InvariantCulture metody do konwersji z obiektu DateTime.

Zobacz też

Dotyczy

Explicit(XAttribute to Boolean)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Rzutowanie wartości tej XAttribute wartości na wartość Boolean.

public:
 static explicit operator bool(System::Xml::Linq::XAttribute ^ attribute);
[System.CLSCompliant(false)]
public static explicit operator bool (System.Xml.Linq.XAttribute attribute);
[<System.CLSCompliant(false)>]
static member op_Explicit : System.Xml.Linq.XAttribute -> bool
Public Shared Narrowing Operator CType (attribute As XAttribute) As Boolean

Parametry

attribute
XAttribute

Rzutowanie XAttribute do Boolean.

Zwraca

Boolean

Element Boolean zawierający zawartość tego XAttributeelementu .

Atrybuty

Wyjątki

Atrybut nie zawiera prawidłowej Boolean wartości.

Parametr attribute to null.

Przykłady

Poniższy przykład tworzy atrybut z wartością Boolean , a następnie rzutuje go na Boolean.

XElement root = new XElement("Root",   
    new XAttribute("BoolValue", true)  
);  
bool bv = (bool)root.Attribute("BoolValue");  
Console.WriteLine("(bool)BoolValue={0}", bv);  
Dim root As XElement = <root BoolValue="true"/>  
Dim bv As Boolean = CBool(root.Attribute("BoolValue"))  
Console.WriteLine("(bool)BoolValue={0}", bv)  

Ten przykład generuje następujące wyniki:

(bool)BoolValue=True  

Uwagi

Podczas konwertowania na Boolean z atrybutu lub elementu dozwolone wartości to "0", "1" i każdy ciąg, który generuje "true" lub "false" po przycinaniu i konwersji na małe litery.

Zobacz też

Dotyczy