Type.Namespace Свойство

Определение

Возвращает пространство имен объекта 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

Значение свойства

Пространство имен текущего экземпляра Typenull не имеет пространства имен или представляет универсальный параметр.

Реализации

Примеры

В следующем примере демонстрируется использование Namespace свойств и ModuleToString методов 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.

Комментарии

Пространство имен — это удобство именования во время логического проектирования, используемое главным образом для определения области в приложении и упорядочивания классов и других типов в одной иерархической структуре. В точке зрения среды выполнения нет пространств имен.

Если текущий Type представляет созданный универсальный тип, это свойство возвращает пространство имен, содержащее определение универсального типа. Аналогичным образом, если текущий Type представляет универсальный параметр T, это свойство возвращает пространство имен, содержащее определение универсального типа, определяющее T.

Если текущий Type объект представляет универсальный параметр, а определение универсального типа недоступно, например для типа подписи, возвращаемого этим свойствомMakeGenericMethodParameternull.

Применяется к

См. также раздел