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