diff --git a/ref/PluginUpdateCheck/.editorconfig b/ref/PluginUpdateCheck/.editorconfig index 77fcd03..ea1548d 100644 --- a/ref/PluginUpdateCheck/.editorconfig +++ b/ref/PluginUpdateCheck/.editorconfig @@ -158,3 +158,6 @@ dotnet_diagnostic.CS1591.severity = suggestion # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +# IDE0251: Make member 'readonly' +dotnet_diagnostic.IDE0251.severity = silent diff --git a/ref/ZipAssembly/.editorconfig b/ref/ZipAssembly/.editorconfig index 877dbcf..c453eac 100644 --- a/ref/ZipAssembly/.editorconfig +++ b/ref/ZipAssembly/.editorconfig @@ -155,3 +155,6 @@ dotnet_diagnostic.S3903.severity = none # S1133: Do not forget to remove this deprecated code someday. dotnet_diagnostic.S1133.severity = suggestion + +# AD0001: Analyzer Failure +dotnet_diagnostic.AD0001.severity = suggestion diff --git a/src/BlowFish/.editorconfig b/src/BlowFish/.editorconfig index 9251a1a..6204730 100644 --- a/src/BlowFish/.editorconfig +++ b/src/BlowFish/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -149,3 +150,9 @@ dotnet_diagnostic.S3903.severity = none # S1133: Do not forget to remove this deprecated code someday. dotnet_diagnostic.S1133.severity = suggestion + +# IDE0072: Add missing cases +dotnet_diagnostic.IDE0072.severity = suggestion + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/BlowFish/BlowFish/BlowFish.cs b/src/BlowFish/BlowFish/BlowFish.cs index 067c25c..c07005e 100644 --- a/src/BlowFish/BlowFish/BlowFish.cs +++ b/src/BlowFish/BlowFish/BlowFish.cs @@ -94,11 +94,11 @@ public static void XorBlock(Stream block, byte[] iv) [Obsolete("Using CipherMode.ECB in this method is deprecated.")] public string? Encrypt(string ct, CipherMode mode) => mode switch - { - CipherMode.ECB => this.bfInternal.EncryptECB(ct), - CipherMode.CBC => this.bfInternal.EncryptCBC(ct), - _ => null, - }; + { + CipherMode.ECB => this.bfInternal.EncryptECB(ct), + CipherMode.CBC => this.bfInternal.EncryptCBC(ct), + _ => null, + }; /// /// Encrypts a byte array. @@ -126,11 +126,11 @@ public static void XorBlock(Stream block, byte[] iv) [Obsolete("Using CipherMode.ECB in this method is deprecated.")] public string? Decrypt(string ct, CipherMode mode) => mode switch - { - CipherMode.ECB => this.bfInternal.DecryptECB(ct), - CipherMode.CBC => this.bfInternal.DecryptCBC(ct), - _ => null, - }; + { + CipherMode.ECB => this.bfInternal.DecryptECB(ct), + CipherMode.CBC => this.bfInternal.DecryptCBC(ct), + _ => null, + }; /// /// Decrypts a byte array. diff --git a/src/BlowFish/BlowFish/BlowFishInternal.cs b/src/BlowFish/BlowFish/BlowFishInternal.cs index 6c34c92..d250dbc 100644 --- a/src/BlowFish/BlowFish/BlowFishInternal.cs +++ b/src/BlowFish/BlowFish/BlowFishInternal.cs @@ -58,7 +58,7 @@ internal IEnumerable IV get => this.initVector; set { - var array = value?.ToArray() ?? Array.Empty(); + var array = value?.ToArray() ?? []; ThrowHelpers.ThrowInvalidOperation(array!.Length != 8, Resources.BlowFish_Invalid_IV_Size!); this.initVector = array; this.iVSet = true; @@ -70,16 +70,16 @@ internal IEnumerable IV // SBLOCKS ARE THE HEX DIGITS OF PI. // The amount of hex digits can be increased if you want to experiment with more rounds and longer key lengths private static ReadOnlySpan SetupP - => new uint[] - { + => + [ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b, - }; + ]; private static ReadOnlySpan SetupS0 - => new uint[] - { + => + [ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, @@ -123,11 +123,11 @@ private static ReadOnlySpan SetupS0 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a, - }; + ]; private static ReadOnlySpan SetupS1 - => new uint[] - { + => + [ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, @@ -171,11 +171,11 @@ private static ReadOnlySpan SetupS1 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7, - }; + ]; private static ReadOnlySpan SetupS2 - => new uint[] - { + => + [ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, @@ -219,11 +219,11 @@ private static ReadOnlySpan SetupS2 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0, - }; + ]; private static ReadOnlySpan SetupS3 - => new uint[] - { + => + [ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, @@ -267,7 +267,7 @@ private static ReadOnlySpan SetupS3 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6, - }; + ]; internal string EncryptCBC(string pt) { diff --git a/src/Common/.editorconfig b/src/Common/.editorconfig index a4f327c..d208a80 100644 --- a/src/Common/.editorconfig +++ b/src/Common/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -149,3 +150,9 @@ dotnet_diagnostic.CA1307.severity = warning # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +# IDE0072: Add missing cases +dotnet_diagnostic.IDE0072.severity = silent + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/Common/Common/MessageEventArgs.cs b/src/Common/Common/MessageEventArgs.cs index 0af92b3..f8137d8 100644 --- a/src/Common/Common/MessageEventArgs.cs +++ b/src/Common/Common/MessageEventArgs.cs @@ -8,35 +8,25 @@ namespace Elskom.Generic.Libs; /// /// Event that holds the message text and the caption. /// -public class MessageEventArgs : EventArgs +/// The text for the message. +/// The title (caption) for the message. +/// The error level for the message, or for no error level information. +public class MessageEventArgs(string text, string caption, ErrorLevel errorlevel) : EventArgs { - /// - /// Initializes a new instance of the class. - /// - /// The text for the message. - /// The title (caption) for the message. - /// The error level for the message, or for no error level information. - public MessageEventArgs(string text, string caption, ErrorLevel errorlevel) - { - this.Text = text; - this.Caption = caption; - this.ErrorLevel = errorlevel; - } - /// /// Gets the text for the message. /// - public string Text { get; } + public string Text { get; } = text; /// /// Gets the caption (title) for the message. /// - public string Caption { get; } + public string Caption { get; } = caption; /// /// Gets the of the message. /// - public ErrorLevel ErrorLevel { get; } + public ErrorLevel ErrorLevel { get; } = errorlevel; /// /// Gets or sets the ExitCode for the application. diff --git a/src/Common/Common/NotificationEventArgs.cs b/src/Common/Common/NotificationEventArgs.cs index 0ce4409..45e950c 100644 --- a/src/Common/Common/NotificationEventArgs.cs +++ b/src/Common/Common/NotificationEventArgs.cs @@ -8,63 +8,49 @@ namespace Elskom.Generic.Libs; /// /// Event that holds that data to call the apis for notifications. /// -public class NotificationEventArgs : EventArgs +/// The notification timeout. +/// The Notification or MessageBox title. +/// The Notification or MessageBox text. +/// The notification icon. +/// Indicates whether the event should call into the platform's Notifications API, or the MessageBox API. +/// The MessageBox Buttons. +/// The MessageBox Icon. +public class NotificationEventArgs(int timeout, string title, string text, int icon, bool useNotifications, int messageBoxButtons, int messageBoxIcon) : EventArgs { - /// - /// Initializes a new instance of the class. - /// - /// The notification timeout. - /// The Notification or MessageBox title. - /// The Notification or MessageBox text. - /// The notification icon. - /// Indicates whether the event should call into the platform's Notifications API, or the MessageBox API. - /// The MessageBox Buttons. - /// The MessageBox Icon. - public NotificationEventArgs(int timeout, string title, string text, int icon, bool useNotifications, int messageBoxButtons, int messageBoxIcon) - { - this.TimeOut = timeout; - this.Title = title; - this.Text = text; - this.Icon = icon; - this.UseNotifications = useNotifications; - this.MessageBoxButtons = messageBoxButtons; - this.MessageBoxIcon = messageBoxIcon; - } - /// /// Gets the timeout to use for the Notification. /// - public int TimeOut { get; } + public int TimeOut { get; } = timeout; /// /// Gets the title of the Notification or MessageBox. /// - public string Title { get; } + public string Title { get; } = title; /// /// Gets the text of the Notification or MessageBox. /// - public string Text { get; } + public string Text { get; } = text; /// /// Gets the icon to use for the Notification. /// - public int Icon { get; } + public int Icon { get; } = icon; /// /// Gets a value indicating whether gets whether to use platform's specific Notification APIs, or it's MessageBox APIs. /// - public bool UseNotifications { get; } + public bool UseNotifications { get; } = useNotifications; /// /// Gets the Buttons to use for the platform's specific MessageBox APIs. /// - public int MessageBoxButtons { get; } + public int MessageBoxButtons { get; } = messageBoxButtons; /// /// Gets the Icon to use for the MessageBox made using the platform's specific MessageBox APIs. /// - public int MessageBoxIcon { get; } + public int MessageBoxIcon { get; } = messageBoxIcon; /// /// Gets or sets the Result from the platform's specific MessageBox. diff --git a/src/Common/Common/ProcessStartOptions.cs b/src/Common/Common/ProcessStartOptions.cs index c371cf0..56538af 100644 --- a/src/Common/Common/ProcessStartOptions.cs +++ b/src/Common/Common/ProcessStartOptions.cs @@ -169,5 +169,5 @@ public override string ToString() {this.Stderr}", (false, false) => string.Empty, (false, true) => $"{this.Stderr}", - }; + }; } diff --git a/src/Common/Common/RuntimeHelpers.cs b/src/Common/Common/RuntimeHelpers.cs index 8ad7c0a..159fd65 100644 --- a/src/Common/Common/RuntimeHelpers.cs +++ b/src/Common/Common/RuntimeHelpers.cs @@ -15,26 +15,19 @@ internal static class RuntimeHelpers /// of the current process into an valid runtime identifier that the .NET SDK has. /// /// - /// An Runtime Identifier string, or null if it cannot be converted into an runtime identifier. + /// An Runtime Identifier , or if it cannot be converted into a runtime identifier. /// public static string GetCurrentRuntimeIdentifier() - => ( - - // Desktop Operating Systems. - OperatingSystem.IsWindows(), + => (OperatingSystem.IsWindows(), /* Desktop Operating Systems. */ OperatingSystem.IsLinux(), OperatingSystem.IsMacOS(), OperatingSystem.IsMacCatalyst(), OperatingSystem.IsFreeBSD(), - - // Phone Operting Systems. - OperatingSystem.IsAndroid(), + OperatingSystem.IsAndroid(), /* Phone Operating Systems. */ OperatingSystem.IsIOS(), OperatingSystem.IsWatchOS(), OperatingSystem.IsTvOS(), - - // Web Browser. - OperatingSystem.IsBrowser()) switch + OperatingSystem.IsBrowser() /* Web Browser. */) switch { (true, false, false, false, false, false, false, false, false, false) => $"win-{RuntimeInformation.ProcessArchitecture}", (false, true, false, false, false, false, false, false, false, false) => $"linux-{RuntimeInformation.ProcessArchitecture}", diff --git a/src/GenericPluginLoader/.editorconfig b/src/GenericPluginLoader/.editorconfig index c78e009..1fe5703 100644 --- a/src/GenericPluginLoader/.editorconfig +++ b/src/GenericPluginLoader/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -152,3 +153,6 @@ dotnet_diagnostic.CA1303.severity = warning # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/GenericPluginLoader/GenericPluginLoader/GenericPluginLoader.cs b/src/GenericPluginLoader/GenericPluginLoader/GenericPluginLoader.cs index c6c4593..2fdad70 100644 --- a/src/GenericPluginLoader/GenericPluginLoader/GenericPluginLoader.cs +++ b/src/GenericPluginLoader/GenericPluginLoader/GenericPluginLoader.cs @@ -20,7 +20,7 @@ public sealed class GenericPluginLoader /// public static event EventHandler? PluginLoaderMessage; - internal Dictionary> Contexts { get; } = new(); + internal Dictionary> Contexts { get; } = []; /// /// Loads plugins with the specified plugin interface type. @@ -71,8 +71,8 @@ public ICollection LoadPlugins(string path, bool saveToZip) // try to load from a zip as well if plugins are installed in both places. var zippath = $"{path}.zip"; - List plugins = new(); - List contexts = new(); + List plugins = []; + List contexts = []; // handle when path points to a zip file. if (Directory.Exists(path) || File.Exists(zippath)) @@ -96,7 +96,7 @@ public ICollection LoadPlugins(string path, bool saveToZip) if (saveToZip && File.Exists(zippath)) { - Dictionary filesInZip = new(); + Dictionary filesInZip = []; using (var zipFile = ZipFile.OpenRead(zippath)) { foreach (var entry in zipFile.Entries) diff --git a/src/GenericPluginLoader/GenericPluginLoader/PluginLoadContext.cs b/src/GenericPluginLoader/GenericPluginLoader/PluginLoadContext.cs index 3eda147..23f1ae0 100644 --- a/src/GenericPluginLoader/GenericPluginLoader/PluginLoadContext.cs +++ b/src/GenericPluginLoader/GenericPluginLoader/PluginLoadContext.cs @@ -6,18 +6,11 @@ namespace Elskom.Generic.Libs; /// -internal sealed class PluginLoadContext : AssemblyLoadContext +/// The name of the load context. +/// The path the the plugins. +internal sealed class PluginLoadContext(string name, string pluginPath) : AssemblyLoadContext(name, true) { - private readonly AssemblyDependencyResolver resolver; - - /// - /// Initializes a new instance of the class. - /// - /// The name of the load context. - /// The path the the plugins. - public PluginLoadContext(string name, string pluginPath) - : base(name, true) - => this.resolver = new(pluginPath); + private readonly AssemblyDependencyResolver resolver = new(pluginPath); /// protected override Assembly? Load(AssemblyName assemblyName) diff --git a/src/GenericPluginLoader/GenericPluginLoader/RuntimeExtensions.cs b/src/GenericPluginLoader/GenericPluginLoader/RuntimeExtensions.cs index 65f5659..228fa66 100644 --- a/src/GenericPluginLoader/GenericPluginLoader/RuntimeExtensions.cs +++ b/src/GenericPluginLoader/GenericPluginLoader/RuntimeExtensions.cs @@ -9,7 +9,7 @@ internal static class RuntimeExtensions { public static List CreateInstancesFromInterface(this AssemblyLoadContext context, string dllFile, string pdbFile) { - List instances = new(); + List instances = []; try { var (asmBytes, pdbBytes) = OpenAssemblyFiles(dllFile, pdbFile); @@ -36,7 +36,7 @@ public static List CreateInstancesFromInterface(this AssemblyLoadContext c public static List CreateInstancesFromInterface(Assembly? assembly) { - List instances = new(); + List instances = []; if (assembly is not null) { try diff --git a/src/GitInformation/.editorconfig b/src/GitInformation/.editorconfig index 66bcf28..a82ff70 100644 --- a/src/GitInformation/.editorconfig +++ b/src/GitInformation/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -152,3 +153,6 @@ dotnet_diagnostic.S3903.severity = none # S1133: Do not forget to remove this deprecated code someday. dotnet_diagnostic.S1133.severity = none + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/GitInformation/GitInformation.cs b/src/GitInformation/GitInformation.cs index 8c44826..e605b1e 100644 --- a/src/GitInformation/GitInformation.cs +++ b/src/GitInformation/GitInformation.cs @@ -11,8 +11,8 @@ namespace Elskom.Generic.Libs; public class GitInformation { // This is the collection of instances this has. - private static readonly Dictionary AssemblyInstances = new(); - private static readonly HashSet AppliedAssemblies = new(); + private static readonly Dictionary AssemblyInstances = []; + private static readonly HashSet AppliedAssemblies = []; private GitInformation(string headdesc, string commit, string branchname) { diff --git a/src/MessageManager/.editorconfig b/src/MessageManager/.editorconfig index 1871448..02f67c9 100644 --- a/src/MessageManager/.editorconfig +++ b/src/MessageManager/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -146,3 +147,6 @@ csharp_preserve_single_line_statements = true # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/MessageManager/MessageManager/MessageManager.cs b/src/MessageManager/MessageManager/MessageManager.cs index 4e19a6a..f7009e5 100644 --- a/src/MessageManager/MessageManager/MessageManager.cs +++ b/src/MessageManager/MessageManager/MessageManager.cs @@ -53,7 +53,7 @@ public static int ShowInfo(string text, string caption, bool useNotifications) /// Indicates if this function should show notifications. /// A new DialogResult returned as an . public static int ShowWarning(string text, string caption, bool useNotifications) - => ShowCore(0, text, caption, 2, useNotifications, 0, 48); + => ShowCore(0, text, caption, 2, useNotifications, 0, 48); private static int ShowCore(int timeout, string text, string caption, int tipIcon, bool useNotifications, int messageBoxButtons, int messageBoxIcon) { diff --git a/src/MiniDump/.editorconfig b/src/MiniDump/.editorconfig index 3a3c6ca..cfcce3b 100644 --- a/src/MiniDump/.editorconfig +++ b/src/MiniDump/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -152,3 +153,6 @@ dotnet_diagnostic.CA1303.severity = warning # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/PluginFramework/.editorconfig b/src/PluginFramework/.editorconfig index 2374532..40a8058 100644 --- a/src/PluginFramework/.editorconfig +++ b/src/PluginFramework/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -152,3 +153,6 @@ dotnet_diagnostic.S3903.severity = none # S1135: Track uses of "TODO" tags dotnet_diagnostic.S1135.severity = suggestion + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/PluginUpdateCheck/.editorconfig b/src/PluginUpdateCheck/.editorconfig index 27d02fe..f081cb1 100644 --- a/src/PluginUpdateCheck/.editorconfig +++ b/src/PluginUpdateCheck/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -155,3 +156,6 @@ dotnet_diagnostic.CA1305.severity = warning # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/PluginUpdateCheck/PluginUpdateCheck/PluginUpdateCheck.cs b/src/PluginUpdateCheck/PluginUpdateCheck/PluginUpdateCheck.cs index 2f91327..619fe11 100644 --- a/src/PluginUpdateCheck/PluginUpdateCheck/PluginUpdateCheck.cs +++ b/src/PluginUpdateCheck/PluginUpdateCheck/PluginUpdateCheck.cs @@ -8,8 +8,9 @@ namespace Elskom.Generic.Libs; /// /// A generic plugin update checker. /// +/// The serviceprovider to use for this instance. [GenerateDispose(false)] -public sealed partial class PluginUpdateCheck +public sealed partial class PluginUpdateCheck(IServiceProvider serviceprovider) { private static readonly CompositeFormat PluginUpdateCheckShowMessageUpdateForPluginIsAvailible = CompositeFormat.Parse( Resources.PluginUpdateCheck_ShowMessage_Update_for_plugin_is_availible); @@ -23,17 +24,7 @@ public sealed partial class PluginUpdateCheck private static readonly CompositeFormat PluginUpdateCheckUninstallFailedToUninstallTheSelectedPluginReason = CompositeFormat.Parse( Resources.PluginUpdateCheck_Uninstall_Failed_to_uninstall_the_selected_plugin_Reason); - private readonly IServiceProvider serviceProvider; - - /// - /// Initializes a new instance of the class. - /// - /// The serviceprovider to use for this instance. - public PluginUpdateCheck(IServiceProvider serviceprovider) - { - this.serviceProvider = serviceprovider; - this.PluginUpdateDatas = new List(); - } + private readonly IServiceProvider serviceProvider = serviceprovider; /// /// Event that fires when a new message should show up. @@ -88,7 +79,7 @@ public bool ShowMessage /// Gets a list of instances representing the plugins that needs updating or are to be installed. /// [NullOnDispose] - public IList PluginUpdateDatas { get; private set; } + public IList PluginUpdateDatas { get; private set; } = []; /// /// Checks for plugin updates from the provided plugin source urls. @@ -125,7 +116,7 @@ public bool CheckForUpdates(string[] pluginURLs, IList pluginTypes) pluginURLs1[i] = $"{arg0}{arg1}"; } - this.PluginUrls ??= new List(); + this.PluginUrls ??= []; foreach (var pluginURL in pluginURLs1) { if (!this.PluginUrls.Contains(pluginURL)) @@ -313,16 +304,4 @@ public bool Uninstall(PluginUpdateData pluginUpdateData, bool saveToZip) return false; } - - [CallOnDispose] - private void ClearDownloadFiles() - { - foreach (var pluginUpdateData in this.PluginUpdateDatas) - { - pluginUpdateData.DownloadFiles.Clear(); - } - - this.PluginUpdateDatas.Clear(); - this.PluginUrls?.Clear(); - } } diff --git a/src/ReleasePackaging/.editorconfig b/src/ReleasePackaging/.editorconfig index a4f327c..6242e46 100644 --- a/src/ReleasePackaging/.editorconfig +++ b/src/ReleasePackaging/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -149,3 +150,6 @@ dotnet_diagnostic.CA1307.severity = warning # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/ReleasePackaging/ReleasePackaging/ReleasePackaging.cs b/src/ReleasePackaging/ReleasePackaging/ReleasePackaging.cs index 2046178..3fb4b29 100644 --- a/src/ReleasePackaging/ReleasePackaging/ReleasePackaging.cs +++ b/src/ReleasePackaging/ReleasePackaging/ReleasePackaging.cs @@ -11,10 +11,10 @@ namespace Elskom.Generic.Libs; public static class ReleasePackaging { private static List Extensions - => new() - { + => + [ "*.exe", "*.dll", "*.xml", "*.txt", "*.pdb", - }; + ]; /// /// Packages an application's Release build to a zip file. @@ -62,7 +62,7 @@ public static void PackageRelease(ReadOnlySpan args) private static List GetAllFilesWithExtensions(DirectoryInfo dinfo, List extensions) { - List fileInfos = new(); + List fileInfos = []; foreach (var extension in extensions) { var files = dinfo.GetFiles(extension).ToList(); diff --git a/src/SettingsFile/.editorconfig b/src/SettingsFile/.editorconfig index a4f327c..6242e46 100644 --- a/src/SettingsFile/.editorconfig +++ b/src/SettingsFile/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -149,3 +150,6 @@ dotnet_diagnostic.CA1307.severity = warning # S3903: Move '%s' into a named namespace. dotnet_diagnostic.S3903.severity = none + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/SettingsFile/SettingsFile/JsonSettings.cs b/src/SettingsFile/SettingsFile/JsonSettings.cs index 4a58ebc..9a0d4c2 100644 --- a/src/SettingsFile/SettingsFile/JsonSettings.cs +++ b/src/SettingsFile/SettingsFile/JsonSettings.cs @@ -110,7 +110,7 @@ public static string Serialize(JsonSettings value, JsonSerializerOptions? option : new() { ElsDir = string.Empty, - Sources = Array.Empty(), + Sources = [], SaveToZip = default, ShowTestMessages = default, UseNotifications = default, diff --git a/src/UnluacNET/.editorconfig b/src/UnluacNET/.editorconfig index dfe3b72..f2f37ae 100644 --- a/src/UnluacNET/.editorconfig +++ b/src/UnluacNET/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -179,3 +180,15 @@ dotnet_diagnostic.S1135.severity = suggestion # CA1812: Avoid uninstantiated internal classes dotnet_diagnostic.CA1812.severity = suggestion + +# CA1822: Mark members as static +dotnet_diagnostic.CA1822.severity = suggestion + +# IDE0010: Add missing cases +dotnet_diagnostic.IDE0010.severity = suggestion + +# IDE0072: Add missing cases +dotnet_diagnostic.IDE0072.severity = suggestion + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion diff --git a/src/UnluacNET/Decompile/Block/AlwaysLoop.cs b/src/UnluacNET/Decompile/Block/AlwaysLoop.cs index da4c928..86b1235 100644 --- a/src/UnluacNET/Decompile/Block/AlwaysLoop.cs +++ b/src/UnluacNET/Decompile/Block/AlwaysLoop.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class AlwaysLoop : Block +internal sealed class AlwaysLoop(LFunction function, int begin, int end) : Block(function, begin, end) { - private readonly List m_statements; - - public AlwaysLoop(LFunction function, int begin, int end) - : base(function, begin, end) - => this.m_statements = new(); + private readonly List m_statements = []; public override bool Breakable => true; diff --git a/src/UnluacNET/Decompile/Block/Block.cs b/src/UnluacNET/Decompile/Block/Block.cs index 660bfab..96fd252 100644 --- a/src/UnluacNET/Decompile/Block/Block.cs +++ b/src/UnluacNET/Decompile/Block/Block.cs @@ -5,18 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal abstract class Block : Statement, IComparable +internal abstract class Block(LFunction function, int begin, int end) : Statement, IComparable { - protected Block(LFunction function, int begin, int end) - { - this.Function = function; - this.Begin = begin; - this.End = end; - } - - public int Begin { get; set; } + public int Begin { get; set; } = begin; - public int End { get; set; } + public int End { get; set; } = end; public bool LoopRedirectAdjustment { get; set; } @@ -28,7 +21,7 @@ protected Block(LFunction function, int begin, int end) public abstract bool IsUnprotected { get; } - protected LFunction Function { get; } + protected LFunction Function { get; } = function; public static bool operator ==(Block left, Block right) => left is null ? right is null : left.Equals(right); diff --git a/src/UnluacNET/Decompile/Block/BooleanIndicator.cs b/src/UnluacNET/Decompile/Block/BooleanIndicator.cs index 55139bd..80e3d77 100644 --- a/src/UnluacNET/Decompile/Block/BooleanIndicator.cs +++ b/src/UnluacNET/Decompile/Block/BooleanIndicator.cs @@ -5,13 +5,8 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class BooleanIndicator : Block +internal sealed class BooleanIndicator(LFunction function, int line) : Block(function, line, line) { - public BooleanIndicator(LFunction function, int line) - : base(function, line, line) - { - } - public override bool Breakable => false; public override bool IsContainer => false; diff --git a/src/UnluacNET/Decompile/Block/Break.cs b/src/UnluacNET/Decompile/Block/Break.cs index f323951..9bd587e 100644 --- a/src/UnluacNET/Decompile/Block/Break.cs +++ b/src/UnluacNET/Decompile/Block/Break.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class Break : Block +internal sealed class Break(LFunction function, int line, int target) : Block(function, line, line) { - public Break(LFunction function, int line, int target) - : base(function, line, line) - => this.Target = target; - - public int Target { get; private set; } + public int Target { get; private set; } = target; public override bool Breakable => false; diff --git a/src/UnluacNET/Decompile/Block/CompareBlock.cs b/src/UnluacNET/Decompile/Block/CompareBlock.cs index 97cd3c0..4f8cab4 100644 --- a/src/UnluacNET/Decompile/Block/CompareBlock.cs +++ b/src/UnluacNET/Decompile/Block/CompareBlock.cs @@ -5,18 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class CompareBlock : Block +internal sealed class CompareBlock(LFunction function, int begin, int end, int target, Branch branch) : Block(function, begin, end) { - public CompareBlock(LFunction function, int begin, int end, int target, Branch branch) - : base(function, begin, end) - { - this.Target = target; - this.Branch = branch; - } - - public int Target { get; } + public int Target { get; } = target; - public Branch Branch { get; } + public Branch Branch { get; } = branch; public override bool Breakable => false; diff --git a/src/UnluacNET/Decompile/Block/DoEndBlock.cs b/src/UnluacNET/Decompile/Block/DoEndBlock.cs index f78f557..8509367 100644 --- a/src/UnluacNET/Decompile/Block/DoEndBlock.cs +++ b/src/UnluacNET/Decompile/Block/DoEndBlock.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class DoEndBlock : Block +internal sealed class DoEndBlock(LFunction function, int begin, int end) : Block(function, begin, end) { - private readonly List m_statements; - - public DoEndBlock(LFunction function, int begin, int end) - : base(function, begin, end) - => this.m_statements = new(end - begin + 1); + private readonly List m_statements = new(end - begin + 1); public override bool Breakable => false; diff --git a/src/UnluacNET/Decompile/Block/ElseEndBlock.cs b/src/UnluacNET/Decompile/Block/ElseEndBlock.cs index 3092950..0828657 100644 --- a/src/UnluacNET/Decompile/Block/ElseEndBlock.cs +++ b/src/UnluacNET/Decompile/Block/ElseEndBlock.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class ElseEndBlock : Block +internal sealed class ElseEndBlock(LFunction function, int begin, int end) : Block(function, begin, end) { - private readonly List m_statements; - - public ElseEndBlock(LFunction function, int begin, int end) - : base(function, begin, end) - => this.m_statements = new(end - begin + 1); + private readonly List m_statements = new(end - begin + 1); public IfThenElseBlock Partner { get; set; } diff --git a/src/UnluacNET/Decompile/Block/ForBlock.cs b/src/UnluacNET/Decompile/Block/ForBlock.cs index 95fb30a..0357828 100644 --- a/src/UnluacNET/Decompile/Block/ForBlock.cs +++ b/src/UnluacNET/Decompile/Block/ForBlock.cs @@ -5,19 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class ForBlock : Block +internal sealed class ForBlock(LFunction function, int begin, int end, int register, Registers r) : Block(function, begin, end) { - private readonly int m_register; - private readonly Registers m_r; - private readonly List m_statements; - - public ForBlock(LFunction function, int begin, int end, int register, Registers r) - : base(function, begin, end) - { - this.m_register = register; - this.m_r = r; - this.m_statements = new(end - begin + 1); - } + private readonly int m_register = register; + private readonly Registers m_r = r; + private readonly List m_statements = new(end - begin + 1); public override bool Breakable => true; diff --git a/src/UnluacNET/Decompile/Block/IfThenElseBlock.cs b/src/UnluacNET/Decompile/Block/IfThenElseBlock.cs index 3489cd6..e88102a 100644 --- a/src/UnluacNET/Decompile/Block/IfThenElseBlock.cs +++ b/src/UnluacNET/Decompile/Block/IfThenElseBlock.cs @@ -5,23 +5,13 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class IfThenElseBlock : Block +internal sealed class IfThenElseBlock(LFunction function, Branch branch, int loopback, bool emptyElse, Registers r) : Block(function, branch.Begin, branch.End) { - private readonly Branch m_branch; - private readonly int m_loopback; - private readonly Registers m_r; - private readonly List m_statements; - private readonly bool m_emptyElse; - - public IfThenElseBlock(LFunction function, Branch branch, int loopback, bool emptyElse, Registers r) - : base(function, branch.Begin, branch.End) - { - this.m_branch = branch; - this.m_loopback = loopback; - this.m_emptyElse = emptyElse; - this.m_r = r; - this.m_statements = new(branch.End - branch.Begin + 1); - } + private readonly Branch m_branch = branch; + private readonly int m_loopback = loopback; + private readonly Registers m_r = r; + private readonly List m_statements = new(branch.End - branch.Begin + 1); + private readonly bool m_emptyElse = emptyElse; public ElseEndBlock Partner { get; set; } diff --git a/src/UnluacNET/Decompile/Block/IfThenEndBlock.cs b/src/UnluacNET/Decompile/Block/IfThenEndBlock.cs index 6569739..cc62e46 100644 --- a/src/UnluacNET/Decompile/Block/IfThenEndBlock.cs +++ b/src/UnluacNET/Decompile/Block/IfThenEndBlock.cs @@ -5,27 +5,18 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class IfThenEndBlock : Block +internal sealed class IfThenEndBlock(LFunction function, Branch branch, Stack stack, Registers r) : Block(function, branch.Begin == branch.End ? branch.Begin - 1 : branch.Begin, branch.Begin == branch.End ? branch.Begin - 1 : branch.End) { - private readonly Branch m_branch; - private readonly Stack m_stack; - private readonly Registers m_r; - private readonly List m_statements; + private readonly Branch m_branch = branch; + private readonly Stack m_stack = stack; + private readonly Registers m_r = r; + private readonly List m_statements = new(branch.End - branch.Begin + 1); public IfThenEndBlock(LFunction function, Branch branch, Registers r) : this(function, branch, null, r) { } - public IfThenEndBlock(LFunction function, Branch branch, Stack stack, Registers r) - : base(function, branch.Begin == branch.End ? branch.Begin - 1 : branch.Begin, branch.Begin == branch.End ? branch.Begin - 1 : branch.End) - { - this.m_branch = branch; - this.m_stack = stack; - this.m_r = r; - this.m_statements = new(branch.End - branch.Begin + 1); - } - public override bool Breakable => false; public override bool IsContainer => true; diff --git a/src/UnluacNET/Decompile/Block/OuterBlock.cs b/src/UnluacNET/Decompile/Block/OuterBlock.cs index 54aa624..a14cd33 100644 --- a/src/UnluacNET/Decompile/Block/OuterBlock.cs +++ b/src/UnluacNET/Decompile/Block/OuterBlock.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class OuterBlock : Block +internal sealed class OuterBlock(LFunction function, int length) : Block(function, 0, length + 1) { - private readonly List m_statements; - - public OuterBlock(LFunction function, int length) - : base(function, 0, length + 1) - => this.m_statements = new(length); + private readonly List m_statements = new(length); public override bool Breakable => false; @@ -31,7 +27,7 @@ public override void Print(Output output) { /* extra return statement */ var last = this.m_statements.Count - 1; - if (last < 0 || !(this.m_statements[last] is Return)) + if (last < 0 || this.m_statements[last] is not Return) { throw new InvalidOperationException(this.m_statements[last].ToString()); } diff --git a/src/UnluacNET/Decompile/Block/RepeatBlock.cs b/src/UnluacNET/Decompile/Block/RepeatBlock.cs index b05e375..bdbc61a 100644 --- a/src/UnluacNET/Decompile/Block/RepeatBlock.cs +++ b/src/UnluacNET/Decompile/Block/RepeatBlock.cs @@ -5,19 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class RepeatBlock : Block +internal sealed class RepeatBlock(LFunction function, Branch branch, Registers r) : Block(function, branch.End, branch.Begin) { - private readonly Branch m_branch; - private readonly Registers m_r; - private readonly List m_statements; - - public RepeatBlock(LFunction function, Branch branch, Registers r) - : base(function, branch.End, branch.Begin) - { - this.m_branch = branch; - this.m_r = r; - this.m_statements = new(branch.Begin - branch.End + 1); - } + private readonly Branch m_branch = branch; + private readonly Registers m_r = r; + private readonly List m_statements = new(branch.Begin - branch.End + 1); public override bool Breakable => true; diff --git a/src/UnluacNET/Decompile/Block/TForBlock.cs b/src/UnluacNET/Decompile/Block/TForBlock.cs index 1c2eafe..63c3946 100644 --- a/src/UnluacNET/Decompile/Block/TForBlock.cs +++ b/src/UnluacNET/Decompile/Block/TForBlock.cs @@ -5,21 +5,12 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class TForBlock : Block +internal sealed class TForBlock(LFunction function, int begin, int end, int register, int length, Registers r) : Block(function, begin, end) { - private readonly int m_register; - private readonly int m_length; - private readonly Registers m_r; - private readonly List m_statements; - - public TForBlock(LFunction function, int begin, int end, int register, int length, Registers r) - : base(function, begin, end) - { - this.m_register = register; - this.m_length = length; - this.m_r = r; - this.m_statements = new(end - begin + 1); - } + private readonly int m_register = register; + private readonly int m_length = length; + private readonly Registers m_r = r; + private readonly List m_statements = new(end - begin + 1); public override bool Breakable => true; diff --git a/src/UnluacNET/Decompile/Block/WhileBlock.cs b/src/UnluacNET/Decompile/Block/WhileBlock.cs index 2e12d07..22a4917 100644 --- a/src/UnluacNET/Decompile/Block/WhileBlock.cs +++ b/src/UnluacNET/Decompile/Block/WhileBlock.cs @@ -5,21 +5,12 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class WhileBlock : Block +internal sealed class WhileBlock(LFunction function, Branch branch, int loopback, Registers registers) : Block(function, branch.Begin, branch.End) { - private readonly Branch m_branch; - private readonly int m_loopback; - private readonly Registers m_registers; - private readonly List m_statements; - - public WhileBlock(LFunction function, Branch branch, int loopback, Registers registers) - : base(function, branch.Begin, branch.End) - { - this.m_branch = branch; - this.m_loopback = loopback; - this.m_registers = registers; - this.m_statements = new(branch.End - branch.Begin + 1); - } + private readonly Branch m_branch = branch; + private readonly int m_loopback = loopback; + private readonly Registers m_registers = registers; + private readonly List m_statements = new(branch.End - branch.Begin + 1); public override int ScopeEnd => this.End - 2; diff --git a/src/UnluacNET/Decompile/Branch/AndBranch.cs b/src/UnluacNET/Decompile/Branch/AndBranch.cs index 50ed840..0102e54 100644 --- a/src/UnluacNET/Decompile/Branch/AndBranch.cs +++ b/src/UnluacNET/Decompile/Branch/AndBranch.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class AndBranch : Branch +internal sealed class AndBranch(Branch left, Branch right) : Branch(right.Line, right.Begin, right.End) { - private readonly Branch m_left; - private readonly Branch m_right; - - public AndBranch(Branch left, Branch right) - : base(right.Line, right.Begin, right.End) - { - this.m_left = left; - this.m_right = right; - } + private readonly Branch m_left = left; + private readonly Branch m_right = right; public override Expression AsExpression(Registers registers) => Expression.MakeAND(this.m_left.AsExpression(registers), this.m_right.AsExpression(registers)); diff --git a/src/UnluacNET/Decompile/Branch/AssignNode.cs b/src/UnluacNET/Decompile/Branch/AssignNode.cs index f254575..666d909 100644 --- a/src/UnluacNET/Decompile/Branch/AssignNode.cs +++ b/src/UnluacNET/Decompile/Branch/AssignNode.cs @@ -5,15 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class AssignNode : Branch +internal sealed class AssignNode(int line, int begin, int end) : Branch(line, begin, end) { private Expression m_expression; - public AssignNode(int line, int begin, int end) - : base(line, begin, end) - { - } - public override Expression AsExpression(Registers registers) => this.m_expression; diff --git a/src/UnluacNET/Decompile/Branch/Branch.cs b/src/UnluacNET/Decompile/Branch/Branch.cs index d8fd8fb..43d78ab 100644 --- a/src/UnluacNET/Decompile/Branch/Branch.cs +++ b/src/UnluacNET/Decompile/Branch/Branch.cs @@ -5,20 +5,13 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal abstract class Branch +internal abstract class Branch(int line, int begin, int end) { - protected Branch(int line, int begin, int end) - { - this.Line = line; - this.Begin = begin; - this.End = end; - } + public int Line { get; private set; } = line; - public int Line { get; private set; } + public int Begin { get; set; } = begin; - public int Begin { get; set; } - - public int End { get; set; } // Might be modified to undo redirect + public int End { get; set; } = end; public bool IsSet { get; set; } diff --git a/src/UnluacNET/Decompile/Branch/EQNode.cs b/src/UnluacNET/Decompile/Branch/EQNode.cs index 5d3e14f..680f5d3 100644 --- a/src/UnluacNET/Decompile/Branch/EQNode.cs +++ b/src/UnluacNET/Decompile/Branch/EQNode.cs @@ -5,19 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class EQNode : Branch +internal sealed class EQNode(int left, int right, bool invert, int line, int begin, int end) : Branch(line, begin, end) { - private readonly int m_left; - private readonly int m_right; - private readonly bool m_invert; - - public EQNode(int left, int right, bool invert, int line, int begin, int end) - : base(line, begin, end) - { - this.m_left = left; - this.m_right = right; - this.m_invert = invert; - } + private readonly int m_left = left; + private readonly int m_right = right; + private readonly bool m_invert = invert; public override Branch Invert() => new EQNode(this.m_left, this.m_right, !this.m_invert, this.Line, this.End, this.Begin); diff --git a/src/UnluacNET/Decompile/Branch/LENode.cs b/src/UnluacNET/Decompile/Branch/LENode.cs index 6982e35..52d644a 100644 --- a/src/UnluacNET/Decompile/Branch/LENode.cs +++ b/src/UnluacNET/Decompile/Branch/LENode.cs @@ -5,19 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LENode : Branch +internal sealed class LENode(int left, int right, bool invert, int line, int begin, int end) : Branch(line, begin, end) { - private readonly int m_left; - private readonly int m_right; - private readonly bool m_invert; - - public LENode(int left, int right, bool invert, int line, int begin, int end) - : base(line, begin, end) - { - this.m_left = left; - this.m_right = right; - this.m_invert = invert; - } + private readonly int m_left = left; + private readonly int m_right = right; + private readonly bool m_invert = invert; public override Expression AsExpression(Registers registers) { diff --git a/src/UnluacNET/Decompile/Branch/LTNode.cs b/src/UnluacNET/Decompile/Branch/LTNode.cs index 3399df0..1d7f32e 100644 --- a/src/UnluacNET/Decompile/Branch/LTNode.cs +++ b/src/UnluacNET/Decompile/Branch/LTNode.cs @@ -5,19 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LTNode : Branch +internal sealed class LTNode(int left, int right, bool invert, int line, int begin, int end) : Branch(line, begin, end) { - private readonly int m_left; - private readonly int m_right; - private readonly bool m_invert; - - public LTNode(int left, int right, bool invert, int line, int begin, int end) - : base(line, begin, end) - { - this.m_left = left; - this.m_right = right; - this.m_invert = invert; - } + private readonly int m_left = left; + private readonly int m_right = right; + private readonly bool m_invert = invert; public override Expression AsExpression(Registers registers) { diff --git a/src/UnluacNET/Decompile/Branch/NotBranch.cs b/src/UnluacNET/Decompile/Branch/NotBranch.cs index 06c0c39..e4543c5 100644 --- a/src/UnluacNET/Decompile/Branch/NotBranch.cs +++ b/src/UnluacNET/Decompile/Branch/NotBranch.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class NotBranch : Branch +internal sealed class NotBranch(Branch branch) : Branch(branch.Line, branch.Begin, branch.End) { - private readonly Branch m_branch; - - public NotBranch(Branch branch) - : base(branch.Line, branch.Begin, branch.End) - => this.m_branch = branch; + private readonly Branch m_branch = branch; public override Expression AsExpression(Registers registers) => Expression.MakeNOT(this.m_branch.AsExpression(registers)); diff --git a/src/UnluacNET/Decompile/Branch/OrBranch.cs b/src/UnluacNET/Decompile/Branch/OrBranch.cs index 171d687..3a70a45 100644 --- a/src/UnluacNET/Decompile/Branch/OrBranch.cs +++ b/src/UnluacNET/Decompile/Branch/OrBranch.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class OrBranch : Branch +internal sealed class OrBranch(Branch left, Branch right) : Branch(right.Line, right.Begin, right.End) { - private readonly Branch m_left; - private readonly Branch m_right; - - public OrBranch(Branch left, Branch right) - : base(right.Line, right.Begin, right.End) - { - this.m_left = left; - this.m_right = right; - } + private readonly Branch m_left = left; + private readonly Branch m_right = right; public override Expression AsExpression(Registers registers) => Expression.MakeOR(this.m_left.AsExpression(registers), this.m_right.AsExpression(registers)); diff --git a/src/UnluacNET/Decompile/Code.cs b/src/UnluacNET/Decompile/Code.cs index 26b26c8..477cfa9 100644 --- a/src/UnluacNET/Decompile/Code.cs +++ b/src/UnluacNET/Decompile/Code.cs @@ -5,7 +5,7 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class Code +internal sealed class Code(LFunction function) { /* ** Size and position of opcode arguments @@ -37,15 +37,8 @@ internal sealed class Code private static readonly int MASK_C = MASK1(SIZE_C, 0); private static readonly int MASK_Bx = MASK1(SIZE_Bx, 0); - private readonly OpcodeMap map; - private readonly int[] code; - - //----------------------------------------------------\\ - public Code(LFunction function) - { - this.code = function.Code; - this.map = function.Header.Version.GetOpcodeMap(); - } + private readonly OpcodeMap map = function.Header.Version.GetOpcodeMap(); + private readonly int[] code = function.Code; public static int GetOpCode(int codePoint) => (codePoint >> POS_OP) & MASK_OPCODE; diff --git a/src/UnluacNET/Decompile/Constant.cs b/src/UnluacNET/Decompile/Constant.cs index 9222e86..f54cad3 100644 --- a/src/UnluacNET/Decompile/Constant.cs +++ b/src/UnluacNET/Decompile/Constant.cs @@ -12,8 +12,7 @@ internal sealed class Constant public const int CONST_NUMBER = 2; public const int CONST_STRING = 3; private static readonly HashSet M_reservedWords = - new() - { + [ "and", "and", "break", @@ -36,7 +35,7 @@ internal sealed class Constant "true", "until", "while", - }; + ]; private readonly int m_type; private readonly bool m_bool; diff --git a/src/UnluacNET/Decompile/Decompiler.cs b/src/UnluacNET/Decompile/Decompiler.cs index e625caa..85af1ba 100644 --- a/src/UnluacNET/Decompile/Decompiler.cs +++ b/src/UnluacNET/Decompile/Decompiler.cs @@ -264,7 +264,7 @@ private Expression GetMoveIntoTargetValue(int line, int previous) private OuterBlock HandleBranches(bool first) { var oldBlocks = this.blocks; - this.blocks = new List(); + this.blocks = []; var l_outer = new OuterBlock(this.Function, this.length); this.blocks.Add(l_outer); var isBreak = new bool[this.length + 1]; diff --git a/src/UnluacNET/Decompile/Expression/BinaryExpression.cs b/src/UnluacNET/Decompile/Expression/BinaryExpression.cs index 81ff4b7..cb3826e 100644 --- a/src/UnluacNET/Decompile/Expression/BinaryExpression.cs +++ b/src/UnluacNET/Decompile/Expression/BinaryExpression.cs @@ -5,21 +5,12 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class BinaryExpression : Expression +internal sealed class BinaryExpression(string op, Expression left, Expression right, int precedence, int associativity) : Expression(precedence) { - private readonly string m_op; - private readonly Expression m_left; - private readonly Expression m_right; - private readonly int m_associativity; - - public BinaryExpression(string op, Expression left, Expression right, int precedence, int associativity) - : base(precedence) - { - this.m_op = op; - this.m_left = left; - this.m_right = right; - this.m_associativity = associativity; - } + private readonly string m_op = op; + private readonly Expression m_left = left; + private readonly Expression m_right = right; + private readonly int m_associativity = associativity; public override int ConstantIndex => Math.Max(this.m_left.ConstantIndex, this.m_right.ConstantIndex); diff --git a/src/UnluacNET/Decompile/Expression/ClosureExpression.cs b/src/UnluacNET/Decompile/Expression/ClosureExpression.cs index b9c7d81..6cabfb9 100644 --- a/src/UnluacNET/Decompile/Expression/ClosureExpression.cs +++ b/src/UnluacNET/Decompile/Expression/ClosureExpression.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class ClosureExpression : Expression +internal sealed class ClosureExpression(LFunction function, int upvalueLine) : Expression(PRECEDENCE_ATOMIC) { - private readonly LFunction m_function; - private readonly int m_upvalueLine; - - public ClosureExpression(LFunction function, int upvalueLine) - : base(PRECEDENCE_ATOMIC) - { - this.m_function = function; - this.m_upvalueLine = upvalueLine; - } + private readonly LFunction m_function = function; + private readonly int m_upvalueLine = upvalueLine; public override int ConstantIndex => -1; diff --git a/src/UnluacNET/Decompile/Expression/ConstantExpression.cs b/src/UnluacNET/Decompile/Expression/ConstantExpression.cs index 0e242f9..2508d17 100644 --- a/src/UnluacNET/Decompile/Expression/ConstantExpression.cs +++ b/src/UnluacNET/Decompile/Expression/ConstantExpression.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class ConstantExpression : Expression +internal sealed class ConstantExpression(Constant constant, int index) : Expression(PRECEDENCE_ATOMIC) { - private readonly Constant m_constant; - private readonly int m_index; - - public ConstantExpression(Constant constant, int index) - : base(PRECEDENCE_ATOMIC) - { - this.m_constant = constant; - this.m_index = index; - } + private readonly Constant m_constant = constant; + private readonly int m_index = index; public override int ConstantIndex => this.m_index; diff --git a/src/UnluacNET/Decompile/Expression/Expression.cs b/src/UnluacNET/Decompile/Expression/Expression.cs index fb6143e..2658b45 100644 --- a/src/UnluacNET/Decompile/Expression/Expression.cs +++ b/src/UnluacNET/Decompile/Expression/Expression.cs @@ -5,7 +5,7 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal abstract class Expression +internal abstract class Expression(int precedence) { public const int PRECEDENCE_OR = 1; public const int PRECEDENCE_AND = 2; @@ -21,9 +21,6 @@ internal abstract class Expression public const int ASSOCIATIVITY_RIGHT = 2; public static readonly Expression NIL = new ConstantExpression(new(LNil.NIL), -1); - protected Expression(int precedence) - => this.Precedence = precedence; - public abstract int ConstantIndex { get; } public virtual int ClosureUpvalueLine => throw new InvalidOperationException(); @@ -56,7 +53,7 @@ protected Expression(int precedence) public virtual bool IsNewEntryAllowed => false; - public int Precedence { get; private set; } + public int Precedence { get; private set; } = precedence; public static BinaryExpression MakeADD(Expression left, Expression right) => new("+", left, right, PRECEDENCE_ADD, ASSOCIATIVITY_LEFT); diff --git a/src/UnluacNET/Decompile/Expression/FunctionCall.cs b/src/UnluacNET/Decompile/Expression/FunctionCall.cs index 85b9ad5..613a7fa 100644 --- a/src/UnluacNET/Decompile/Expression/FunctionCall.cs +++ b/src/UnluacNET/Decompile/Expression/FunctionCall.cs @@ -5,19 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class FunctionCall : Expression +internal sealed class FunctionCall(Expression function, Expression[] arguments, bool multiple) : Expression(PRECEDENCE_ATOMIC) { - private readonly Expression m_function; - private readonly Expression[] m_arguments; - private readonly bool m_multiple; - - public FunctionCall(Expression function, Expression[] arguments, bool multiple) - : base(PRECEDENCE_ATOMIC) - { - this.m_function = function; - this.m_arguments = arguments; - this.m_multiple = multiple; - } + private readonly Expression m_function = function; + private readonly Expression[] m_arguments = arguments; + private readonly bool m_multiple = multiple; public override bool BeginsWithParen { diff --git a/src/UnluacNET/Decompile/Expression/GlobalExpression.cs b/src/UnluacNET/Decompile/Expression/GlobalExpression.cs index f2c3dbf..8b32e71 100644 --- a/src/UnluacNET/Decompile/Expression/GlobalExpression.cs +++ b/src/UnluacNET/Decompile/Expression/GlobalExpression.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class GlobalExpression : Expression +internal sealed class GlobalExpression(string name, int index) : Expression(PRECEDENCE_ATOMIC) { - private readonly string m_name; - private readonly int m_index; - - public GlobalExpression(string name, int index) - : base(PRECEDENCE_ATOMIC) - { - this.m_name = name; - this.m_index = index; - } + private readonly string m_name = name; + private readonly int m_index = index; public override int ConstantIndex => this.m_index; diff --git a/src/UnluacNET/Decompile/Expression/LocalVariable.cs b/src/UnluacNET/Decompile/Expression/LocalVariable.cs index 40a6a57..653e5c8 100644 --- a/src/UnluacNET/Decompile/Expression/LocalVariable.cs +++ b/src/UnluacNET/Decompile/Expression/LocalVariable.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LocalVariable : Expression +internal sealed class LocalVariable(Declaration decl) : Expression(PRECEDENCE_ATOMIC) { - public LocalVariable(Declaration decl) - : base(PRECEDENCE_ATOMIC) - => this.Declaration = decl; - - public Declaration Declaration { get; private set; } + public Declaration Declaration { get; private set; } = decl; public override int ConstantIndex => -1; diff --git a/src/UnluacNET/Decompile/Expression/TableLiteral.cs b/src/UnluacNET/Decompile/Expression/TableLiteral.cs index 14e7ab7..93a2425 100644 --- a/src/UnluacNET/Decompile/Expression/TableLiteral.cs +++ b/src/UnluacNET/Decompile/Expression/TableLiteral.cs @@ -141,23 +141,15 @@ private void PrintEntry(int index, Output output) } } - public sealed class Entry : IComparable + public sealed class Entry(Expression key, Expression value, bool isList, int timestamp) : IComparable { - public Entry(Expression key, Expression value, bool isList, int timestamp) - { - this.Key = key; - this.Value = value; - this.IsList = isList; - this.Timestamp = timestamp; - } - - public Expression Key { get; private set; } + public Expression Key { get; private set; } = key; - public Expression Value { get; private set; } + public Expression Value { get; private set; } = value; - public bool IsList { get; private set; } + public bool IsList { get; private set; } = isList; - public int Timestamp { get; private set; } + public int Timestamp { get; private set; } = timestamp; public static bool operator ==(Entry left, Entry right) => left is null ? right is null : left.Equals(right); diff --git a/src/UnluacNET/Decompile/Expression/TableReference.cs b/src/UnluacNET/Decompile/Expression/TableReference.cs index 22d84cb..52abfb3 100644 --- a/src/UnluacNET/Decompile/Expression/TableReference.cs +++ b/src/UnluacNET/Decompile/Expression/TableReference.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class TableReference : Expression +internal sealed class TableReference(Expression table, Expression index) : Expression(PRECEDENCE_ATOMIC) { - private readonly Expression m_table; - private readonly Expression m_index; - - public TableReference(Expression table, Expression index) - : base(PRECEDENCE_ATOMIC) - { - this.m_table = table; - this.m_index = index; - } + private readonly Expression m_table = table; + private readonly Expression m_index = index; public override int ConstantIndex => Math.Max(this.m_table.ConstantIndex, this.m_index.ConstantIndex); diff --git a/src/UnluacNET/Decompile/Expression/UnaryExpression.cs b/src/UnluacNET/Decompile/Expression/UnaryExpression.cs index ddc599f..37cb9a9 100644 --- a/src/UnluacNET/Decompile/Expression/UnaryExpression.cs +++ b/src/UnluacNET/Decompile/Expression/UnaryExpression.cs @@ -5,31 +5,24 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class UnaryExpression : Expression +internal sealed class UnaryExpression(string op, Expression expression, int precedence) : Expression(precedence) { - private readonly string m_op; - private readonly Expression m_expression; - - public UnaryExpression(string op, Expression expression, int precedence) - : base(precedence) - { - this.m_op = op; - this.m_expression = expression; - } + private readonly string m_op = op; + private readonly Expression m_expression = expression; public override int ConstantIndex => this.m_expression.ConstantIndex; public override void Print(Output output) { - var precedence = this.Precedence > this.m_expression.Precedence; + var isPrecedence = this.Precedence > this.m_expression.Precedence; output.Print(this.m_op); - if (precedence) + if (isPrecedence) { output.Print("("); } this.m_expression.Print(output); - if (precedence) + if (isPrecedence) { output.Print(")"); } diff --git a/src/UnluacNET/Decompile/Expression/UpvalueExpression.cs b/src/UnluacNET/Decompile/Expression/UpvalueExpression.cs index 364c4cc..5880666 100644 --- a/src/UnluacNET/Decompile/Expression/UpvalueExpression.cs +++ b/src/UnluacNET/Decompile/Expression/UpvalueExpression.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class UpvalueExpression : Expression +internal sealed class UpvalueExpression(string name) : Expression(PRECEDENCE_ATOMIC) { - private readonly string m_name; - - public UpvalueExpression(string name) - : base(PRECEDENCE_ATOMIC) - => this.m_name = name; + private readonly string m_name = name; public override int ConstantIndex => -1; diff --git a/src/UnluacNET/Decompile/Expression/Vararg.cs b/src/UnluacNET/Decompile/Expression/Vararg.cs index 6fbffd0..761c1f5 100644 --- a/src/UnluacNET/Decompile/Expression/Vararg.cs +++ b/src/UnluacNET/Decompile/Expression/Vararg.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class Vararg : Expression +internal sealed class Vararg(bool multiple) : Expression(PRECEDENCE_ATOMIC) { - private readonly bool m_multiple; - - public Vararg(bool multiple) - : base(PRECEDENCE_ATOMIC) - => this.m_multiple = multiple; + private readonly bool m_multiple = multiple; public override int ConstantIndex => -1; diff --git a/src/UnluacNET/Decompile/OpcodeMap.cs b/src/UnluacNET/Decompile/OpcodeMap.cs index 745888c..c4012de 100644 --- a/src/UnluacNET/Decompile/OpcodeMap.cs +++ b/src/UnluacNET/Decompile/OpcodeMap.cs @@ -5,69 +5,66 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class OpcodeMap +internal sealed class OpcodeMap(int version) { private readonly int[] luaP_opmodes = - { + [ /* T A B C mode opcode */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_MOVE */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgN, OpMode.iABx), /* OP_LOADK */ - opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_LOADBOOL */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_LOADNIL */ - opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_GETUPVAL */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgN, OpMode.iABx), /* OP_GETGLOBAL */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgK, OpMode.iABC), /* OP_GETTABLE */ - opmode(0, 0, OpArgMask.OpArgK, OpArgMask.OpArgN, OpMode.iABx), /* OP_SETGLOBAL */ - opmode(0, 0, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_SETUPVAL */ - opmode(0, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_SETTABLE */ - opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_NEWTABLE */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgK, OpMode.iABC), /* OP_SELF */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_ADD */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_SUB */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_MUL */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_DIV */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_MOD */ - opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_POW */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_UNM */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_NOT */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_LEN */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgR, OpMode.iABC), /* OP_CONCAT */ - opmode(0, 0, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iAsBx), /* OP_JMP */ - opmode(1, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_EQ */ - opmode(1, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_LT */ - opmode(1, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_LE */ - opmode(1, 1, OpArgMask.OpArgR, OpArgMask.OpArgU, OpMode.iABC), /* OP_TEST */ - opmode(1, 1, OpArgMask.OpArgR, OpArgMask.OpArgU, OpMode.iABC), /* OP_TESTSET */ - opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_CALL */ - opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_TAILCALL */ - opmode(0, 0, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_RETURN */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iAsBx), /* OP_FORLOOP */ - opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iAsBx), /* OP_FORPREP */ - opmode(1, 0, OpArgMask.OpArgN, OpArgMask.OpArgU, OpMode.iABC), /* OP_TFORLOOP */ - opmode(0, 0, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_SETLIST */ - opmode(0, 0, OpArgMask.OpArgN, OpArgMask.OpArgN, OpMode.iABC), /* OP_CLOSE */ - opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABx), /* OP_CLOSURE */ - opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_VARARG */ - }; + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_MOVE */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgN, OpMode.iABx), /* OP_LOADK */ + Opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_LOADBOOL */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_LOADNIL */ + Opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_GETUPVAL */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgN, OpMode.iABx), /* OP_GETGLOBAL */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgK, OpMode.iABC), /* OP_GETTABLE */ + Opmode(0, 0, OpArgMask.OpArgK, OpArgMask.OpArgN, OpMode.iABx), /* OP_SETGLOBAL */ + Opmode(0, 0, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_SETUPVAL */ + Opmode(0, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_SETTABLE */ + Opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_NEWTABLE */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgK, OpMode.iABC), /* OP_SELF */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_ADD */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_SUB */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_MUL */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_DIV */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_MOD */ + Opmode(0, 1, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_POW */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_UNM */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_NOT */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iABC), /* OP_LEN */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgR, OpMode.iABC), /* OP_CONCAT */ + Opmode(0, 0, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iAsBx), /* OP_JMP */ + Opmode(1, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_EQ */ + Opmode(1, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_LT */ + Opmode(1, 0, OpArgMask.OpArgK, OpArgMask.OpArgK, OpMode.iABC), /* OP_LE */ + Opmode(1, 1, OpArgMask.OpArgR, OpArgMask.OpArgU, OpMode.iABC), /* OP_TEST */ + Opmode(1, 1, OpArgMask.OpArgR, OpArgMask.OpArgU, OpMode.iABC), /* OP_TESTSET */ + Opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_CALL */ + Opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_TAILCALL */ + Opmode(0, 0, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_RETURN */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iAsBx), /* OP_FORLOOP */ + Opmode(0, 1, OpArgMask.OpArgR, OpArgMask.OpArgN, OpMode.iAsBx), /* OP_FORPREP */ + Opmode(1, 0, OpArgMask.OpArgN, OpArgMask.OpArgU, OpMode.iABC), /* OP_TFORLOOP */ + Opmode(0, 0, OpArgMask.OpArgU, OpArgMask.OpArgU, OpMode.iABC), /* OP_SETLIST */ + Opmode(0, 0, OpArgMask.OpArgN, OpArgMask.OpArgN, OpMode.iABC), /* OP_CLOSE */ + Opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABx), /* OP_CLOSURE */ + Opmode(0, 1, OpArgMask.OpArgU, OpArgMask.OpArgN, OpMode.iABC), /* OP_VARARG */ + ]; - private readonly Op[] m_map; - - public OpcodeMap(int version) - => this.m_map = version is 0x51 - ? new[] - { + private readonly Op[] m_map = version is 0x51 + ? + [ Op.MOVE, Op.LOADK, Op.LOADBOOL, Op.LOADNIL, Op.GETUPVAL, Op.GETGLOBAL, Op.GETTABLE, Op.SETGLOBAL, Op.SETUPVAL, Op.SETTABLE, Op.NEWTABLE, Op.SELF, Op.ADD, Op.SUB, Op.MUL, Op.DIV, Op.MOD, Op.POW, Op.UNM, Op.NOT, Op.LEN, Op.CONCAT, Op.JMP, Op.EQ, Op.LT, Op.LE, Op.TEST, Op.TESTSET, Op.CALL, Op.TAILCALL, Op.RETURN, Op.FORLOOP, Op.FORPREP, Op.TFORLOOP, Op.SETLIST, Op.CLOSE, Op.CLOSURE, Op.VARARG, - } - : new[] - { + ] + : + [ Op.MOVE, Op.LOADK, Op.LOADKX, Op.LOADBOOL, Op.LOADNIL, Op.GETUPVAL, Op.GETTABUP, Op.GETTABLE, Op.SETTABUP, Op.SETUPVAL, Op.SETTABLE, Op.NEWTABLE, Op.SELF, Op.ADD, Op.SUB, Op.MUL, Op.DIV, Op.MOD, Op.POW, Op.UNM, Op.NOT, Op.LEN, Op.CONCAT, Op.JMP, Op.EQ, Op.LT, Op.LE, Op.TEST, Op.TESTSET, Op.CALL, Op.TAILCALL, Op.RETURN, Op.FORLOOP, Op.FORPREP, Op.TFORCALL, Op.TFORLOOP, Op.SETLIST, Op.CLOSURE, Op.VARARG, Op.EXTRAARG, - }; + ]; public Op this[int opcode] => this.GetOp(opcode); @@ -99,6 +96,6 @@ public bool TestTMode(int m) ** bit 6: instruction set register A ** bit 7: operator is a test */ - private static int opmode(byte t, byte a, OpArgMask b, OpArgMask c, OpMode m) + private static int Opmode(byte t, byte a, OpArgMask b, OpArgMask c, OpMode m) => (t << 7) | (a << 6) | ((byte)b << 4) | ((byte)c << 2) | (byte)m; } diff --git a/src/UnluacNET/Decompile/Operation/CallOperation.cs b/src/UnluacNET/Decompile/Operation/CallOperation.cs index 4ee0bd7..641d261 100644 --- a/src/UnluacNET/Decompile/Operation/CallOperation.cs +++ b/src/UnluacNET/Decompile/Operation/CallOperation.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class CallOperation : Operation +internal sealed class CallOperation(int line, FunctionCall call) : Operation(line) { - private readonly FunctionCall m_call; - - public CallOperation(int line, FunctionCall call) - : base(line) - => this.m_call = call; + private readonly FunctionCall m_call = call; public override Statement Process(Registers r, Block block) => new FunctionCallStatement(this.m_call); diff --git a/src/UnluacNET/Decompile/Operation/GenericOperation.cs b/src/UnluacNET/Decompile/Operation/GenericOperation.cs index fd18335..6299ccb 100644 --- a/src/UnluacNET/Decompile/Operation/GenericOperation.cs +++ b/src/UnluacNET/Decompile/Operation/GenericOperation.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class GenericOperation : Operation +internal sealed class GenericOperation(int line, Statement statement) : Operation(line) { - private readonly Statement m_statement; - - public GenericOperation(int line, Statement statement) - : base(line) - => this.m_statement = statement; + private readonly Statement m_statement = statement; public override Statement Process(Registers r, Block block) => this.m_statement; diff --git a/src/UnluacNET/Decompile/Operation/GlobalSet.cs b/src/UnluacNET/Decompile/Operation/GlobalSet.cs index 7923d6e..a207ce8 100644 --- a/src/UnluacNET/Decompile/Operation/GlobalSet.cs +++ b/src/UnluacNET/Decompile/Operation/GlobalSet.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class GlobalSet : Operation +internal sealed class GlobalSet(int line, string global, Expression value) : Operation(line) { - private readonly string m_global; - private readonly Expression m_value; - - public GlobalSet(int line, string global, Expression value) - : base(line) - { - this.m_global = global; - this.m_value = value; - } + private readonly string m_global = global; + private readonly Expression m_value = value; public override Statement Process(Registers r, Block block) => new Assignment(new GlobalTarget(this.m_global), this.m_value); diff --git a/src/UnluacNET/Decompile/Operation/LambdaOperation.cs b/src/UnluacNET/Decompile/Operation/LambdaOperation.cs index 3776d2a..6c3276e 100644 --- a/src/UnluacNET/Decompile/Operation/LambdaOperation.cs +++ b/src/UnluacNET/Decompile/Operation/LambdaOperation.cs @@ -5,13 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LambdaOperation : Operation +internal sealed class LambdaOperation(int line, Func func) : Operation(line) { - private readonly Func m_func; - - public LambdaOperation(int line, Func func) - : base(line) - => this.m_func = func; + private readonly Func m_func = func; public override Statement Process(Registers r, Block block) => this.m_func.Invoke(r, block); diff --git a/src/UnluacNET/Decompile/Operation/Operation.cs b/src/UnluacNET/Decompile/Operation/Operation.cs index 54d2a80..a192c64 100644 --- a/src/UnluacNET/Decompile/Operation/Operation.cs +++ b/src/UnluacNET/Decompile/Operation/Operation.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal abstract class Operation +internal abstract class Operation(int line) { - protected Operation(int line) - => this.Line = line; - - public int Line { get; private set; } + public int Line { get; private set; } = line; public abstract Statement Process(Registers r, Block block); } diff --git a/src/UnluacNET/Decompile/Operation/RegisterSet.cs b/src/UnluacNET/Decompile/Operation/RegisterSet.cs index 60a234d..5de4579 100644 --- a/src/UnluacNET/Decompile/Operation/RegisterSet.cs +++ b/src/UnluacNET/Decompile/Operation/RegisterSet.cs @@ -5,18 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class RegisterSet : Operation +internal sealed class RegisterSet(int line, int register, Expression value) : Operation(line) { - public RegisterSet(int line, int register, Expression value) - : base(line) - { - this.Register = register; - this.Value = value; - } - - public int Register { get; private set; } + public int Register { get; private set; } = register; - public Expression Value { get; private set; } + public Expression Value { get; private set; } = value; public override Statement Process(Registers r, Block block) { diff --git a/src/UnluacNET/Decompile/Operation/ReturnOperation.cs b/src/UnluacNET/Decompile/Operation/ReturnOperation.cs index 616c422..51528b1 100644 --- a/src/UnluacNET/Decompile/Operation/ReturnOperation.cs +++ b/src/UnluacNET/Decompile/Operation/ReturnOperation.cs @@ -11,10 +11,10 @@ internal sealed class ReturnOperation : Operation public ReturnOperation(int line, Expression value) : base(line) - => this.m_values = new[] - { + => this.m_values = + [ value, - }; + ]; public ReturnOperation(int line, Expression[] values) : base(line) diff --git a/src/UnluacNET/Decompile/Operation/TableSet.cs b/src/UnluacNET/Decompile/Operation/TableSet.cs index 453afc2..8a80132 100644 --- a/src/UnluacNET/Decompile/Operation/TableSet.cs +++ b/src/UnluacNET/Decompile/Operation/TableSet.cs @@ -5,23 +5,13 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class TableSet : Operation +internal sealed class TableSet(int line, Expression table, Expression index, Expression value, bool isTable, int timestamp) : Operation(line) { - private readonly Expression m_table; - private readonly Expression m_index; - private readonly Expression m_value; - private readonly bool m_isTable; - private readonly int m_timestamp; - - public TableSet(int line, Expression table, Expression index, Expression value, bool isTable, int timestamp) - : base(line) - { - this.m_table = table; - this.m_index = index; - this.m_value = value; - this.m_isTable = isTable; - this.m_timestamp = timestamp; - } + private readonly Expression m_table = table; + private readonly Expression m_index = index; + private readonly Expression m_value = value; + private readonly bool m_isTable = isTable; + private readonly int m_timestamp = timestamp; public override Statement Process(Registers r, Block block) { diff --git a/src/UnluacNET/Decompile/Operation/UpvalueSet.cs b/src/UnluacNET/Decompile/Operation/UpvalueSet.cs index f7f3e68..424afa5 100644 --- a/src/UnluacNET/Decompile/Operation/UpvalueSet.cs +++ b/src/UnluacNET/Decompile/Operation/UpvalueSet.cs @@ -5,17 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class UpvalueSet : Operation +internal sealed class UpvalueSet(int line, string upvalue, Expression value) : Operation(line) { - private readonly UpvalueTarget m_target; - private readonly Expression m_value; - - public UpvalueSet(int line, string upvalue, Expression value) - : base(line) - { - this.m_target = new UpvalueTarget(upvalue); - this.m_value = value; - } + private readonly UpvalueTarget m_target = new(upvalue); + private readonly Expression m_value = value; public override Statement Process(Registers r, Block block) => new Assignment(this.m_target, this.m_value); diff --git a/src/UnluacNET/Decompile/Output.cs b/src/UnluacNET/Decompile/Output.cs index 25be411..333b9cc 100644 --- a/src/UnluacNET/Decompile/Output.cs +++ b/src/UnluacNET/Decompile/Output.cs @@ -5,18 +5,15 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class Output +internal sealed class Output(TextWriter writer) { - private readonly TextWriter m_writer; + private readonly TextWriter m_writer = writer; public Output() : this(Console.Out) { } - public Output(TextWriter writer) - => this.m_writer = writer; - public int IndentationLevel { get; set; } public int Position { get; private set; } diff --git a/src/UnluacNET/Decompile/Statement/Declare.cs b/src/UnluacNET/Decompile/Statement/Declare.cs index c97fc3f..d11d8c6 100644 --- a/src/UnluacNET/Decompile/Statement/Declare.cs +++ b/src/UnluacNET/Decompile/Statement/Declare.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class Declare : Statement +internal sealed class Declare(List decls) : Statement { - private readonly List m_decls; - - public Declare(List decls) - => this.m_decls = decls; + private readonly List m_decls = decls; public override void Print(Output output) { diff --git a/src/UnluacNET/Decompile/Statement/FunctionCallStatement.cs b/src/UnluacNET/Decompile/Statement/FunctionCallStatement.cs index 60e1cec..cb67c24 100644 --- a/src/UnluacNET/Decompile/Statement/FunctionCallStatement.cs +++ b/src/UnluacNET/Decompile/Statement/FunctionCallStatement.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class FunctionCallStatement : Statement +internal sealed class FunctionCallStatement(FunctionCall call) : Statement { - private readonly FunctionCall m_call; - - public FunctionCallStatement(FunctionCall call) - => this.m_call = call; + private readonly FunctionCall m_call = call; public override bool BeginsWithParen => this.m_call.BeginsWithParen; diff --git a/src/UnluacNET/Decompile/Statement/Return.cs b/src/UnluacNET/Decompile/Statement/Return.cs index 6f61e76..316ecee 100644 --- a/src/UnluacNET/Decompile/Statement/Return.cs +++ b/src/UnluacNET/Decompile/Statement/Return.cs @@ -10,13 +10,13 @@ internal sealed class Return : Statement private readonly Expression[] values; public Return() - => this.values = Array.Empty(); + => this.values = []; public Return(Expression value) - => this.values = new[] - { + => this.values = + [ value, - }; + ]; public Return(Expression[] values) => this.values = values; diff --git a/src/UnluacNET/Decompile/Target/GlobalTarget.cs b/src/UnluacNET/Decompile/Target/GlobalTarget.cs index ab23ed7..a58b515 100644 --- a/src/UnluacNET/Decompile/Target/GlobalTarget.cs +++ b/src/UnluacNET/Decompile/Target/GlobalTarget.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class GlobalTarget : Target +internal sealed class GlobalTarget(string name) : Target { - private readonly string m_name; - - public GlobalTarget(string name) - => this.m_name = name; + private readonly string m_name = name; public override void Print(Output output) => output.Print(this.m_name); diff --git a/src/UnluacNET/Decompile/Target/TableTarget.cs b/src/UnluacNET/Decompile/Target/TableTarget.cs index 7746839..4d06e05 100644 --- a/src/UnluacNET/Decompile/Target/TableTarget.cs +++ b/src/UnluacNET/Decompile/Target/TableTarget.cs @@ -5,16 +5,10 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class TableTarget : Target +internal sealed class TableTarget(Expression table, Expression index) : Target { - private readonly Expression m_table; - private readonly Expression m_index; - - public TableTarget(Expression table, Expression index) - { - this.m_table = table; - this.m_index = index; - } + private readonly Expression m_table = table; + private readonly Expression m_index = index; public override bool IsFunctionName => this.m_index.IsIdentifier && this.m_table.IsDotChain; diff --git a/src/UnluacNET/Decompile/Target/UpvalueTarget.cs b/src/UnluacNET/Decompile/Target/UpvalueTarget.cs index 21c51c4..dd7ca5e 100644 --- a/src/UnluacNET/Decompile/Target/UpvalueTarget.cs +++ b/src/UnluacNET/Decompile/Target/UpvalueTarget.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class UpvalueTarget : Target +internal sealed class UpvalueTarget(string name) : Target { - private readonly string m_name; - - public UpvalueTarget(string name) - => this.m_name = name; + private readonly string m_name = name; public override void Print(Output output) => output.Print(this.m_name); diff --git a/src/UnluacNET/Decompile/Target/VariableTarget.cs b/src/UnluacNET/Decompile/Target/VariableTarget.cs index 808ecbe..cc42726 100644 --- a/src/UnluacNET/Decompile/Target/VariableTarget.cs +++ b/src/UnluacNET/Decompile/Target/VariableTarget.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class VariableTarget : Target +internal sealed class VariableTarget(Declaration decl) : Target { - public VariableTarget(Declaration decl) - => this.Declaration = decl; - - public Declaration Declaration { get; private set; } + public Declaration Declaration { get; private set; } = decl; public override bool IsLocal => true; diff --git a/src/UnluacNET/Decompile/Upvalues.cs b/src/UnluacNET/Decompile/Upvalues.cs index 900df75..b35df23 100644 --- a/src/UnluacNET/Decompile/Upvalues.cs +++ b/src/UnluacNET/Decompile/Upvalues.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class Upvalues +internal sealed class Upvalues(LUpvalue[] upvalues) { - private readonly LUpvalue[] m_upvalues; - - public Upvalues(LUpvalue[] upvalues) - => this.m_upvalues = upvalues; + private readonly LUpvalue[] m_upvalues = upvalues; public string GetName(int idx) => idx < this.m_upvalues.Length && this.m_upvalues[idx].Name != null diff --git a/src/UnluacNET/LuaDecompileStream.cs b/src/UnluacNET/LuaDecompileStream.cs index d11a3f5..ede44b9 100644 --- a/src/UnluacNET/LuaDecompileStream.cs +++ b/src/UnluacNET/LuaDecompileStream.cs @@ -48,7 +48,7 @@ public LuaDecompileStream() /// public override bool CanRead - => false; + => !this.InputNoData; /// public override bool CanSeek @@ -56,7 +56,7 @@ public override bool CanSeek /// public override bool CanWrite - => false; + => this.InputNoData; /// public override long Length @@ -82,7 +82,7 @@ public override long Position /// A dummy count, set to 0 always. /// The amount of data bytes in the decompiled lua. public override int Read(byte[] buffer, int offset, int count) - => this.InputNoData switch + => !this.CanRead switch { true => throw new InvalidOperationException( "Read can only be used to decompile an lua file only if the backing stream contains the data to the lua file to decompile."), @@ -97,7 +97,7 @@ public override int Read(byte[] buffer, int offset, int count) /// . public override void Write(byte[] buffer, int offset, int count) { - if (!this.InputNoData) + if (!this.CanWrite) { throw new InvalidOperationException("Write can only be used to decompile an lua file only if the backing stream contains no data."); } diff --git a/src/UnluacNET/Parse/BHeader.cs b/src/UnluacNET/Parse/BHeader.cs index 33b8d75..790dab5 100644 --- a/src/UnluacNET/Parse/BHeader.cs +++ b/src/UnluacNET/Parse/BHeader.cs @@ -129,10 +129,10 @@ public BHeader(Stream stream) this.Function = this.Version.GetLFunctionType(); if (this.Version.HasHeaderTail) { - Span luacTail = stackalloc byte[] - { + Span luacTail = + [ 0x19, 0x93, 0x0D, 0x0A, 0x1A, 0x0A, - }; + ]; foreach (var t in luacTail) { if (stream.ReadByte() != t) diff --git a/src/UnluacNET/Parse/BIntegerType.cs b/src/UnluacNET/Parse/BIntegerType.cs index 983df86..fd7fab6 100644 --- a/src/UnluacNET/Parse/BIntegerType.cs +++ b/src/UnluacNET/Parse/BIntegerType.cs @@ -5,12 +5,9 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class BIntegerType : BObjectType +internal sealed class BIntegerType(int intSize) : BObjectType { - public BIntegerType(int intSize) - => this.IntSize = intSize; - - public int IntSize { get; } + public int IntSize { get; } = intSize; public override BInteger Parse(Stream stream, BHeader header) { diff --git a/src/UnluacNET/Parse/BList.cs b/src/UnluacNET/Parse/BList.cs index 9d8650d..49a239a 100644 --- a/src/UnluacNET/Parse/BList.cs +++ b/src/UnluacNET/Parse/BList.cs @@ -5,18 +5,12 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class BList : IBObject +internal sealed class BList(BInteger length, List values) : IBObject where T : IBObject { - private readonly List m_values; + private readonly List m_values = values; - public BList(BInteger length, List values) - { - this.Length = length; - this.m_values = values; - } - - public BInteger Length { get; private set; } + public BInteger Length { get; private set; } = length; public T this[int index] => this.m_values[index]; diff --git a/src/UnluacNET/Parse/BObjectType.cs b/src/UnluacNET/Parse/BObjectType.cs index 15cc196..a2a76cb 100644 --- a/src/UnluacNET/Parse/BObjectType.cs +++ b/src/UnluacNET/Parse/BObjectType.cs @@ -13,7 +13,7 @@ internal abstract class BObjectType : IBObject public BList ParseList(Stream stream, BHeader header) { var length = header.Integer.Parse(stream, header); - List values = new(); + List values = []; length.Iterate(() => { values.Add(this.Parse(stream, header)); diff --git a/src/UnluacNET/Parse/BSizeTType.cs b/src/UnluacNET/Parse/BSizeTType.cs index c83c07d..1b1c9bf 100644 --- a/src/UnluacNET/Parse/BSizeTType.cs +++ b/src/UnluacNET/Parse/BSizeTType.cs @@ -5,17 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class BSizeTType : BObjectType +internal sealed class BSizeTType(int sizeTSize) : BObjectType { - private readonly BIntegerType integerType; + private readonly BIntegerType integerType = new(sizeTSize); - public BSizeTType(int sizeTSize) - { - this.SizeTSize = sizeTSize; - this.integerType = new(sizeTSize); - } - - public int SizeTSize { get; } + public int SizeTSize { get; } = sizeTSize; public override BSizeT Parse(Stream stream, BHeader header) { diff --git a/src/UnluacNET/Parse/LDoubleNumber.cs b/src/UnluacNET/Parse/LDoubleNumber.cs index af07ef2..f00f3b2 100644 --- a/src/UnluacNET/Parse/LDoubleNumber.cs +++ b/src/UnluacNET/Parse/LDoubleNumber.cs @@ -5,17 +5,14 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LDoubleNumber : LNumber +internal sealed class LDoubleNumber(double number) : LNumber { - public LDoubleNumber(double number) - => this.Number = number; - - public double Number { get; } + public double Number { get; } = number; public override double Value => this.Number; public override bool Equals(object obj) - => obj is LDoubleNumber number ? this.Number == number.Number : base.Equals(obj); + => obj is LDoubleNumber lnumber ? this.Number == lnumber.Number : base.Equals(obj); public override int GetHashCode() => throw new NotImplementedException(); diff --git a/src/UnluacNET/Parse/LFloatNumber.cs b/src/UnluacNET/Parse/LFloatNumber.cs index ef3b365..f020bfd 100644 --- a/src/UnluacNET/Parse/LFloatNumber.cs +++ b/src/UnluacNET/Parse/LFloatNumber.cs @@ -5,17 +5,14 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LFloatNumber : LNumber +internal sealed class LFloatNumber(float number) : LNumber { - public LFloatNumber(float number) - => this.Number = number; - - public float Number { get; } + public float Number { get; } = number; public override double Value => this.Number; public override bool Equals(object obj) - => obj is LFloatNumber number ? this.Number == number.Number : base.Equals(obj); + => obj is LFloatNumber lnumber ? this.Number == lnumber.Number : base.Equals(obj); public override int GetHashCode() => throw new NotImplementedException(); diff --git a/src/UnluacNET/Parse/LFunction.cs b/src/UnluacNET/Parse/LFunction.cs index c7f2ffa..e530503 100644 --- a/src/UnluacNET/Parse/LFunction.cs +++ b/src/UnluacNET/Parse/LFunction.cs @@ -5,39 +5,25 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LFunction : IBObject +internal sealed class LFunction(BHeader header, int[] code, LLocal[] locals, LObject[] constants, LUpvalue[] upvalues, LFunction[] functions, int maximumStackSize, int numUpValues, int numParams, int vararg) : IBObject { - public LFunction(BHeader header, int[] code, LLocal[] locals, LObject[] constants, LUpvalue[] upvalues, LFunction[] functions, int maximumStackSize, int numUpValues, int numParams, int vararg) - { - this.Header = header; - this.Code = code; - this.Locals = locals; - this.Constants = constants; - this.UpValues = upvalues; - this.Functions = functions; - this.MaxStackSize = maximumStackSize; - this.NumUpValues = numUpValues; - this.NumParams = numParams; - this.VarArg = vararg; - } + public BHeader Header { get; set; } = header; - public BHeader Header { get; set; } + public int[] Code { get; set; } = code; - public int[] Code { get; set; } + public LLocal[] Locals { get; set; } = locals; - public LLocal[] Locals { get; set; } + public LObject[] Constants { get; set; } = constants; - public LObject[] Constants { get; set; } + public LUpvalue[] UpValues { get; set; } = upvalues; - public LUpvalue[] UpValues { get; set; } + public LFunction[] Functions { get; set; } = functions; - public LFunction[] Functions { get; set; } + public int MaxStackSize { get; set; } = maximumStackSize; - public int MaxStackSize { get; set; } + public int NumUpValues { get; set; } = numUpValues; - public int NumUpValues { get; set; } + public int NumParams { get; set; } = numParams; - public int NumParams { get; set; } - - public int VarArg { get; set; } + public int VarArg { get; set; } = vararg; } diff --git a/src/UnluacNET/Parse/LIntNumber.cs b/src/UnluacNET/Parse/LIntNumber.cs index f8ba34e..b0aaec7 100644 --- a/src/UnluacNET/Parse/LIntNumber.cs +++ b/src/UnluacNET/Parse/LIntNumber.cs @@ -5,17 +5,14 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LIntNumber : LNumber +internal sealed class LIntNumber(int number) : LNumber { - public LIntNumber(int number) - => this.Number = number; - - public int Number { get; private set; } + public int Number { get; private set; } = number; public override double Value => this.Number; public override bool Equals(object obj) - => obj is LIntNumber number ? this.Number == number.Number : base.Equals(obj); + => obj is LIntNumber lnumber ? this.Number == lnumber.Number : base.Equals(obj); public override int GetHashCode() => throw new NotImplementedException(); diff --git a/src/UnluacNET/Parse/LLocal.cs b/src/UnluacNET/Parse/LLocal.cs index a86e715..3487618 100644 --- a/src/UnluacNET/Parse/LLocal.cs +++ b/src/UnluacNET/Parse/LLocal.cs @@ -5,20 +5,13 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LLocal : IBObject +internal sealed class LLocal(LString name, BInteger start, BInteger end) : IBObject { - public LLocal(LString name, BInteger start, BInteger end) - { - this.Name = name; - this.Start = start.AsInteger(); - this.End = end.AsInteger(); - } + public LString Name { get; private set; } = name; - public LString Name { get; private set; } + public int Start { get; private set; } = start.AsInteger(); - public int Start { get; private set; } - - public int End { get; private set; } + public int End { get; private set; } = end.AsInteger(); /* Used by the decompiler for annotation. */ internal bool ForLoop { get; set; } diff --git a/src/UnluacNET/Parse/LLongNumber.cs b/src/UnluacNET/Parse/LLongNumber.cs index 3722f72..f0ad2e2 100644 --- a/src/UnluacNET/Parse/LLongNumber.cs +++ b/src/UnluacNET/Parse/LLongNumber.cs @@ -5,17 +5,14 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LLongNumber : LNumber +internal sealed class LLongNumber(long number) : LNumber { - public LLongNumber(long number) - => this.Number = number; - - public long Number { get; private set; } + public long Number { get; private set; } = number; public override double Value => this.Number; public override bool Equals(object obj) - => obj is LLongNumber number ? this.Number == number.Number : base.Equals(obj); + => obj is LLongNumber lnumber ? this.Number == lnumber.Number : base.Equals(obj); public override int GetHashCode() => throw new NotImplementedException(); diff --git a/src/UnluacNET/Parse/LString.cs b/src/UnluacNET/Parse/LString.cs index 9a38778..c22a692 100644 --- a/src/UnluacNET/Parse/LString.cs +++ b/src/UnluacNET/Parse/LString.cs @@ -5,17 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -internal sealed class LString : LObject +internal sealed class LString(BSizeT size, string value) : LObject { - public LString(BSizeT size, string value) - { - this.Size = size; - this.Value = value.Length is 0 ? string.Empty : value.AsSpan().Slice(0, value.Length - 1).ToString(); - } + public BSizeT Size { get; } = size; - public BSizeT Size { get; } - - public string Value { get; } + public string Value { get; } = value.Length is 0 ? string.Empty : value.AsSpan().Slice(0, value.Length - 1).ToString(); public override string DeRef() => this.Value; diff --git a/src/ZipAssembly/.editorconfig b/src/ZipAssembly/.editorconfig index 877dbcf..da37149 100644 --- a/src/ZipAssembly/.editorconfig +++ b/src/ZipAssembly/.editorconfig @@ -88,6 +88,7 @@ csharp_preferred_modifier_order = public,private,protected,internal,static,exter # Code-block preferences csharp_prefer_braces = true:warning +csharp_style_namespace_declarations = file_scoped # Expression-level preferences csharp_prefer_simple_default_expression = true:warning @@ -155,3 +156,6 @@ dotnet_diagnostic.S3903.severity = none # S1133: Do not forget to remove this deprecated code someday. dotnet_diagnostic.S1133.severity = suggestion + +#Remove unnecessary usings/imports +dotnet_diagnostic.IDE0005.severity = suggestion