XName.Implicit(String to XName) Operator

Definition

Viktigt!

Detta API uppfyller inte CLS.

Konverterar en sträng formaterad som ett expanderat XML-namn (dvs{namespace}localname. till ett XName objekt).

public:
 static operator System::Xml::Linq::XName ^(System::String ^ expandedName);
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName(string expandedName);
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName?(string? expandedName);
[<System.CLSCompliant(false)>]
static member op_Implicit : string -> System.Xml.Linq.XName
Public Shared Widening Operator CType (expandedName As String) As XName

Parametrar

expandedName
String

En sträng som innehåller ett expanderat XML-namn i formatet {namespace}localname.

Returer

Ett XName objekt som har konstruerats från det expanderade namnet.

Attribut

Exempel

I följande exempel skapas en XName genom att tilldela en sträng till den, som anropar den här implicita konverteringsoperatorn.

XElement el = new XElement("{http://www.adventure-works.com}Root", "content");
Console.WriteLine(el);

// The preferred approach is to initialize an XNamespace object
// and use the overload of the addition operator.
XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root", "content");
Console.WriteLine(root);
Imports <xmlns="http://www.adventure-works.com">

Module Module1
    Sub Main()
        Dim el As XElement = New XElement("{http://www.adventure-works.com}Root", "content")
        Console.WriteLine(el)

        ' The preferred approach is to import a global namespace and
        ' use an XML literal.
        Dim root As XElement = <Root>content</Root>
        Console.WriteLine(root)
    End Sub
End Module

Det här exemplet genererar följande utdata:

<Root xmlns="http://www.adventure-works.com">content</Root>
<Root xmlns="http://www.adventure-works.com">content</Root>

Kommentarer

Du använder den här implicita operatorn när du skapar en XElement eller XAttribute genom att skicka en sträng till lämplig konstruktor.

Gäller för

Se även