Type.Namespace Vlastnost

Definice

Získá obor názvů Type.

public:
 abstract property System::String ^ Namespace { System::String ^ get(); };
public abstract string Namespace { get; }
public abstract string? Namespace { get; }
member this.Namespace : string
Public MustOverride ReadOnly Property Namespace As String

Hodnota vlastnosti

Obor názvů ; Typenull pokud aktuální instance nemá žádný obor názvů nebo představuje obecný parametr.

Implementuje

Příklady

Následující příklad ukazuje použití Namespace a Module vlastnosti a ToString metoda Type.

using System;

namespace MyNamespace
{
    class MyClass
    {
    }
}

public class Example
{
    public static void Main()
    {
         Type myType = typeof(MyNamespace.MyClass);
         Console.WriteLine("Displaying information about {0}:", myType);
         // Get the namespace of the myClass class.
         Console.WriteLine("   Namespace: {0}.", myType.Namespace);
         // Get the name of the module.
         Console.WriteLine("   Module: {0}.", myType.Module);
         // Get the fully qualified type name.
         Console.WriteLine("   Fully qualified name: {0}.", myType.ToString());
    }
}
// The example displays the following output:
//    Displaying information about MyNamespace.MyClass:
//       Namespace: MyNamespace.
//       Module: type_tostring.exe.
//       Fully qualified name: MyNamespace.MyClass.
namespace MyNamespace
    
type MyClass() = class end

namespace global

module Example = 
    let myType = typeof<MyNamespace.MyClass>
    printfn $"Displaying information about {myType}:"
    // Get the namespace of the myClass class.
    printfn $"   Namespace: {myType.Namespace}."
    // Get the name of the ilmodule.
    printfn $"   Module: {myType.Module}."
    // Get the fully qualified type name.
    printfn $"   Fully qualified name: {myType.ToString()}."
// The example displays the following output:
//    Displaying information about MyNamespace.MyClass:
//       Namespace: MyNamespace.
//       Module: type_tostring.exe.
//       Fully qualified name: MyNamespace.MyClass.
Namespace MyNamespace
    Class [MyClass]
    End Class 
End Namespace 

Public Class Example
    Public Shared Sub Main()
         Dim myType As Type = GetType(MyNamespace.MyClass)
         Console.WriteLine(", myType)
         ' Get the namespace of the MyClass class.
         Console.WriteLine("   Namespace: {0}.", myType.Namespace)
         ' Get the name of the module.
         Console.WriteLine("   Module: {0}.", myType.Module)
         ' Get the fully qualified type name.
         Console.WriteLine("   Fully qualified name: {0}.", myType.ToString())
    End Sub
End Class
' The example displays the following output:
'       Displaying information about MyNamespace.MyClass:
'          Namespace: MyNamespace.
'          Module: type_tostring.exe.
'          Fully qualified name: MyNamespace.MyClass.

Poznámky

Obor názvů je logické usnadnění vytváření názvů v době návrhu, které se používá hlavně k definování oboru v aplikaci a uspořádání tříd a dalších typů v jedné hierarchické struktuře. Z pohledu modulu runtime neexistují žádné obory názvů.

Pokud aktuální Type představuje vytvořený obecný typ, tato vlastnost vrátí obor názvů, který obsahuje definici obecného typu. Podobně pokud aktuální Type představuje obecný parametr T, tato vlastnost vrátí obor názvů, který obsahuje definici obecného typu, která definuje T.

Pokud aktuální Type objekt představuje obecný parametr a definice obecného typu není k dispozici, například pro typ podpisu vrácený MakeGenericMethodParameter, tato vlastnost vrátí null.

Platí pro

Viz také