From d412e4ba26745b0a52f8766dad5506d4dcec8f0f Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Mon, 11 May 2026 17:44:36 -0700 Subject: [PATCH] Generate polyfills for CA2263 --- .../Actions/Calls/ParamsDictArgBuilder.cs | 4 ++-- src/core/Microsoft.Dynamic/Hosting/Shell/BasicConsole.cs | 2 +- .../Interpreter/Instructions/InstructionList.cs | 2 +- src/core/Microsoft.Dynamic/Interpreter/LightLambda.cs | 2 +- src/core/Microsoft.Dynamic/Microsoft.Dynamic.csproj | 9 +++------ .../Microsoft.Scripting.Metadata.csproj | 2 +- src/core/Microsoft.Scripting/Microsoft.Scripting.csproj | 2 +- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/core/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs b/src/core/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs index 2e7d5079..db51fbcc 100644 --- a/src/core/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs +++ b/src/core/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs @@ -99,7 +99,7 @@ private Func GetCreationDelegate(Type dictType) { if (genArgs[0] == typeof(string) || genArgs[0] == typeof(object)) { MethodInfo target = typeof(BinderOps).GetMethod(nameof(BinderOps.MakeReadOnlyDictionary)).MakeGenericMethod(genArgs); - func = (Func)target.CreateDelegate(typeof(Func)); + func = target.CreateDelegate>(); } } else if (dictType.GetGenericTypeDefinition() == typeof(IDictionary<,>) || dictType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) { @@ -107,7 +107,7 @@ private Func GetCreationDelegate(Type dictType) { if (genArgs[0] == typeof(string) || genArgs[0] == typeof(object)) { MethodInfo target = typeof(BinderOps).GetMethod(nameof(BinderOps.MakeDictionary)).MakeGenericMethod(genArgs); - func = (Func)target.CreateDelegate(typeof(Func)); + func = target.CreateDelegate>(); } } } else if (dictType == typeof(IDictionary)) { diff --git a/src/core/Microsoft.Dynamic/Hosting/Shell/BasicConsole.cs b/src/core/Microsoft.Dynamic/Hosting/Shell/BasicConsole.cs index 196b0d41..a3d51eff 100644 --- a/src/core/Microsoft.Dynamic/Hosting/Shell/BasicConsole.cs +++ b/src/core/Microsoft.Dynamic/Hosting/Shell/BasicConsole.cs @@ -104,7 +104,7 @@ private static bool HasDarkBackground(bool? isDarkConsole) { } // Try autodetect - if (Enum.IsDefined(typeof(ConsoleColor), Console.BackgroundColor)) { + if (Enum.IsDefined(Console.BackgroundColor)) { return IsDark(Console.BackgroundColor); } diff --git a/src/core/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs b/src/core/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs index e02de6dc..79d05162 100644 --- a/src/core/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs +++ b/src/core/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs @@ -802,7 +802,7 @@ internal static Instruction CreateDynamicInstruction(Type delegateType, CallSite return new DynamicInstructionN(delegateType, CallSite.Create(delegateType, binder)); } - factory = (Func)instructionType.GetMethod("Factory").CreateDelegate(typeof(Func)); + factory = instructionType.GetMethod("Factory").CreateDelegate>(); _factories[delegateType] = factory; } } diff --git a/src/core/Microsoft.Dynamic/Interpreter/LightLambda.cs b/src/core/Microsoft.Dynamic/Interpreter/LightLambda.cs index 34bb02af..d2399638 100644 --- a/src/core/Microsoft.Dynamic/Interpreter/LightLambda.cs +++ b/src/core/Microsoft.Dynamic/Interpreter/LightLambda.cs @@ -95,7 +95,7 @@ private static Func MakeRunDelegateCtor(Type delegateType name = "Make" + name + paramInfos.Length; MethodInfo ctorMethod = typeof(LightLambda).GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(paramTypes); - return _runCache[delegateType] = (Func)ctorMethod.CreateDelegate(typeof(Func)); + return _runCache[delegateType] = ctorMethod.CreateDelegate>(); } runMethod = typeof(LightLambda).GetMethod(name + paramInfos.Length, BindingFlags.NonPublic | BindingFlags.Instance); diff --git a/src/core/Microsoft.Dynamic/Microsoft.Dynamic.csproj b/src/core/Microsoft.Dynamic/Microsoft.Dynamic.csproj index 99251395..7ad7b3e5 100644 --- a/src/core/Microsoft.Dynamic/Microsoft.Dynamic.csproj +++ b/src/core/Microsoft.Dynamic/Microsoft.Dynamic.csproj @@ -10,16 +10,13 @@ P:System.Collections.ObjectModel.ReadOnlyCollection`1.Empty; P:System.Collections.ObjectModel.ReadOnlyDictionary`2.Empty; + M:System.Enum.IsDefined``1(``0); + M:System.Reflection.MethodInfo.CreateDelegate``1; M:System.String.IndexOf(System.Char,System.StringComparison); M:System.String.StartsWith(System.Char); - - - $(NoWarn);CA2263 - - @@ -32,7 +29,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/core/Microsoft.Scripting.Metadata/Microsoft.Scripting.Metadata.csproj b/src/core/Microsoft.Scripting.Metadata/Microsoft.Scripting.Metadata.csproj index 2a7de3cf..3ecd7aa7 100644 --- a/src/core/Microsoft.Scripting.Metadata/Microsoft.Scripting.Metadata.csproj +++ b/src/core/Microsoft.Scripting.Metadata/Microsoft.Scripting.Metadata.csproj @@ -18,7 +18,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/core/Microsoft.Scripting/Microsoft.Scripting.csproj b/src/core/Microsoft.Scripting/Microsoft.Scripting.csproj index feab801e..0da83db6 100644 --- a/src/core/Microsoft.Scripting/Microsoft.Scripting.csproj +++ b/src/core/Microsoft.Scripting/Microsoft.Scripting.csproj @@ -22,7 +22,7 @@ - + all runtime; build; native; contentfiles; analyzers