Type.Namespace プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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
プロパティ値
Typeの名前空間。現在のインスタンスに名前空間がない場合、またはジェネリック パラメーターを表す場合にnull。
実装
例
次の例では、NamespaceプロパティとModuleプロパティ、およびToStringの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.
注釈
名前空間は、主にアプリケーションでスコープを定義し、クラスやその他の型を 1 つの階層構造で整理するために使用される、論理的なデザイン時の名前付けの利便性です。 ランタイムの観点からは、名前空間はありません。
現在の Type が構築されたジェネリック型を表す場合、このプロパティはジェネリック型定義を含む名前空間を返します。 同様に、現在の Type がジェネリック パラメーター Tを表す場合、このプロパティは、 Tを定義するジェネリック型定義を含む名前空間を返します。
現在の Type オブジェクトがジェネリック パラメーターを表し、 MakeGenericMethodParameterによって返されるシグネチャ型など、ジェネリック型定義を使用できない場合、このプロパティは nullを返します。