Skip to content

Commit

Permalink
Add RequiresUnreferencedCode to DefinePInvokeMethod (#56537)
Browse files Browse the repository at this point in the history
* Add RequiresUnreferencedCode to DefinePInvokeMethod

* adjust message per PR feedback
  • Loading branch information
krwq authored Aug 5, 2021
1 parent a426032 commit 1a4675d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -895,13 +895,15 @@ private EnumBuilder DefineEnumNoLock(string name, TypeAttributes visibility, Typ

#region Define Global Method

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes,
CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes,
CallingConvention nativeCallConv, CharSet nativeCharSet)
{
return DefinePInvokeMethod(name, dllName, name, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes,
CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, CallingConvention nativeCallConv,
CharSet nativeCharSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ private MethodBuilder DefineMethodNoLock(string name, MethodAttributes attribute
return method;
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes,
CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes,
CallingConvention nativeCallConv, CharSet nativeCharSet)
Expand All @@ -1338,6 +1339,7 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttr
return method;
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes,
CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes,
CallingConvention nativeCallConv, CharSet nativeCharSet)
Expand All @@ -1348,6 +1350,7 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, string ent
return method;
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes,
CallingConventions callingConvention,
Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers,
Expand All @@ -1360,8 +1363,7 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, string ent
return method;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2082:UnrecognizedReflectionPattern",
Justification = "Reflection.Emit is not subject to trimming")]
[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
private MethodBuilder DefinePInvokeMethodHelper(
string name, string dllName, string importName, MethodAttributes attributes, CallingConventions callingConvention,
Type? returnType, Type[]? returnTypeRequiredCustomModifiers, Type[]? returnTypeOptionalCustomModifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ public void CreateGlobalFunctions() { }
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? requiredReturnTypeCustomModifiers, System.Type[]? optionalReturnTypeCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? requiredParameterTypeCustomModifiers, System.Type[][]? optionalParameterTypeCustomModifiers) { throw null; }
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Type? returnType, System.Type[]? parameterTypes) { throw null; }
public System.Reflection.Emit.FieldBuilder DefineInitializedData(string name, byte[] data, System.Reflection.FieldAttributes attributes) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw null; }
public System.Reflection.Emit.TypeBuilder DefineType(string name) { throw null; }
public System.Reflection.Emit.TypeBuilder DefineType(string name, System.Reflection.TypeAttributes attr) { throw null; }
Expand Down Expand Up @@ -494,8 +496,11 @@ public void DefineMethodOverride(System.Reflection.MethodInfo methodInfoBody, Sy
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type? parent, System.Reflection.Emit.PackingSize packSize) { throw null; }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type? parent, System.Reflection.Emit.PackingSize packSize, int typeSize) { throw null; }
public System.Reflection.Emit.TypeBuilder DefineNestedType(string name, System.Reflection.TypeAttributes attr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type? parent, System.Type[]? interfaces) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw null; }
public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[]? parameterTypes) { throw null; }
public System.Reflection.Emit.PropertyBuilder DefineProperty(string name, System.Reflection.PropertyAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[]? returnTypeRequiredCustomModifiers, System.Type[]? returnTypeOptionalCustomModifiers, System.Type[]? parameterTypes, System.Type[][]? parameterTypeRequiredCustomModifiers, System.Type[][]? parameterTypeOptionalCustomModifiers) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes
return mb;
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
{
return DefinePInvokeMethod(name, dllName, name, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
{
if (name == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,15 @@ public MethodBuilder DefineMethod(string name, MethodAttributes attributes, Call
return res;
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
{
return DefinePInvokeMethod(name, dllName, entryName, attributes,
callingConvention, returnType, null, null, parameterTypes,
null, null, nativeCallConv, nativeCharSet);
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(
string name,
string dllName,
Expand Down Expand Up @@ -633,6 +635,7 @@ MethodBuilder res
return res;
}

[RequiresUnreferencedCode("P/Invoke marshalling may dynamically access members that could be trimmed.")]
public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
{
return DefinePInvokeMethod(name, dllName, name, attributes, callingConvention, returnType, parameterTypes,
Expand Down

0 comments on commit 1a4675d

Please sign in to comment.