Skip to content

Commit cc1ad00

Browse files
committed
Avoid unnecessary use of Linq
1 parent b09b2de commit cc1ad00

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsAssemblyRewriter.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
54

65
using Microsoft.Android.Build.Tasks;
76
using Microsoft.Build.Utilities;
@@ -84,7 +83,7 @@ public void Rewrite (bool brokenExceptionTransitions)
8483
continue;
8584
}
8685

87-
if (method.NativeCallback.GetCustomAttributes ("System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute").Any (ca => ca != null)) {
86+
if (HasUnmanagedCallersOnlyAttribute (method.NativeCallback)) {
8887
log.LogDebugMessage ($"[{targetArch}] Method '{method.NativeCallback.FullName}' does not need a wrapper, it already has UnmanagedCallersOnlyAttribute");
8988
method.NativeCallbackWrapper = method.NativeCallback;
9089
continue;
@@ -194,6 +193,17 @@ void RemoveFile (string? path)
194193
log.LogDebugMessage ($"[{targetArch}] {ex.ToString ()}");
195194
}
196195
}
196+
197+
static bool HasUnmanagedCallersOnlyAttribute (MethodDefinition method)
198+
{
199+
foreach (CustomAttribute ca in method.CustomAttributes) {
200+
if (ca.Constructor.DeclaringType.FullName == "System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute") {
201+
return true;
202+
}
203+
}
204+
205+
return false;
206+
}
197207
}
198208

199209
MethodDefinition GenerateWrapper (MarshalMethodEntry method, Dictionary<AssemblyDefinition, AssemblyImports> assemblyImports, bool brokenExceptionTransitions)

0 commit comments

Comments
 (0)