239 references to MethodImportAttributes
Microsoft.CodeAnalysis (40)
MetadataReader\PEModule.cs (2)
3407MethodImportAttributes flags = (MethodImportAttributes)methodImport.Attributes;
PEWriter\Miscellaneous.cs (1)
236MethodImportAttributes Flags { get; }
Symbols\Attributes\CommonMethodWellKnownAttributeData.cs (1)
65public void SetDllImport(int attributeIndex, string? moduleName, string? entryPointName, MethodImportAttributes flags, bool preserveSig)
Symbols\PlatformInvokeInformation.cs (36)
18private readonly MethodImportAttributes _flags; 20internal DllImportData(string? moduleName, string? entryPointName, MethodImportAttributes flags) 43MethodImportAttributes Cci.IPlatformInvokeInformation.Flags 56return (_flags & MethodImportAttributes.ExactSpelling) != 0; 67switch (_flags & MethodImportAttributes.CharSetMask) 69case MethodImportAttributes.CharSetAnsi: 72case MethodImportAttributes.CharSetUnicode: 75case MethodImportAttributes.CharSetAuto: 93return (_flags & MethodImportAttributes.SetLastError) != 0; 104switch (_flags & MethodImportAttributes.CallingConventionMask) 109case MethodImportAttributes.CallingConventionCDecl: 112case MethodImportAttributes.CallingConventionStdCall: 115case MethodImportAttributes.CallingConventionThisCall: 118case MethodImportAttributes.CallingConventionFastCall: 132switch (_flags & MethodImportAttributes.BestFitMappingMask) 134case MethodImportAttributes.BestFitMappingEnable: 137case MethodImportAttributes.BestFitMappingDisable: 154switch (_flags & MethodImportAttributes.ThrowOnUnmappableCharMask) 156case MethodImportAttributes.ThrowOnUnmappableCharEnable: 159case MethodImportAttributes.ThrowOnUnmappableCharDisable: 168internal static MethodImportAttributes MakeFlags(bool exactSpelling, CharSet charSet, bool setLastError, CallingConvention callingConvention, bool? useBestFit, bool? throwOnUnmappable) 170MethodImportAttributes result = 0; 173result |= MethodImportAttributes.ExactSpelling; 179result |= MethodImportAttributes.CharSetAnsi; 183result |= MethodImportAttributes.CharSetUnicode; 187result |= MethodImportAttributes.CharSetAuto; 195result |= MethodImportAttributes.SetLastError; 201result |= MethodImportAttributes.CallingConventionWinApi; 205result |= MethodImportAttributes.CallingConventionCDecl; 209result |= MethodImportAttributes.CallingConventionStdCall; 213result |= MethodImportAttributes.CallingConventionThisCall; 217result |= MethodImportAttributes.CallingConventionFastCall; 225result |= MethodImportAttributes.ThrowOnUnmappableCharEnable; 229result |= MethodImportAttributes.ThrowOnUnmappableCharDisable; 237result |= MethodImportAttributes.BestFitMappingEnable; 241result |= MethodImportAttributes.BestFitMappingDisable;
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (65)
Attributes\AttributeTests_WellKnownAttributes.cs (65)
2709MethodImportAttributes.ExactSpelling | 2710MethodImportAttributes.CharSetUnicode | 2711MethodImportAttributes.SetLastError | 2712MethodImportAttributes.CallingConventionCDecl | 2713MethodImportAttributes.BestFitMappingEnable | 2714MethodImportAttributes.ThrowOnUnmappableCharEnable, import.Attributes); 2736MethodImportAttributes.ExactSpelling | 2737MethodImportAttributes.CharSetUnicode | 2738MethodImportAttributes.SetLastError | 2739MethodImportAttributes.CallingConventionCDecl | 2740MethodImportAttributes.BestFitMappingEnable | 2741MethodImportAttributes.ThrowOnUnmappableCharEnable, ((Cci.IPlatformInvokeInformation)info).Flags); 2857new { attr = MakeDllImport(), expected = MethodImportAttributes.CallingConventionWinApi}, // M0 2858new { attr = MakeDllImport(cc: CallingConvention.Cdecl), expected = MethodImportAttributes.CallingConventionCDecl }, // M1 2859new { attr = MakeDllImport(cc: CallingConvention.FastCall), expected = MethodImportAttributes.CallingConventionFastCall }, // M2 2860new { attr = MakeDllImport(cc: CallingConvention.StdCall), expected = MethodImportAttributes.CallingConventionStdCall }, // M3 2861new { attr = MakeDllImport(cc: CallingConvention.ThisCall), expected = MethodImportAttributes.CallingConventionThisCall }, // M4 2862new { attr = MakeDllImport(cc: CallingConvention.Winapi), expected = MethodImportAttributes.CallingConventionWinApi }, // M5 2865new { attr = MakeDllImport(), expected = MethodImportAttributes.CallingConventionWinApi }, // M6 2866new { attr = MakeDllImport(charSet: CharSet.None), expected = MethodImportAttributes.CallingConventionWinApi }, // M7 2867new { attr = MakeDllImport(charSet: CharSet.Ansi), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.CharSetAnsi }, // M8 2868new { attr = MakeDllImport(charSet: CharSet.Unicode), expected =MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.CharSetUnicode }, // M9 2869new { attr = MakeDllImport(charSet: CharSet.Auto), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.CharSetAuto }, // M10 2871new { attr = MakeDllImport(exactSpelling: true), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.ExactSpelling }, // M11 2872new { attr = MakeDllImport(exactSpelling: false), expected = MethodImportAttributes.CallingConventionWinApi }, // M12 2874new { attr = MakeDllImport(charSet: CharSet.Ansi, exactSpelling: true), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.ExactSpelling | MethodImportAttributes.CharSetAnsi }, // M13 2875new { attr = MakeDllImport(charSet: CharSet.Ansi, exactSpelling: false), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.CharSetAnsi }, // M14 2876new { attr = MakeDllImport(charSet: CharSet.Unicode, exactSpelling: true), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.ExactSpelling | MethodImportAttributes.CharSetUnicode },// M15 2877new { attr = MakeDllImport(charSet: CharSet.Unicode, exactSpelling: false), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.CharSetUnicode }, // M16 2878new { attr = MakeDllImport(charSet: CharSet.Auto, exactSpelling: true), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.ExactSpelling | MethodImportAttributes.CharSetAuto }, // M17 2879new { attr = MakeDllImport(charSet: CharSet.Auto, exactSpelling: false), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.CharSetAuto }, // M18 2882new { attr = MakeDllImport(preserveSig: true), expected = MethodImportAttributes.CallingConventionWinApi}, // M19 2883new { attr = MakeDllImport(preserveSig: false), expected = MethodImportAttributes.CallingConventionWinApi}, // M20 2886new { attr = MakeDllImport(setLastError: true), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.SetLastError}, // M21 2887new { attr = MakeDllImport(setLastError: false), expected = MethodImportAttributes.CallingConventionWinApi}, // M22 2890new { attr = MakeDllImport(bestFitMapping: true), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.BestFitMappingEnable}, // M23 2891new { attr = MakeDllImport(bestFitMapping: false), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.BestFitMappingDisable}, // M24 2894new { attr = MakeDllImport(throwOnUnmappableChar: true), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.ThrowOnUnmappableCharEnable}, // M23 2895new { attr = MakeDllImport(throwOnUnmappableChar: false), expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.ThrowOnUnmappableCharDisable}, // M24 2899expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.SetLastError }, // M25 2903expected = MethodImportAttributes.CallingConventionWinApi | MethodImportAttributes.SetLastError }, // M26 3436Assert.Equal(MethodImportAttributes.CharSetAnsi, import.Attributes & MethodImportAttributes.CharSetMask); 3468Assert.Equal(MethodImportAttributes.None, import.Attributes & MethodImportAttributes.CharSetMask);
Microsoft.CodeAnalysis.VisualBasic (9)
Symbols\Source\SourceMethodSymbol.vb (9)
285Private Shared Function GetPInvokeAttributes(syntax As DeclareStatementSyntax) As MethodImportAttributes 286Dim result As MethodImportAttributes 289result = MethodImportAttributes.CharSetAnsi Or MethodImportAttributes.ExactSpelling 292result = MethodImportAttributes.CharSetUnicode Or MethodImportAttributes.ExactSpelling 295result = MethodImportAttributes.CharSetAuto 298Return result Or MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.SetLastError
Microsoft.CodeAnalysis.VisualBasic.Emit.UnitTests (78)
Attributes\AttributeTests_WellKnownAttributes.vb (78)
1514Assert.Equal(MethodImportAttributes.ExactSpelling Or 1515MethodImportAttributes.CharSetUnicode Or 1516MethodImportAttributes.SetLastError Or 1517MethodImportAttributes.CallingConventionCDecl Or 1518MethodImportAttributes.BestFitMappingEnable Or 1519MethodImportAttributes.ThrowOnUnmappableCharEnable, import.Attributes) 1542MethodImportAttributes.ExactSpelling Or 1543MethodImportAttributes.CharSetUnicode Or 1544MethodImportAttributes.SetLastError Or 1545MethodImportAttributes.CallingConventionCDecl Or 1546MethodImportAttributes.BestFitMappingEnable Or 1547MethodImportAttributes.ThrowOnUnmappableCharEnable, DirectCast(info, Cci.IPlatformInvokeInformation).Flags) 1878New With {.n = 0, .attr = MakeDllImport(), .expected = MethodImportAttributes.CallingConventionWinApi}, 1879New With {.n = 1, .attr = MakeDllImport(cc:=CallingConvention.Cdecl), .expected = MethodImportAttributes.CallingConventionCDecl}, 1880New With {.n = 2, .attr = MakeDllImport(cc:=CallingConvention.FastCall), .expected = MethodImportAttributes.CallingConventionFastCall}, 1881New With {.n = 3, .attr = MakeDllImport(cc:=CallingConvention.StdCall), .expected = MethodImportAttributes.CallingConventionStdCall}, 1882New With {.n = 4, .attr = MakeDllImport(cc:=CallingConvention.ThisCall), .expected = MethodImportAttributes.CallingConventionThisCall}, 1883New With {.n = 5, .attr = MakeDllImport(cc:=CallingConvention.Winapi), .expected = MethodImportAttributes.CallingConventionWinApi}, 1885New With {.n = 6, .attr = MakeDllImport(), .expected = MethodImportAttributes.CallingConventionWinApi}, 1886New With {.n = 7, .attr = MakeDllImport(charSet:=CharSet.None), .expected = MethodImportAttributes.CallingConventionWinApi}, 1887New With {.n = 8, .attr = MakeDllImport(charSet:=CharSet.Ansi), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.CharSetAnsi}, 1888New With {.n = 9, .attr = MakeDllImport(charSet:=CharSet.Unicode), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.CharSetUnicode}, 1889New With {.n = 10, .attr = MakeDllImport(charSet:=CharSet.Auto), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.CharSetAuto}, 1891New With {.n = 11, .attr = MakeDllImport(exactSpelling:=True), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.ExactSpelling}, 1892New With {.n = 12, .attr = MakeDllImport(exactSpelling:=False), .expected = MethodImportAttributes.CallingConventionWinApi}, 1894New With {.n = 13, .attr = MakeDllImport(charSet:=CharSet.Ansi, exactSpelling:=True), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.ExactSpelling Or MethodImportAttributes.CharSetAnsi}, 1895New With {.n = 14, .attr = MakeDllImport(charSet:=CharSet.Ansi, exactSpelling:=False), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.CharSetAnsi}, 1896New With {.n = 15, .attr = MakeDllImport(charSet:=CharSet.Unicode, exactSpelling:=True), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.ExactSpelling Or MethodImportAttributes.CharSetUnicode}, 1897New With {.n = 16, .attr = MakeDllImport(charSet:=CharSet.Unicode, exactSpelling:=False), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.CharSetUnicode}, 1898New With {.n = 17, .attr = MakeDllImport(charSet:=CharSet.Auto, exactSpelling:=True), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.ExactSpelling Or MethodImportAttributes.CharSetAuto}, 1899New With {.n = 18, .attr = MakeDllImport(charSet:=CharSet.Auto, exactSpelling:=False), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.CharSetAuto}, 1901New With {.n = 19, .attr = MakeDllImport(preserveSig:=True), .expected = MethodImportAttributes.CallingConventionWinApi}, 1902New With {.n = 20, .attr = MakeDllImport(preserveSig:=False), .expected = MethodImportAttributes.CallingConventionWinApi}, 1904New With {.n = 21, .attr = MakeDllImport(setLastError:=True), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.SetLastError}, 1905New With {.n = 22, .attr = MakeDllImport(setLastError:=False), .expected = MethodImportAttributes.CallingConventionWinApi}, 1907New With {.n = 23, .attr = MakeDllImport(bestFitMapping:=True), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.BestFitMappingEnable}, 1908New With {.n = 24, .attr = MakeDllImport(bestFitMapping:=False), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.BestFitMappingDisable}, 1910New With {.n = 25, .attr = MakeDllImport(throwOnUnmappableChar:=True), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.ThrowOnUnmappableCharEnable}, 1911New With {.n = 26, .attr = MakeDllImport(throwOnUnmappableChar:=False), .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.ThrowOnUnmappableCharDisable}, 1913New With {.n = 27, .attr = "<DllImport(""bar"", CharSet:=CType(15, CharSet), SetLastError:=True)>", .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.SetLastError}, 1914New With {.n = 28, .attr = "<DllImport(""bar"", CallingConvention:=CType(15, CallingConvention), SetLastError:=True)>", .expected = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.SetLastError} 2523Assert.Equal(MethodImportAttributes.CharSetAnsi, import.Attributes And MethodImportAttributes.CharSetMask) 2556Assert.Equal(MethodImportAttributes.None, import.Attributes And MethodImportAttributes.CharSetMask) 2776Assert.Equal(MethodImportAttributes.ExactSpelling Or 2777MethodImportAttributes.CharSetAnsi Or 2778MethodImportAttributes.CallingConventionWinApi Or 2779MethodImportAttributes.SetLastError, import.Attributes) 2808Const declareFlags = MethodImportAttributes.CallingConventionWinApi Or MethodImportAttributes.SetLastError 2827Assert.Equal(declareFlags Or MethodImportAttributes.ExactSpelling Or MethodImportAttributes.CharSetAnsi, import.Attributes) 2832Assert.Equal(declareFlags Or MethodImportAttributes.ExactSpelling Or MethodImportAttributes.CharSetUnicode, import.Attributes) 2837Assert.Equal(declareFlags Or MethodImportAttributes.CharSetAuto, import.Attributes) 2842Assert.Equal(declareFlags Or MethodImportAttributes.ExactSpelling Or MethodImportAttributes.CharSetAnsi, import.Attributes)
System.Reflection.Emit (24)
System\Reflection\Emit\ModuleBuilderImpl.cs (1)
961MethodImportAttributes attributes, ModuleReferenceHandle moduleHandle) =>
System\Reflection\Emit\PseudoCustomAttributesData.cs (23)
14private readonly MethodImportAttributes _flags; 16internal DllImportData(string moduleName, string? entryPoint, MethodImportAttributes flags) 27public MethodImportAttributes Flags => _flags; 37MethodImportAttributes importAttributes = MethodImportAttributes.None; 61importAttributes |= MethodImportAttributes.ExactSpelling; 67importAttributes |= MethodImportAttributes.SetLastError; 73importAttributes |= MethodImportAttributes.BestFitMappingEnable; 77importAttributes |= MethodImportAttributes.BestFitMappingDisable; 83importAttributes |= MethodImportAttributes.ThrowOnUnmappableCharEnable; 87importAttributes |= MethodImportAttributes.ThrowOnUnmappableCharDisable; 103MethodImportAttributes importAttributes = MatchNativeCallingConvention(nativeCallConv); 109private static MethodImportAttributes MatchNativeCharSet(CharSet nativeCharSet) => 112CharSet.Ansi => MethodImportAttributes.CharSetAnsi, 113CharSet.Auto => MethodImportAttributes.CharSetAuto, 114CharSet.Unicode => MethodImportAttributes.CharSetUnicode, 115_ => MethodImportAttributes.CharSetAuto 118private static MethodImportAttributes MatchNativeCallingConvention(CallingConvention nativeCallConv) => 121CallingConvention.Cdecl => MethodImportAttributes.CallingConventionCDecl, 122CallingConvention.FastCall => MethodImportAttributes.CallingConventionFastCall, 123CallingConvention.StdCall => MethodImportAttributes.CallingConventionStdCall, 124CallingConvention.ThisCall => MethodImportAttributes.CallingConventionThisCall, 125_ => MethodImportAttributes.CallingConventionWinApi // Roslyn defaults with this
System.Reflection.Metadata (6)
System\Reflection\Metadata\Ecma335\MetadataBuilder.Tables.cs (1)
1023MethodImportAttributes attributes,
System\Reflection\Metadata\Internal\Tables.cs (2)
1710var pInvokeMapFlags = (MethodImportAttributes)Block.PeekUInt16(rowOffset + _FlagsOffset);
System\Reflection\Metadata\TypeSystem\MethodImport.cs (3)
8private readonly MethodImportAttributes _attributes; 12internal MethodImport(MethodImportAttributes attributes, StringHandle name, ModuleReferenceHandle module) 19public MethodImportAttributes Attributes { get { return _attributes; } }
System.Reflection.MetadataLoadContext (17)
System\Reflection\TypeLoading\MethodBase\Ecma\EcmaMethodDecoder.cs (17)
123MethodImportAttributes a = mi.Attributes; 124CharSet charSet = (a & MethodImportAttributes.CharSetMask) switch 126MethodImportAttributes.CharSetAnsi => CharSet.Ansi, 127MethodImportAttributes.CharSetAuto => CharSet.Auto, 128MethodImportAttributes.CharSetUnicode => CharSet.Unicode, 131CallingConvention callConv = (a & MethodImportAttributes.CallingConventionMask) switch 133MethodImportAttributes.CallingConventionCDecl => CallingConvention.Cdecl, 134MethodImportAttributes.CallingConventionFastCall => CallingConvention.FastCall, 135MethodImportAttributes.CallingConventionStdCall => CallingConvention.StdCall, 136MethodImportAttributes.CallingConventionThisCall => CallingConvention.ThisCall, 137MethodImportAttributes.CallingConventionWinApi => CallingConvention.Winapi, 143ExactSpelling = (a & MethodImportAttributes.ExactSpelling) != 0, 147SetLastError = (a & MethodImportAttributes.SetLastError) != 0, 148BestFitMapping = (a & MethodImportAttributes.BestFitMappingMask) == MethodImportAttributes.BestFitMappingEnable, 149ThrowOnUnmappableChar = (a & MethodImportAttributes.ThrowOnUnmappableCharMask) == MethodImportAttributes.ThrowOnUnmappableCharEnable,