MethodImplAttribute Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Megadja a metódus implementálásának részleteit. Ez az osztály nem örökölhető.
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
- Öröklődés
- Attribútumok
Példák
Az alábbi példa arra a MethodImplAttribute metódusra GetCalendarName vonatkozik, amely biztosítja, hogy a just-in-time (JIT) fordító futásidőben ne legyen beágyazott.
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
Az alábbi példa ezután meghívja a metódust annak MethodInfo.GetMethodImplementationFlags meghatározására, hogy mely jelölők legyenek beállítva a GetCalendarName metódushoz. Azt is bemutatja, hogy ezt az információt nem a MemberInfo.GetCustomAttributes metódus kéri le.
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
Megjegyzések
Ezt az attribútumot alkalmazhatja metódusokra vagy konstruktorokra.
Ezzel az attribútummal testre szabhatja annak a metódusnak vagy konstruktornak a konfigurációját, amelyre vonatkozik, ha megad egy MethodImplOptions értéket az osztálykonstruktornak. Az enumerálás tagjai a MethodImplOptions metaadattábla bitmezőinek CorMethodImpl felelnek meg. Ez azt jelenti, hogy az attribútum információi futásidőben nem kérhetők le a MemberInfo.GetCustomAttributes metódus meghívásával; ehelyett a rendszer vagy a MethodInfo.GetMethodImplementationFlagsConstructorInfo.GetMethodImplementationFlags metódus meghívásával kéri le.
Konstruktorok
| Name | Description |
|---|---|
| MethodImplAttribute() |
Inicializálja a MethodImplAttribute osztály új példányát. |
| MethodImplAttribute(Int16) |
Inicializálja az osztály új példányát MethodImplAttribute a megadott MethodImplOptions értékkel. |
| MethodImplAttribute(MethodImplOptions) |
Inicializálja az osztály új példányát MethodImplAttribute a megadott MethodImplOptions értékkel. |
Mezők
| Name | Description |
|---|---|
| MethodCodeType |
Egy MethodCodeType érték, amely azt jelzi, hogy milyen implementáció van megadva ehhez a módszerhez. |
Tulajdonságok
| Name | Description |
|---|---|
| TypeId |
Ha származtatott osztályban implementálják, ehhez egy egyedi azonosítót Attributekap. (Öröklődés forrása Attribute) |
| Value |
Lekéri az MethodImplOptions attribútumként megadott metódust leíró értéket. |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Olyan értéket ad vissza, amely jelzi, hogy ez a példány egyenlő-e egy adott objektummal. (Öröklődés forrása Attribute) |
| GetHashCode() |
A példány kivonatkódját adja vissza. (Öröklődés forrása Attribute) |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| IsDefaultAttribute() |
Ha egy származtatott osztályban felül van bírálva, azt jelzi, hogy a példány értéke-e a származtatott osztály alapértelmezett értéke. (Öröklődés forrása Attribute) |
| Match(Object) |
Származtatott osztály felülírásakor egy olyan értéket ad vissza, amely jelzi, hogy ez a példány egy adott objektummal egyenlő-e. (Öröklődés forrása Attribute) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |
Explicit interfész-implementációk
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Névkészletet képez le a küldési azonosítók megfelelő készletére. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Lekéri egy objektum típusadatait, amelyek a felület típusadatainak lekérésére használhatók. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Lekéri az objektumok által biztosított típusinformációs felületek számát (0 vagy 1). (Öröklődés forrása Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Hozzáférést biztosít az objektumok által közzétett tulajdonságokhoz és metódusokhoz. (Öröklődés forrása Attribute) |