9 [__DynamicallyInvokable]
15 [__DynamicallyInvokable]
19 [__DynamicallyInvokable]
23 [__DynamicallyInvokable]
27 [__DynamicallyInvokable]
31 [__DynamicallyInvokable]
35 [__DynamicallyInvokable]
39 [__DynamicallyInvokable]
43 [__DynamicallyInvokable]
48 [__DynamicallyInvokable]
51 [__DynamicallyInvokable]
59 internal static Attribute GetCustomAttribute(RuntimeMethodInfo method)
65 MetadataImport metadataImport =
ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
66 string importDll =
null;
67 int metadataToken = method.MetadataToken;
68 PInvokeAttributes attributes = PInvokeAttributes.CharSetNotSpec;
69 metadataImport.GetPInvokeMap(metadataToken, out attributes, out
string importName, out importDll);
71 switch (attributes & PInvokeAttributes.CharSetMask)
73 case PInvokeAttributes.CharSetNotSpec:
76 case PInvokeAttributes.CharSetAnsi:
79 case PInvokeAttributes.CharSetUnicode:
82 case PInvokeAttributes.CharSetMask:
87 switch (attributes & PInvokeAttributes.CallConvMask)
89 case PInvokeAttributes.CallConvWinapi:
92 case PInvokeAttributes.CallConvCdecl:
95 case PInvokeAttributes.CallConvStdcall:
98 case PInvokeAttributes.CallConvThiscall:
101 case PInvokeAttributes.CallConvFastcall:
105 bool exactSpelling = (attributes & PInvokeAttributes.NoMangle) != PInvokeAttributes.CharSetNotSpec;
106 bool setLastError = (attributes & PInvokeAttributes.SupportsLastError) != PInvokeAttributes.CharSetNotSpec;
107 bool bestFitMapping = (attributes & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
108 bool throwOnUnmappableChar = (attributes & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
110 return new DllImportAttribute(importDll, importName, charSet, exactSpelling, setLastError, preserveSig, callingConvention, bestFitMapping, throwOnUnmappableChar);
113 internal static bool IsDefined(RuntimeMethodInfo method)
118 internal DllImportAttribute(
string dllName,
string entryPoint,
CharSet charSet,
bool exactSpelling,
bool setLastError,
bool preserveSig,
CallingConvention callingConvention,
bool bestFitMapping,
bool throwOnUnmappableChar)
133 [__DynamicallyInvokable]
MethodAttributes
Specifies flags for method attributes. These flags are defined in the corhdr.h file.
bool PreserveSig
Indicates whether unmanaged methods that have HRESULT or retval return values are directly translated...
bool BestFitMapping
Enables or disables best-fit mapping behavior when converting Unicode characters to ANSI characters.
bool ThrowOnUnmappableChar
Enables or disables the throwing of an exception on an unmappable Unicode character that is converted...
DllImportAttribute(string dllName)
Initializes a new instance of the T:System.Runtime.InteropServices.DllImportAttribute class with the ...
MethodImplAttributes
Specifies flags for the attributes of a method implementation.
CallingConvention CallingConvention
Indicates the calling convention of an entry point.
Represents the base class for custom attributes.
Represents a runtime handle for a module.
bool SetLastError
Indicates whether the callee calls the SetLastError Win32 API function before returning from the attr...
CallingConvention
Specifies the calling convention required to call methods implemented in unmanaged code.
Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a stati...
CharSet
Dictates which character set marshaled strings should use.
string Value
Gets the name of the DLL file that contains the entry point.
AttributeTargets
Specifies the application elements on which it is valid to apply an attribute.
bool ExactSpelling
Controls whether the F:System.Runtime.InteropServices.DllImportAttribute.CharSet field causes the com...
CharSet CharSet
Indicates how to marshal string parameters to the method and controls name mangling.
string EntryPoint
Indicates the name or ordinal of the DLL entry point to be called.