From 19cc97fe1774e25e499b1ef7cea53000610c1958 Mon Sep 17 00:00:00 2001 From: Unknown6656 Date: Wed, 8 Nov 2023 09:04:18 +0100 Subject: [PATCH] switched to collection expressions --- .../CommandLineInterface/InteractiveShell.cs | 8 ++++---- .../CommandLineInterface/MainProgram.cs | 4 ++-- ...lugins.Au3Framework.AdditionalFunctions.cs | 2 +- .../Plugins.Au3Framework.Functions.cs | 12 +++++------ .../Runtime/DelegateBuilder.cs | 20 +++++++++---------- new/AutoItInterpreter/Runtime/Function.cs | 6 +++--- .../Runtime/GlobalObjectStorage.cs | 4 ++-- .../Runtime/NativeInterop.cs | 4 ++-- .../Runtime/ScriptScanner.cs | 6 +++--- new/AutoItInterpreter/Runtime/Variant.cs | 2 +- .../Plugins.Serial/SerialFunctionProvider.cs | 2 +- new/util/AutoIt3.COM.Server/COMServer.cs | 4 ++-- 12 files changed, 37 insertions(+), 37 deletions(-) diff --git a/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs b/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs index 1b98cb6..0d6f375 100644 --- a/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs +++ b/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs @@ -19,7 +19,7 @@ public sealed class InteractiveShell { public const int MIN_WIDTH = 128; - internal static readonly string[] KNOWN_OPERATORS = { "+", "-", "*", "/", "+=", "-=", "*=", "/=", "&", "&=", "^", "<=", "<", ">", ">=", "<>", "=", "==" }; + internal static readonly string[] KNOWN_OPERATORS = ["+", "-", "*", "/", "+=", "-=", "*=", "/=", "&", "&=", "^", "<=", "<", ">", ">=", "<>", "=", "=="]; private static readonly Regex REGEX_END_OF_MULTILINE = new(@"^(.*\s+)?(?_)$", RegexOptions.Compiled); private static readonly RGBAColor COLOR_HELP_FG = 0xffff; private static readonly RGBAColor COLOR_SEPARATOR = 0xfaaa; @@ -230,15 +230,15 @@ private void MainLoop() private void DrawResizeWarning() { - string[] message = new[] - { + string[] message = + [ " CONSOLE WINDOW TOO SMALL! ", "-----------------------------", " Please resize this window ", $" to a minimum size of {MIN_WIDTH}x32 ", "to use the interactive shell.", $" Current window size: {WIDTH}x{HEIGHT}" - }; + ]; int w = message.Max(l => l.Length); ConsoleExtensions.RGBForegroundColor = RGBAColor.Red; diff --git a/new/AutoItInterpreter/CommandLineInterface/MainProgram.cs b/new/AutoItInterpreter/CommandLineInterface/MainProgram.cs index 19e8326..e175f87 100644 --- a/new/AutoItInterpreter/CommandLineInterface/MainProgram.cs +++ b/new/AutoItInterpreter/CommandLineInterface/MainProgram.cs @@ -707,7 +707,7 @@ public static void PrintReturnCodeAndTelemetry(int retcode, Telemetry telemetry) RGBAColor col_hotpath = RGBAColor.Salmon; Regex regex_trimstart = new(@"^(?\s*)0(?\d[:\.].+)$", RegexOptions.Compiled); - string[] headers = { + string[] headers = [ lang["debug.telemetry.columns.category"], lang["debug.telemetry.columns.count"], lang["debug.telemetry.columns.total"], @@ -716,7 +716,7 @@ public static void PrintReturnCodeAndTelemetry(int retcode, Telemetry telemetry) lang["debug.telemetry.columns.max"], lang["debug.telemetry.columns.parent"], lang["debug.telemetry.columns.relative"], - }; + ]; List<(string[] cells, TelemetryTimingsNode node)> rows = []; static string ReplaceStart(string input, params (string search, string replace)[] substitutions) { diff --git a/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.AdditionalFunctions.cs b/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.AdditionalFunctions.cs index 90cf9e7..3093c06 100644 --- a/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.AdditionalFunctions.cs +++ b/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.AdditionalFunctions.cs @@ -37,7 +37,7 @@ internal static FunctionReturnValue ConsoleClear(CallFrame frame, Variant[] args } internal static FunctionReturnValue ConsoleWriteLine(CallFrame frame, Variant[] args) => - FrameworkFunctions.ConsoleWrite(frame, new[] { (args.Length > 0 ? args[0] : "") & "\r\n" }); + FrameworkFunctions.ConsoleWrite(frame, [(args.Length > 0 ? args[0] : "") & "\r\n"]); internal static FunctionReturnValue ConsoleReadLine(CallFrame frame, Variant[] args) => (Variant)Console.ReadLine(); diff --git a/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.Functions.cs b/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.Functions.cs index 64334cc..7e47590 100644 --- a/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.Functions.cs +++ b/new/AutoItInterpreter/Extensibility/Plugins.Au3Framework.Functions.cs @@ -530,7 +530,7 @@ internal static FunctionReturnValue ConsoleRead(CallFrame frame, Variant[] args) if (input < 0) return FunctionReturnValue.Error(1); else if (binary) - return Variant.FromBinary(new[] { (byte)(input & 0xff) }); + return Variant.FromBinary([(byte)(input & 0xff)]); else return Variant.FromString(new string(new[] { (char)input })); }); @@ -1855,14 +1855,14 @@ internal static FunctionReturnValue InetGetInfo(CallFrame frame, Variant[] args) { int index = (int)args[1]; Variant[] array = - { + [ 0, // TODO : currently downloaded 0, inet.Complete, inet.Complete && !inet.Error, inet.Error, args[0] - }; + ]; return index >= 0 && index < array.Length ? array[index] : Variant.FromArray(frame.Interpreter, array); } @@ -2743,10 +2743,10 @@ internal static unsafe FunctionReturnValue Shutdown(CallFrame frame, Variant[] a TOKEN_PRIVILEGES tk = new() { PrivilegeCount = 1, - Privileges = new[] - { + Privileges = + [ new LUID_AND_ATTRIBUTES { Attributes = 0x00000002 } - } + ] }; NativeInterop.LookupPrivilegeValue(null, "SeShutdownPrivilege", ref tk.Privileges[0].Luid); NativeInterop.AdjustTokenPrivileges(token, false, ref tk, 0, null, null); diff --git a/new/AutoItInterpreter/Runtime/DelegateBuilder.cs b/new/AutoItInterpreter/Runtime/DelegateBuilder.cs index 3cb36e1..49060fc 100644 --- a/new/AutoItInterpreter/Runtime/DelegateBuilder.cs +++ b/new/AutoItInterpreter/Runtime/DelegateBuilder.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Reflection.Emit; using System.Reflection; @@ -63,7 +63,7 @@ private DelegateBuilder() method_il.Emit(OpCodes.Stloc_0); MethodInfo gettypefromhnd = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle))!; - ConstructorInfo tuplector = typeof((object, Type)).GetConstructor(new[] { typeof(object), typeof(Type) })!; + ConstructorInfo tuplector = typeof((object, Type)).GetConstructor([typeof(object), typeof(Type)])!; for (int i = 0; i < @params.Length; ++i) { @@ -93,7 +93,7 @@ private DelegateBuilder() ILGenerator il_cctor = cctor_builder.GetILGenerator(); il_cctor.Emit(OpCodes.Ldftn, method_builder); - il_cctor.Emit(OpCodes.Call, typeof(IntPtr).GetMethod("op_Explicit", new[] { typeof(void*) })!); + il_cctor.Emit(OpCodes.Call, typeof(IntPtr).GetMethod("op_Explicit", [typeof(void*)])!); il_cctor.Emit(OpCodes.Stsfld, field_ptr_builder); il_cctor.Emit(OpCodes.Ret); @@ -131,14 +131,14 @@ private DelegateBuilder() signature.ReturnType.CallConvention.IsWinAPI ? CallingConvention.Winapi : CallingConvention.Cdecl; delegate_builder.SetCustomAttribute(new CustomAttributeBuilder( - typeof(UnmanagedFunctionPointerAttribute).GetConstructor(new[] { typeof(CallingConvention) })!, + typeof(UnmanagedFunctionPointerAttribute).GetConstructor([typeof(CallingConvention)])!, new object[] { callconv } )); ConstructorBuilder constructor = delegate_builder.DefineConstructor( MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public, CallingConventions.Standard, - new[] { typeof(object), typeof(nint) } + [typeof(object), typeof(nint)] ); constructor.SetImplementationFlags(MethodImplAttributes.CodeTypeMask); constructor.DefineParameter(1, ParameterAttributes.None, "object"); @@ -156,7 +156,7 @@ private DelegateBuilder() CallingConventions.Standard, rettype, null, - new[] { + [ callconv switch { CallingConvention.Cdecl => typeof(CallConvCdecl), @@ -166,7 +166,7 @@ private DelegateBuilder() CallingConvention.Winapi when NativeInterop.OperatingSystem == OS.Windows => typeof(CallConvStdcall), _ => typeof(CallConvCdecl), } - }, + ], @params!, null, null @@ -184,7 +184,7 @@ ParameterBuilder ProcessParameter(int index, TYPE type) if (type.IsWSTR || type.IsSTR) parameter.SetCustomAttribute(new CustomAttributeBuilder( - typeof(MarshalAsAttribute).GetConstructor(new[] { typeof(UnmanagedType) })!, + typeof(MarshalAsAttribute).GetConstructor([typeof(UnmanagedType)])!, new object[] { type.IsWSTR ? UnmanagedType.LPWStr : UnmanagedType.LPStr } )); @@ -276,11 +276,11 @@ ParameterBuilder ProcessParameter(int index, TYPE type) // if (otypes[i].IsWSTR || otypes[i].IsSTR) // attr |= FieldAttributes.HasFieldMarshal; - FieldBuilder field = builder.DefineField("Item" + i, ftype, new[] { typeof(MarshalAsAttribute) }, null, attr); + FieldBuilder field = builder.DefineField("Item" + i, ftype, [typeof(MarshalAsAttribute)], null, attr); if (otypes[i].IsWSTR || otypes[i].IsSTR) field.SetCustomAttribute(new CustomAttributeBuilder( - typeof(MarshalAsAttribute).GetConstructor(new[] { typeof(UnmanagedType) })!, + typeof(MarshalAsAttribute).GetConstructor([typeof(UnmanagedType)])!, new object[] { otypes[i].IsWSTR ? UnmanagedType.LPWStr : UnmanagedType.LPStr } )); } diff --git a/new/AutoItInterpreter/Runtime/Function.cs b/new/AutoItInterpreter/Runtime/Function.cs index fb57487..735a4dd 100644 --- a/new/AutoItInterpreter/Runtime/Function.cs +++ b/new/AutoItInterpreter/Runtime/Function.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Reflection; using System.Linq; @@ -25,12 +25,12 @@ public abstract class ScriptFunction /// A collection of reserved function names. /// public static readonly string[] RESERVED_NAMES = - { + [ "_", "$_", VARIABLE.Discard.Name, "$GLOBAL", "GLOBAL", "STATIC", "CONST", "DIM", "REDIM", "ENUM", "STEP", "LOCAL", "FOR", "IN", "NEXT", "TO", "FUNC", "ENDFUNC", "DO", "UNTIL", "WHILE", "WEND", "IF", "THEN", "ELSE", "ENDIF", "ELSEIF", "SELECT", "ENDSELECT", "CASE", "SWITCH", "ENDSWITCH", "WITH", "ENDWITH", "CONTINUECASE", "CONTINUELOOP", "EXIT", "EXITLOOP", "CACHED", "VOLATILE", "RETURN", "TRUE", "FALSE", "DEFAULT", "NULL", "BYREF", "REF", "AND", "OR", "NOT", "CLEAR", "NEW", "DELETE", "CLASS", - }; + ]; /// diff --git a/new/AutoItInterpreter/Runtime/GlobalObjectStorage.cs b/new/AutoItInterpreter/Runtime/GlobalObjectStorage.cs index 192c8f5..575a376 100644 --- a/new/AutoItInterpreter/Runtime/GlobalObjectStorage.cs +++ b/new/AutoItInterpreter/Runtime/GlobalObjectStorage.cs @@ -215,9 +215,9 @@ orderby pars.Length descending return false; } - public bool TrySetNETIndex(object instance, Variant index, Variant value) => TryInvokeNETMember(instance, "set_Item", new[] { index, value }, out _); + public bool TrySetNETIndex(object instance, Variant index, Variant value) => TryInvokeNETMember(instance, "set_Item", [index, value], out _); - public bool TryGetNETIndex(object instance, Variant index, out Variant value) => TryInvokeNETMember(instance, "get_Item", new[] { index }, out value); + public bool TryGetNETIndex(object instance, Variant index, out Variant value) => TryInvokeNETMember(instance, "get_Item", [index], out value); public bool TrySetNETMember(object instance, string member, Variant value) { diff --git a/new/AutoItInterpreter/Runtime/NativeInterop.cs b/new/AutoItInterpreter/Runtime/NativeInterop.cs index 416b82e..8baf95f 100644 --- a/new/AutoItInterpreter/Runtime/NativeInterop.cs +++ b/new/AutoItInterpreter/Runtime/NativeInterop.cs @@ -267,8 +267,8 @@ public static void AddFolderToEnvPath(string dir) } public static (string stdout, int code) Exec(string command, bool use_shellexec = false) => DoPlatformDependent( - () => InternalRun("cmd.exe", new[] { "/c", command }, use_shellexec), - () => InternalRun("/bin/bash", new[] { "-c", command }, use_shellexec) + () => InternalRun("cmd.exe", ["/c", command], use_shellexec), + () => InternalRun("/bin/bash", ["-c", command], use_shellexec) ); private static (string stdout, int code) InternalRun(string filename, string[] arguments, bool use_shexec) diff --git a/new/AutoItInterpreter/Runtime/ScriptScanner.cs b/new/AutoItInterpreter/Runtime/ScriptScanner.cs index 59758e4..d06faa4 100644 --- a/new/AutoItInterpreter/Runtime/ScriptScanner.cs +++ b/new/AutoItInterpreter/Runtime/ScriptScanner.cs @@ -26,7 +26,7 @@ namespace Unknown6656.AutoIt3.Runtime; /// public sealed class ScriptScanner { - private static readonly string[] AUTOIT_FILE_EXTENSIONS = { "", ".au3", ".au2", ".au", ".aupp", ".au++" }; + private static readonly string[] AUTOIT_FILE_EXTENSIONS = ["", ".au3", ".au2", ".au", ".aupp", ".au++"]; private const RegexOptions REGEX_OPTIONS = RegexOptions.IgnoreCase | RegexOptions.Compiled; private const string REGEX_FUNC_MODIFIERS = /*lang=regex*/@"((\s+|\b)(?volatile(\s+cached)?|cached(\s+volatile)?)(\s+|\b))?"; @@ -51,14 +51,14 @@ public sealed class ScriptScanner private static readonly Regex REGEX_NOTRYICON = new(@"^#notrayicon\b", REGEX_OPTIONS); private static readonly Func[] _existing_resolvers = - { + [ ResolveUNC, ResolveHTTP, ResolveFTP, #if SUPPORT_SSH ResolveSSH, #endif - }; + ]; private readonly ConcurrentDictionary _cached_functions = new(); private readonly ConcurrentDictionary _cached_scripts = new(); diff --git a/new/AutoItInterpreter/Runtime/Variant.cs b/new/AutoItInterpreter/Runtime/Variant.cs index c18bee5..a17455b 100644 --- a/new/AutoItInterpreter/Runtime/Variant.cs +++ b/new/AutoItInterpreter/Runtime/Variant.cs @@ -486,7 +486,7 @@ string s when s.StartsWith("0x", StringComparison.OrdinalIgnoreCase) => long.Try /// Binary representation public readonly byte[] ToBinary() => RawData switch { - bool b => new[] { (byte)(b ? 1 : 0) }, + bool b => [(byte)(b ? 1 : 0)], _ when Type is VariantType.Default => DataStream.FromUnmanaged(-1), null => DataStream.FromUnmanaged(0), int i => DataStream.FromUnmanaged(i), diff --git a/new/plugins/Plugins.Serial/SerialFunctionProvider.cs b/new/plugins/Plugins.Serial/SerialFunctionProvider.cs index 0acc9b3..e6870b9 100644 --- a/new/plugins/Plugins.Serial/SerialFunctionProvider.cs +++ b/new/plugins/Plugins.Serial/SerialFunctionProvider.cs @@ -14,7 +14,7 @@ public sealed class SerialFunctionProvider public SerialFunctionProvider(Interpreter interpreter) : base(interpreter) { - RegisterFunction(nameof(SerialOpen), 2, 5, SerialOpen, new Variant[] { (int)Parity.None, 8, (int)StopBits.One }); + RegisterFunction(nameof(SerialOpen), 2, 5, SerialOpen, [(int)Parity.None, 8, (int)StopBits.One]); RegisterFunction(nameof(SerialClose), 1, SerialClose); } diff --git a/new/util/AutoIt3.COM.Server/COMServer.cs b/new/util/AutoIt3.COM.Server/COMServer.cs index da20ce7..1d0807a 100644 --- a/new/util/AutoIt3.COM.Server/COMServer.cs +++ b/new/util/AutoIt3.COM.Server/COMServer.cs @@ -481,7 +481,7 @@ public bool TryGetIndex(COMData index, out COMData? value) { if (FindMembers(INDEX_NAME, MemberFindMode.Getter) is { Count: > 0 } match) { - object? data = GetMember(match[0], new[] { index.Data }); + object? data = GetMember(match[0], [index.Data]); value = COMData.FromArbitrary(data); @@ -501,7 +501,7 @@ public bool TrySetIndex(COMData index, COMData value) { if (FindMembers(INDEX_NAME, MemberFindMode.Setter) is { Count: > 0 } match) { - SetMember(match[0], value.Data, new[] { index.Data }); + SetMember(match[0], value.Data, [index.Data]); return true; }