MethodImplAttribute クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
メソッドの実装方法の詳細を指定します。 このクラスは継承できません。
public ref class MethodImplAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)]
public sealed class MethodImplAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)]
[System.Serializable]
public sealed class MethodImplAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class MethodImplAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)>]
type MethodImplAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)>]
[<System.Serializable>]
type MethodImplAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Constructor | System.AttributeTargets.Method, Inherited=false)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MethodImplAttribute = class
inherit Attribute
Public NotInheritable Class MethodImplAttribute
Inherits Attribute
- 継承
- 属性
次の例では、 MethodImplAttribute メソッドに を GetCalendarName
適用して、Just-In-Time (JIT) コンパイラによって実行時にインライン化されないようにします。
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
public class Utility
{
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static string GetCalendarName(Calendar cal)
{
return cal.ToString().Replace("System.Globalization.", "").
Replace("Calendar", "");
}
}
Imports System.Globalization
Imports System.Runtime.CompilerServices
Public Class Utility
<MethodImplAttribute(MethodImplOptions.NoInlining)>
Public Shared Function GetCalendarName(cal As Calendar) As String
Return cal.ToString().Replace("System.Globalization.", "").Replace("Calendar", "")
End Function
End Class
次の例では、 メソッドを MethodInfo.GetMethodImplementationFlags
呼び出して、 メソッドに設定されているフラグを GetCalendarName
決定します。 また、この情報が メソッドによって MemberInfo.GetCustomAttributes 取得されないことも示します。
using System;
using System.Reflection;
public class Example
{
public static void Main()
{
// Use reflection to get a reference to the GetCalendarName method.
Assembly assem = Assembly.LoadFrom(@".\Example.dll");
Type type = assem.GetType("Utility");
MethodInfo methodInfo = type.GetMethod("GetCalendarName");
// Determine whether the method has any custom attributes.
Console.Write("Utility.GetCalendarName custom attributes:");
object[] attribs = methodInfo.GetCustomAttributes(false);
if (attribs.Length > 0) {
Console.WriteLine();
foreach (var attrib in attribs)
Console.WriteLine(" " + attrib.ToString());
}
else {
Console.WriteLine(" <None>");
}
// Get the method's metadata flags.
MethodImplAttributes flags = methodInfo.GetMethodImplementationFlags();
Console.WriteLine("Utility.GetCalendarName flags: {0}",
flags.ToString());
}
}
// The example displays the following output:
// Utility.GetCalendarName custom attributes: <None>
// Utility.GetCalendarName flags: NoInlining
Imports System.Reflection
Module Example
Public Sub Main()
' Use reflection to get a reference to the GetCalendarName method.
Dim assem As Assembly = Assembly.LoadFrom(".\Example.dll")
Dim type As Type = assem.GetType("Utility")
Dim methodInfo As MethodInfo = type.GetMethod("GetCalendarName")
' Determine whether the method has any custom attributes.
Console.Write("Utility.GetCalendarName custom attributes:")
Dim attribs() As Object = methodInfo.GetCustomAttributes(False)
If attribs.Length > 0 Then
Console.WriteLine()
For Each attrib As Object In attribs
Console.WriteLine(" " + attrib.ToString())
Next
Else
Console.WriteLine(" <None>")
End If
' Get the method's metadata flags.
Dim flags As MethodImplAttributes = methodInfo.GetMethodImplementationFlags()
Console.WriteLine("Utility.GetCalendarName flags: {0}", flags.ToString())
End Sub
End Module
' The example displays the following output:
' Utility.GetCalendarName custom attributes: <None>
' Utility.GetCalendarName flags: NoInlining
この属性は、メソッドまたはコンストラクターに適用できます。
この属性を使用すると、クラス コンストラクターに値を指定 MethodImplOptions することで、適用先のメソッドまたはコンストラクターの構成をカスタマイズできます。 列挙体のメンバーは、 MethodImplOptions メタデータ テーブルのビット フィールドに CorMethodImpl
対応します。 つまり、 属性に関する情報は、 メソッドを呼び出MemberInfo.GetCustomAttributesすことで実行時に取得することはできません。代わりに、 または ConstructorInfo.GetMethodImplementationFlags
メソッドをMethodInfo.GetMethodImplementationFlags
呼び出すことによって取得されます。
Method |
MethodImplAttribute クラスの新しいインスタンスを初期化します。 |
Method |
指定した MethodImplOptions 値を使用して、MethodImplAttribute クラスの新しいインスタンスを初期化します。 |
Method |
指定した MethodImplOptions 値を使用して、MethodImplAttribute クラスの新しいインスタンスを初期化します。 |
Method |
メソッドに対して用意されている実装の種類を示す MethodCodeType 値。 |
Type |
派生クラスで実装されると、この Attribute の一意の識別子を取得します。 (継承元 Attribute) |
Value |
属性付きメソッドを記述する MethodImplOptions 値を取得します。 |
Equals(Object) |
このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。 (継承元 Attribute) |
Get |
このインスタンスのハッシュ コードを返します。 (継承元 Attribute) |
Get |
現在のインスタンスの Type を取得します。 (継承元 Object) |
Is |
派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。 (継承元 Attribute) |
Match(Object) |
派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (継承元 Attribute) |
Memberwise |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
To |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
_Attribute. |
一連の名前を対応する一連のディスパッチ識別子に割り当てます。 (継承元 Attribute) |
_Attribute. |
オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。 (継承元 Attribute) |
_Attribute. |
オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。 (継承元 Attribute) |
_Attribute. |
オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。 (継承元 Attribute) |
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。