XAttribute.Explicit Operador
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Sobrecargas
Explicit(XAttribute to Nullable<Int64>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de Int64.
Devoluciones
Nullable<T> de Int64 que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Int64 .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido entero largo. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable long: value=9223372036854775807
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<Single>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a Nullable<T> de Single.
Devoluciones
Nullable<T> de Single que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Single .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de punto flotante de precisión única. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable Single: value=3.402823E+38
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<TimeSpan>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de TimeSpan.
Devoluciones
Nullable<T> de TimeSpan que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido TimeSpan .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de intervalo de tiempo. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable TimeSpan: value=01:05:30
Comentarios
El espacio de valor de un atributo o elemento que contiene contenido de intervalo de tiempo está estrechamente relacionado con el contenido de duración, tal como se describe en ISO 8601. Al crear un atributo o elemento que contiene contenido de intervalo de tiempo, los valores de atributo o elemento tienen el formato según la especificación W3C. Consulte la especificación W3C para obtener más detalles.
El comportamiento es lax al convertir a un Nullable<T> de TimeSpan desde un atributo o elemento. Incluso si el atributo o valor de elemento no tiene el formato exacto según la especificación W3C, el valor se convierte adecuadamente en un Nullable<T> de TimeSpan.
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<UInt32>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de UInt32.
Devoluciones
Nullable<T> de UInt32 que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido UInt32 .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido entero sin signo. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable uint: value=4294967295
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<UInt64>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de UInt64.
Devoluciones
Nullable<T> de UInt64 que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido UInt64 .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido entero largo sin signo. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable ulong: value=9223372036854775807
Consulte también
Se aplica a
Explicit(XAttribute to TimeSpan)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en TimeSpan.
Devoluciones
que TimeSpan contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido TimeSpan .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de intervalo de tiempo. A continuación, recupera el valor mediante la conversión a TimeSpan.
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)
Este ejemplo produce el siguiente resultado:
value=01:05:30
Comentarios
El espacio de valor de un atributo o elemento que contiene contenido de intervalo de tiempo está estrechamente relacionado con el contenido de duración, tal como se describe en ISO 8601. Al crear un atributo o elemento que contiene contenido de intervalo de tiempo, los valores de atributo o elemento tienen el formato según la especificación W3C. Consulte la especificación W3C para obtener más detalles.
El comportamiento es lax al convertir a desde un TimeSpan atributo o elemento. Incluso si el atributo o valor de elemento no tiene el formato exacto según la especificación W3C, el valor se convierte adecuadamente en un TimeSpan.
Consulte también
Se aplica a
Explicit(XAttribute to String)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en String.
Devoluciones
que String contiene el contenido de este XAttributeobjeto .
- Atributos
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de cadena. A continuación, recupera el valor mediante la conversión a String.
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)
Este ejemplo produce el siguiente resultado:
(string)att=attribute content
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<Int32>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de Int32.
Devoluciones
Nullable<T> de Int32 que contiene el contenido de este XAttributeobjeto .
- Atributos
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido entero. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable int: value=2147483647
Consulte también
Se aplica a
Explicit(XAttribute to UInt32)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en UInt32.
Devoluciones
que UInt32 contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido UInt32 .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido entero sin signo. A continuación, recupera el valor mediante la conversión a UInt32.
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)
Este ejemplo produce el siguiente resultado:
value=4294967295
Consulte también
Se aplica a
Explicit(XAttribute to UInt64)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en UInt64.
Devoluciones
que UInt64 contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido UInt64 .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido entero largo sin signo. A continuación, recupera el valor mediante la conversión a UInt64.
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)
Este ejemplo produce el siguiente resultado:
value=1844674407370955161
Consulte también
Se aplica a
Explicit(XAttribute to Single)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en Single.
Devoluciones
que Single contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Single .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de punto flotante de precisión única. A continuación, recupera el valor mediante la conversión a Single.
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)
Este ejemplo produce el siguiente resultado:
value=3.402823E+38
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<Guid>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de Guid.
Devoluciones
Nullable<T> de Guid que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Guid .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido guid. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable Guid: value=3c1cc55b-baff-4b7a-9d17-077af3aa5730
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<Decimal>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a Nullable<T> de Decimal.
Devoluciones
Nullable<T> de Decimal que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Decimal .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido decimal. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable decimal: value=79228162514264337593543950335
Consulte también
Se aplica a
Explicit(XAttribute to Decimal)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en Decimal.
Devoluciones
que Decimal contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Decimal .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con un valor decimal. A continuación, recupera el valor del atributo mediante la conversión a Decimal.
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)
Este ejemplo produce el siguiente resultado:
value=79228162514264337593543950335
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<DateTimeOffset>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de DateTimeOffset.
Devoluciones
Nullable<T> de DateTimeOffset que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido DateTimeOffset .
Ejemplos
En el ejemplo siguiente se crea un atributo con una fecha y hora como contenido. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable DateTimeOffset: value=10/6/2006 12:30:00 PM -07:00
Comentarios
Este operador de conversión usa la XmlConvert clase para realizar la conversión.
Se aplica a
Explicit(XAttribute to Nullable<DateTime>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a un Nullable<T> de DateTime.
Devoluciones
Nullable<T> de DateTime que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido DateTime .
Ejemplos
En el ejemplo siguiente se crea un atributo con una fecha y hora como contenido. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable DateTime: value=10/6/2006 12:30:00 PM
Comentarios
El espacio de valor de un atributo o elemento que contiene contenido de fecha y hora está estrechamente relacionado con las fechas y horas descritas en ISO 8601. Al crear un atributo o elemento que contiene contenido de fecha y hora, los valores de atributo o elemento tienen formato según la especificación W3C. Consulte la especificación W3C para obtener más detalles.
El comportamiento es lax al convertir a un Nullable<T> de DateTime desde un atributo o elemento. Incluso si el atributo o valor de elemento no tiene el formato exacto según la especificación W3C, el valor se convierte adecuadamente en un Nullable<T> de DateTime.
Este operador de conversión usa CultureInfo.InvariantCulture para convertir de un DateTime.
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<Boolean>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a Nullable<T> de Boolean.
Devoluciones
Nullable<T> de Boolean que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Boolean .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido booleano. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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)
Este ejemplo produce el siguiente resultado:
Nullable boolean: BoolValue1=True
Nullable boolean: BoolValue2=False
Comentarios
Al convertir a Boolean desde un atributo o elemento, los valores permitidos son "0", "1" y cualquier cadena que genere "true" o "false" después de recortar y convertir en minúsculas.
Consulte también
Se aplica a
Explicit(XAttribute to Int64)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de este XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en Int64.
Devoluciones
que Int64 contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Int64 .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con un entero largo como contenido. A continuación, recupera el valor del atributo mediante la conversión a Int64.
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)
Este ejemplo produce el siguiente resultado:
value=9223372036854775807
Consulte también
Se aplica a
Explicit(XAttribute to Int32)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de este XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en Int32.
Devoluciones
que Int32 contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Int32 .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con un entero como contenido. A continuación, recupera el valor mediante la conversión a Int32.
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)
Este ejemplo produce el siguiente resultado:
value=2147483647
Consulte también
Se aplica a
Explicit(XAttribute to Guid)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en Guid.
Devoluciones
que Guid contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Guid .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con un GUID como contenido. A continuación, recupera el valor mediante la conversión a Guid.
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)
Este ejemplo produce el siguiente resultado:
value=3c1cc55b-baff-4b7a-9d17-077af3aa5730
Consulte también
Se aplica a
Explicit(XAttribute to Double)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en Double.
Devoluciones
que Double contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Double .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con Double contenido. A continuación, recupera el valor mediante la conversión a Double.
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)
Este ejemplo produce el siguiente resultado:
value=1.79769313486231E+308
Consulte también
Se aplica a
Explicit(XAttribute to Nullable<Double>)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un Nullable<T> de 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)
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir a Nullable<T> de Double.
Devoluciones
Nullable<T> de Double que contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Double .
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de punto flotante de precisión doble. A continuación, recupera el valor mediante la conversión a Nullable<T> de 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"))
Este ejemplo produce el siguiente resultado:
Nullable double: value=1.79769313486231E+308
Consulte también
Se aplica a
Explicit(XAttribute to DateTimeOffset)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en DateTimeOffset.
Devoluciones
que DateTimeOffset contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido DateTimeOffset .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de fecha y hora. A continuación, lo convierte en DateTimeOffset para recuperar el valor.
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)
Este ejemplo produce el siguiente resultado:
<Root Att="2006-10-06T12:30:00-07:00" />
dt=10/6/2006 12:30:00 PM -07:00
Comentarios
Este operador de conversión usa la XmlConvert clase para realizar la conversión.
Consulte también
Se aplica a
Explicit(XAttribute to DateTime)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en DateTime.
Devoluciones
que DateTime contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido DateTime .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con contenido de fecha y hora. A continuación, lo convierte en DateTime para recuperar el valor.
// 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)
Este ejemplo produce el siguiente resultado:
<Root Att="2006-10-06T12:30:00" />
dt=10/6/2006 12:30:00 PM
-----
OrderDate="October 6, 2006"
OrderDate=10/6/2006
Comentarios
El espacio de valor de un atributo o elemento que contiene contenido de fecha y hora está estrechamente relacionado con las fechas y horas descritas en ISO 8601. Al crear un atributo o elemento que contiene contenido de fecha y hora, los valores de atributo o elemento tienen formato según la especificación W3C. Consulte la especificación W3C para obtener más detalles.
El comportamiento es lax al convertir a desde un DateTime atributo o elemento. Incluso si el atributo o valor de elemento no tiene el formato exacto según la especificación W3C, el valor se convierte adecuadamente en un DateTime.
Este operador de conversión usa CultureInfo.InvariantCulture para convertir de un DateTime.
Consulte también
Se aplica a
Explicit(XAttribute to Boolean)
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
- Source:
- XAttribute.cs
Importante
Esta API no es conforme a CLS.
Convierta el valor de esto XAttribute en un 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
Parámetros
- attribute
- XAttribute
que XAttribute se va a convertir en Boolean.
Devoluciones
que Boolean contiene el contenido de este XAttributeobjeto .
- Atributos
Excepciones
El atributo no contiene un valor válido Boolean .
El attribute parámetro es null.
Ejemplos
En el ejemplo siguiente se crea un atributo con un Boolean valor y, a continuación, se convierte en 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)
Este ejemplo produce el siguiente resultado:
(bool)BoolValue=True
Comentarios
Al convertir a Boolean desde un atributo o elemento, los valores permitidos son "0", "1" y cualquier cadena que genere "true" o "false" después de recortar y convertir en minúsculas.