From 678ab19019df4c2b3d90126964b18d4a8dcd9c67 Mon Sep 17 00:00:00 2001 From: Etienne Baudoux Date: Thu, 25 Jan 2024 18:40:42 -0800 Subject: [PATCH] Addressed tons of warnings, mostly related to lack of documentation in code. --- .../DevToys.Api/Core/DictionaryExtensions.cs | 8 +++ src/app/dev/DevToys.Api/Core/IFileStorage.cs | 1 - .../dev/DevToys.Api/Core/LoggingExtensions.cs | 8 +++ .../Core/ObservableCollectionExtensions.cs | 8 ++- .../dev/DevToys.Api/Core/OneOfExtensions.cs | 37 +++++++++++- .../DevToys.Api/Core/SandboxedFileReader.cs | 26 +++++++- .../DevToys.Api/Core/Threading/AsyncLazy.cs | 59 ++++++++++++++++--- .../Core/Threading/DisposableSemaphore.cs | 23 +++++++- .../Core/Threading/TaskExtensions.cs | 12 ++++ .../Core/Threading/TaskSchedulerAwaiter.cs | 9 ++- src/app/dev/DevToys.Api/IDataGridRow.cs | 4 ++ .../Settings/SettingChangedEventArgs.cs | 5 ++ .../DevToys.Api/Settings/SettingDefinition.cs | 30 +++++++++- .../Tool/CLI/ConsoleProgressBar.cs | 5 ++ .../DevToys.Api/Tool/CLI/ICommandLineTool.cs | 2 +- .../dev/DevToys.Api/Tool/FontDefinition.cs | 17 ++++++ .../Tool/GUI/Components/IUIButton.cs | 21 +++++++ .../Tool/GUI/Components/IUICard.cs | 6 +- .../Tool/GUI/Components/IUIDataGrid.cs | 4 +- .../Tool/GUI/Components/IUIDiffTextInput.cs | 4 +- .../Tool/GUI/Components/IUIImageViewer.cs | 31 ++++++++-- .../GUI/Components/IUIMultiLineTextInput.cs | 4 +- .../Tool/GUI/Components/IUINumberInput.cs | 8 ++- .../Tool/GUI/Components/IUIProgressBar.cs | 14 +++++ .../Tool/GUI/Components/IUISetting.cs | 46 +++++++++++++-- .../Tool/GUI/Components/IUISettingGroup.cs | 43 +++++++++++--- .../Tool/GUI/Components/UIDialog.cs | 38 ++++++++++++ .../Tool/GUI/Components/UIGridLength.cs | 7 +++ .../Tool/GUI/Components/UIGridUnitType.cs | 3 + .../GUI/Components/UIHighlightedTextSpan.cs | 14 +++++ .../Components/UIHighlightedTextSpanColor.cs | 30 ++++++++++ .../Tool/GUI/Components/UIInfoBarSeverity.cs | 18 ++++++ .../Tool/GUI/Components/UILabelStyle.cs | 34 +++++++++++ .../Tool/GUI/Components/UIToolView.cs | 16 ++++- src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs | 2 +- .../GUI/PredefinedCommonToolGroupNames.cs | 30 ++++++++++ .../GUI/PredefinedSupportedImageFormats.cs | 3 + .../AcceptedDataTypeNameAttribute.cs | 7 +++ .../Attributes/CommandLineOptionAttribute.cs | 4 +- .../Attributes/DataTypeNameAttribute.cs | 11 ++++ .../Tool/Metadata/Attributes/MenuPlacement.cs | 10 ++++ .../Attributes/MenuPlacementAttribute.cs | 7 +++ .../Tool/Metadata/Attributes/NameAttribute.cs | 7 +++ .../NoCompactOverlaySupportAttribute.cs | 3 + .../Attributes/NotFavorableAttribute.cs | 3 + .../Attributes/NotSearchableAttribute.cs | 3 + .../Tool/Metadata/Attributes/Platform.cs | 20 ++++++- .../Attributes/TargetPlatformAttribute.cs | 7 +++ .../Metadata/Metadata/IOrderableMetadata.cs | 12 ++++ .../SmartDetection/DataDetectionResult.cs | 23 +++++++- .../Tool/SmartDetection/IDataTypeDetector.cs | 3 +- .../PredefinedCommonDataTypeNames.cs | 58 ++++++++++++++++++ .../ExtensionsManagerGuiTool.cs | 2 +- .../BasicInput/ComboBox/ComboBox.razor.cs | 4 +- .../DropDownButton/DropDownButton.razor.cs | 6 +- .../Menu/ContextMenu/ContextMenu.razor.cs | 2 +- .../Text/MonacoEditor/MonacoEditorHelper.cs | 18 +++--- .../RicherMonacoEditorDiffBase.cs | 12 ++-- .../UIElements/UITextInputWrapper.razor.cs | 2 +- .../Converters/PolymorphicConverterFactory.cs | 2 +- .../DevToys.Core/Debugger/DebuggerHelper.cs | 2 +- .../Core => DevToys.Core}/ExtensionOrderer.cs | 24 ++++++-- .../Mef/RecursiveDirectoryCatalog.cs | 11 ---- src/app/dev/DevToys.Core/OSHelper.cs | 2 +- .../Tools/SmartDetectionService.cs | 6 +- .../dev/DevToys.Tools/Helpers/Base64Helper.cs | 2 - .../Helpers/Core/CryptoRandom.cs | 9 +-- .../dev/DevToys.Tools/Helpers/JsonHelper.cs | 2 +- .../Helpers/LoremIpsum/LipsumGenerator.cs | 6 +- .../dev/DevToys.Tools/Helpers/XmlHelper.cs | 2 +- .../dev/DevToys.Tools/Helpers/XsdHelper.cs | 6 +- .../dev/DevToys.Tools/Helpers/YamlHelper.cs | 2 +- .../SmartDetection/DateDataTypeDetector.cs | 3 +- .../JsonArrayDataTypeDetector.cs | 8 --- .../Converters/Date/DateConverterGuiTool.cs | 2 +- .../Formatters/Json/JsonFormatterGuiTool.cs | 2 +- .../HashAndChecksumGeneratorGuiTool.cs | 2 +- .../EscapeUnescape/EscapeUnescapeGuiTool.cs | 1 - .../OptionToICommandLineToolMap.cs | 2 +- .../Api/Core/ObservableHashSetTests.cs | 52 ++++++++-------- .../Blazor/Core/Helpers/CssBuilderTests.cs | 10 ++-- .../{Api => }/Core/ExtensionOrdererTests.cs | 4 +- .../Mocks/MockIFileStorage.cs | 2 +- .../DateConverterCommandLineToolTests.cs | 1 - .../Helpers/PasswordGeneratorHelperTests.cs | 2 +- .../Tools/Helpers/UuidHelperTests.cs | 4 +- 86 files changed, 857 insertions(+), 168 deletions(-) rename src/app/dev/{DevToys.Api/Core => DevToys.Core}/ExtensionOrderer.cs (78%) rename src/app/tests/DevToys.UnitTests/{Api => }/Core/ExtensionOrdererTests.cs (98%) diff --git a/src/app/dev/DevToys.Api/Core/DictionaryExtensions.cs b/src/app/dev/DevToys.Api/Core/DictionaryExtensions.cs index 7e22950ae4..59e92b4cb5 100644 --- a/src/app/dev/DevToys.Api/Core/DictionaryExtensions.cs +++ b/src/app/dev/DevToys.Api/Core/DictionaryExtensions.cs @@ -1,10 +1,18 @@ namespace DevToys.Api; +/// +/// Provides extension methods for dictionaries. +/// public static class DictionaryExtensions { /// /// Gets the value at the given key, or a default value. /// + /// The type of the keys in the dictionary. + /// The type of the values in the dictionary. + /// The dictionary to retrieve the value from. + /// The key to retrieve the value for. + /// The value associated with the specified key, or the default value if the key is not found. public static TValue? GetValueOrDefault(this IDictionary dictionary, TKey key) { return dictionary.TryGetValue(key, out TValue? value) ? value : default; diff --git a/src/app/dev/DevToys.Api/Core/IFileStorage.cs b/src/app/dev/DevToys.Api/Core/IFileStorage.cs index 52e072c3fd..d4e9609027 100644 --- a/src/app/dev/DevToys.Api/Core/IFileStorage.cs +++ b/src/app/dev/DevToys.Api/Core/IFileStorage.cs @@ -69,7 +69,6 @@ public interface IFileStorage /// /// Creates a new temporary file in that will be deleted when the app stops, or the next time is starts. /// - /// /// (optional) The extension the temporary file should use. /// Returns information to the file. FileInfo CreateSelfDestroyingTempFile(string? desiredFileExtension = null); diff --git a/src/app/dev/DevToys.Api/Core/LoggingExtensions.cs b/src/app/dev/DevToys.Api/Core/LoggingExtensions.cs index 1a54b4edd9..829e348d52 100644 --- a/src/app/dev/DevToys.Api/Core/LoggingExtensions.cs +++ b/src/app/dev/DevToys.Api/Core/LoggingExtensions.cs @@ -2,6 +2,9 @@ namespace DevToys.Api; +/// +/// Provides extension methods for logging. +/// public static class LoggingExtensions { private static ILoggerFactory _loggerFactory = default!; @@ -22,12 +25,17 @@ public static ILoggerFactory LoggerFactory /// /// Creates an instance of for the specified type. /// + /// The type to create the logger for. + /// An instance of . public static ILogger Log(this Type forType) => LoggerFactory.CreateLogger(forType); /// /// Creates an instance of for the given object's type. /// + /// The type of the object. + /// The object instance. + /// An instance of . public static ILogger Log(this T instance) { Guard.IsNotNull(instance); diff --git a/src/app/dev/DevToys.Api/Core/ObservableCollectionExtensions.cs b/src/app/dev/DevToys.Api/Core/ObservableCollectionExtensions.cs index 312913f0fb..ee8dfe19cc 100644 --- a/src/app/dev/DevToys.Api/Core/ObservableCollectionExtensions.cs +++ b/src/app/dev/DevToys.Api/Core/ObservableCollectionExtensions.cs @@ -2,11 +2,17 @@ namespace DevToys.Api; +/// +/// Provides extension methods for . +/// public static class ObservableCollectionExtensions { /// - /// Adds the elements of the specified collection to the end of the ObservableCollection(Of T). + /// Adds the elements of the specified collection to the end of the . /// + /// The type of elements in the collection. + /// The to add elements to. + /// The collection whose elements should be added to the end of the . public static void AddRange(this ObservableCollection origin, IEnumerable newItems) { Guard.IsNotNull(origin); diff --git a/src/app/dev/DevToys.Api/Core/OneOfExtensions.cs b/src/app/dev/DevToys.Api/Core/OneOfExtensions.cs index d8c0f169bd..aa9e629ebc 100644 --- a/src/app/dev/DevToys.Api/Core/OneOfExtensions.cs +++ b/src/app/dev/DevToys.Api/Core/OneOfExtensions.cs @@ -2,8 +2,18 @@ namespace DevToys.Api; +/// +/// Extension methods for working with OneOf types. +/// public static class OneOfExtensions { + /// + /// Gets a stream asynchronously based on the input OneOf type. + /// + /// The input OneOf type. + /// The file storage implementation. + /// The cancellation token. + /// A task that represents the asynchronous operation. The task result contains the stream and a flag indicating if the stream was successfully retrieved. public static Task> GetStreamAsync( this OneOf input, IFileStorage fileStorage, @@ -17,6 +27,13 @@ public static Task> GetStreamAsync( return GetStreamAsync(OneOf.FromT1(input.AsT0), fileStorage, cancellationToken); } + /// + /// Gets a stream asynchronously based on the input OneOf type. + /// + /// The input OneOf type. + /// The file storage implementation. + /// The cancellation token. + /// A task that represents the asynchronous operation. The task result contains the stream and a flag indicating if the stream was successfully retrieved. public static async Task> GetStreamAsync( this OneOf input, IFileStorage fileStorage, @@ -24,14 +41,14 @@ public static async Task> GetStreamAsync( { return await input.Match( - async inputFile => + inputFile => { if (!fileStorage.FileExists(inputFile.FullName)) { - return new ResultInfo(Stream.Null, false); + return Task.FromResult(new ResultInfo(Stream.Null, false)); } - return new ResultInfo(fileStorage.OpenReadFile(inputFile.FullName), true); + return Task.FromResult(new ResultInfo(fileStorage.OpenReadFile(inputFile.FullName), true)); }, async inputString => { @@ -47,6 +64,13 @@ public static async Task> GetStreamAsync( }); } + /// + /// Reads all text asynchronously based on the input OneOf type. + /// + /// The input OneOf type. + /// The file storage implementation. + /// The cancellation token. + /// A task that represents the asynchronous operation. The task result contains the text content and a flag indicating if the content was successfully read. public static async Task> ReadAllTextAsync( this OneOf input, IFileStorage fileStorage, @@ -60,6 +84,13 @@ public static async Task> ReadAllTextAsync( return await ReadAllTextAsync(OneOf.FromT1(input.AsT0), fileStorage, cancellationToken); } + /// + /// Reads all text asynchronously based on the input OneOf type. + /// + /// The input OneOf type. + /// The file storage implementation. + /// The cancellation token. + /// A task that represents the asynchronous operation. The task result contains the text content and a flag indicating if the content was successfully read. public static async Task> ReadAllTextAsync( this OneOf input, IFileStorage fileStorage, diff --git a/src/app/dev/DevToys.Api/Core/SandboxedFileReader.cs b/src/app/dev/DevToys.Api/Core/SandboxedFileReader.cs index c737069358..b573143d21 100644 --- a/src/app/dev/DevToys.Api/Core/SandboxedFileReader.cs +++ b/src/app/dev/DevToys.Api/Core/SandboxedFileReader.cs @@ -11,12 +11,20 @@ [DebuggerDisplay($"FileName = {{{nameof(FileName)}}}")] public abstract class SandboxedFileReader : IDisposable { + /// + /// The buffer size used for reading the file in chunks. + /// public const int BufferSize = 4096; // 4 KB chunks private readonly DisposableSemaphore _semaphore = new(); private bool _disposed; private List? _fileAccesses; + /// + /// Creates a new instance of the class from a object. + /// + /// The object representing the file. + /// A new instance of the class. public static SandboxedFileReader FromFileInfo(FileInfo fileInfo) { Guard.IsNotNull(fileInfo); @@ -26,6 +34,7 @@ public static SandboxedFileReader FromFileInfo(FileInfo fileInfo) /// /// Initializes a new instance of the class. /// + /// The name of the file, including its extension. protected SandboxedFileReader(string fileName) { FileName = Path.GetFileName(fileName); @@ -41,8 +50,16 @@ protected SandboxedFileReader(string fileName) /// public event EventHandler? Disposed; + /// + /// Opens the file for reading asynchronously. + /// + /// The cancellation token. + /// A task representing the asynchronous operation. protected abstract ValueTask OpenReadFileAsync(CancellationToken cancellationToken); + /// + /// Disposes the and releases any resources used. + /// public void Dispose() { lock (_semaphore) @@ -56,11 +73,13 @@ public void Dispose() } /// - /// Get a new stream that can be used to read the file. The stream gets disposed automatically + /// Gets a new stream that can be used to read the file. The stream gets disposed automatically /// when the is disposed. /// /// In some cases, the returned stream is non-seekable. + /// The cancellation token. /// The has been disposed." + /// A task representing the asynchronous operation. public async Task GetNewAccessToFileContentAsync(CancellationToken cancellationToken) { using (await _semaphore.WaitAsync(cancellationToken)) @@ -78,8 +97,11 @@ public async Task GetNewAccessToFileContentAsync(CancellationToken cance } /// - /// Copy the content of the file to the given stream. + /// Copies the content of the file to the given stream. /// + /// The destination stream. + /// The cancellation token. + /// A representing the asynchronous operation. /// The has been disposed." public async Task CopyFileContentToAsync(Stream destinationStream, CancellationToken cancellationToken) { diff --git a/src/app/dev/DevToys.Api/Core/Threading/AsyncLazy.cs b/src/app/dev/DevToys.Api/Core/Threading/AsyncLazy.cs index a3b491777d..b7ff5b0af4 100644 --- a/src/app/dev/DevToys.Api/Core/Threading/AsyncLazy.cs +++ b/src/app/dev/DevToys.Api/Core/Threading/AsyncLazy.cs @@ -1,55 +1,98 @@ namespace DevToys.Api; +/// +/// Represents an asynchronous lazy initialization. +/// +/// The type of the value being lazily initialized. [DebuggerDisplay($"IsValueCreated = {{{nameof(IsValueCreated)}}}")] public class AsyncLazy { - private static Func> FromFuncT(Func valueFunc) - { - Guard.IsNotNull(valueFunc); - return () => Task.FromResult(valueFunc()); - } - private readonly Lazy> _innerLazy; - public bool IsValueCreated => _innerLazy.IsValueCreated && _innerLazy.Value.IsCompletedSuccessfully; - + /// + /// Creates a new instance of the class with the specified value. + /// + /// The value to initialize the instance with. public AsyncLazy(T value) { _innerLazy = new Lazy>(Task.FromResult(value)); } + /// + /// Creates a new instance of the class with the specified value factory. + /// + /// The delegate that represents the value factory. public AsyncLazy(Func valueFactory) { _innerLazy = new Lazy>(FromFuncT(valueFactory)); } + /// + /// Creates a new instance of the class with the specified value factory and thread safety option. + /// + /// The delegate that represents the value factory. + /// A boolean value indicating whether the lazy initialization is thread-safe. public AsyncLazy(Func valueFactory, bool isThreadSafe) { _innerLazy = new Lazy>(FromFuncT(valueFactory), isThreadSafe); } + /// + /// Creates a new instance of the class with the specified value factory and thread safety mode. + /// + /// The delegate that represents the value factory. + /// The thread safety mode for the lazy initialization. public AsyncLazy(Func valueFactory, LazyThreadSafetyMode mode) { _innerLazy = new Lazy>(FromFuncT(valueFactory), mode); } + /// + /// Creates a new instance of the class with the specified asynchronous value factory. + /// + /// The delegate that represents the asynchronous value factory. public AsyncLazy(Func> valueFactory) { _innerLazy = new Lazy>(valueFactory); } + /// + /// Creates a new instance of the class with the specified asynchronous value factory and thread safety option. + /// + /// The delegate that represents the asynchronous value factory. + /// A boolean value indicating whether the lazy initialization is thread-safe. public AsyncLazy(Func> valueFactory, bool isThreadSafe) { _innerLazy = new Lazy>(valueFactory, isThreadSafe); } + /// + /// Creates a new instance of the class with the specified asynchronous value factory and thread safety mode. + /// + /// The delegate that represents the asynchronous value factory. + /// The thread safety mode for the lazy initialization. public AsyncLazy(Func> valueFactory, LazyThreadSafetyMode mode) { _innerLazy = new Lazy>(valueFactory, mode); } + /// + /// Gets a task that represents the asynchronous initialization of the value. + /// + /// A task that represents the asynchronous initialization of the value. public Task GetValueAsync() { return IsValueCreated ? Task.FromResult(_innerLazy.Value.Result) : _innerLazy.Value; } + + /// + /// Determines whether the value has been created. + /// + public bool IsValueCreated => _innerLazy.IsValueCreated && _innerLazy.Value.IsCompletedSuccessfully; + + private static Func> FromFuncT(Func valueFunc) + { + Guard.IsNotNull(valueFunc); + return () => Task.FromResult(valueFunc()); + } } diff --git a/src/app/dev/DevToys.Api/Core/Threading/DisposableSemaphore.cs b/src/app/dev/DevToys.Api/Core/Threading/DisposableSemaphore.cs index b9aaac4a65..8d1509f394 100644 --- a/src/app/dev/DevToys.Api/Core/Threading/DisposableSemaphore.cs +++ b/src/app/dev/DevToys.Api/Core/Threading/DisposableSemaphore.cs @@ -1,7 +1,7 @@ namespace DevToys.Api; /// -/// Represents a semaphore that free other threads when disposing the result of the method.. +/// Represents a semaphore that free other threads when disposing the result of the method. /// [DebuggerDisplay($"IsBusy = {{{nameof(IsBusy)}}}, Disposed = {{{nameof(Disposed)}}}")] public sealed class DisposableSemaphore : IDisposable @@ -9,15 +9,28 @@ public sealed class DisposableSemaphore : IDisposable private readonly object _lockObject = new(); private readonly SemaphoreSlim _semaphore; + /// + /// Gets a value indicating whether the semaphore has been disposed. + /// public bool Disposed { get; private set; } + /// + /// Gets a value indicating whether the semaphore is currently busy. + /// public bool IsBusy => _semaphore.CurrentCount == 0; + /// + /// Initializes a new instance of the class. + /// + /// The maximum number of concurrent tasks that can be executed. public DisposableSemaphore(int maxTasksCount = 1) { _semaphore = new SemaphoreSlim(maxTasksCount, maxTasksCount); } + /// + /// Releases all resources used by the . + /// public void Dispose() { lock (_lockObject) @@ -30,6 +43,11 @@ public void Dispose() } } + /// + /// Asynchronously waits for the semaphore to be available. + /// + /// The cancellation token. + /// An object that should be disposed to release the semaphore. public async Task WaitAsync(CancellationToken cancellationToken) { await _semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); @@ -46,6 +64,9 @@ internal DummyDisposable(SemaphoreSlim semaphore) _semaphore = semaphore; } + /// + /// Releases the semaphore. + /// public void Dispose() { _semaphore.Release(); diff --git a/src/app/dev/DevToys.Api/Core/Threading/TaskExtensions.cs b/src/app/dev/DevToys.Api/Core/Threading/TaskExtensions.cs index 3f4918d4f8..0b6c24c1b9 100644 --- a/src/app/dev/DevToys.Api/Core/Threading/TaskExtensions.cs +++ b/src/app/dev/DevToys.Api/Core/Threading/TaskExtensions.cs @@ -8,6 +8,7 @@ public static class TaskExtensions /// /// Runs a task without waiting for its result. /// + /// The task to run. public static void Forget(this Task _) { } @@ -15,6 +16,8 @@ public static void Forget(this Task _) /// /// Runs a task without waiting for its result. /// + /// The type of the task result. + /// The task to run. public static void Forget(this Task _) { } @@ -22,6 +25,7 @@ public static void Forget(this Task _) /// /// Runs a task without waiting for its result. /// + /// The task to run. public static void Forget(this ValueTask _) { } @@ -29,6 +33,8 @@ public static void Forget(this ValueTask _) /// /// Runs a task without waiting for its result. /// + /// The type of the task result. + /// The task to run. public static void Forget(this ValueTask _) { } @@ -36,6 +42,7 @@ public static void Forget(this ValueTask _) /// /// Runs a task without waiting for its result. Swallows or handle any exception caused by the task. /// + /// The task to run. /// The action to run when an exception is caught. public static async void ForgetSafely(this Task task, Action? errorHandler = null) { @@ -52,6 +59,7 @@ public static async void ForgetSafely(this Task task, Action? errorHa /// /// Runs a task without waiting for its result. Swallows or handle any exception caused by the task. /// + /// The task to run. /// The action to run when an exception is caught. public static async void ForgetSafely(this ValueTask task, Action? errorHandler = null) { @@ -68,6 +76,7 @@ public static async void ForgetSafely(this ValueTask task, Action? er /// /// Gets the result of the task synchronously, on the current thread. /// + /// The task to complete. public static void CompleteOnCurrentThread(this Task task) { task.GetAwaiter().GetResult(); @@ -76,6 +85,9 @@ public static void CompleteOnCurrentThread(this Task task) /// /// Gets the result of the task synchronously, on the current thread. /// + /// The type of the task result. + /// The task to complete. + /// The result of the task. public static T CompleteOnCurrentThread(this Task task) { return task.GetAwaiter().GetResult(); diff --git a/src/app/dev/DevToys.Api/Core/Threading/TaskSchedulerAwaiter.cs b/src/app/dev/DevToys.Api/Core/Threading/TaskSchedulerAwaiter.cs index e38fd7fa4c..ca78a16687 100644 --- a/src/app/dev/DevToys.Api/Core/Threading/TaskSchedulerAwaiter.cs +++ b/src/app/dev/DevToys.Api/Core/Threading/TaskSchedulerAwaiter.cs @@ -3,10 +3,16 @@ namespace DevToys.Api; /// -/// An awaiter returned from . +/// An awaiter returned from . /// public readonly struct TaskSchedulerAwaiter : ICriticalNotifyCompletion { + /// + /// Switches the execution context off the main thread asynchronously. + /// + /// A to observe while waiting for the task to complete. + /// A configured to the appropriate . + /// The token has had cancellation requested. public static TaskSchedulerAwaiter SwitchOffMainThreadAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -32,6 +38,7 @@ public static TaskSchedulerAwaiter SwitchOffMainThreadAsync(CancellationToken ca /// Initializes a new instance of the struct. /// /// The scheduler for continuations. + /// A to observe while waiting for the task to complete. /// A value indicating whether the caller should yield even if /// already executing on the desired task scheduler. public TaskSchedulerAwaiter(TaskScheduler scheduler, CancellationToken cancellationToken, bool alwaysYield = false) diff --git a/src/app/dev/DevToys.Api/IDataGridRow.cs b/src/app/dev/DevToys.Api/IDataGridRow.cs index c9903b2009..95cc6430a9 100644 --- a/src/app/dev/DevToys.Api/IDataGridRow.cs +++ b/src/app/dev/DevToys.Api/IDataGridRow.cs @@ -1,5 +1,9 @@ namespace DevToys.Api; +/// +/// Represents a data grid row with optional detail information. +/// +/// The type of the detail information. public interface IDataGridRow where T : class { /// diff --git a/src/app/dev/DevToys.Api/Settings/SettingChangedEventArgs.cs b/src/app/dev/DevToys.Api/Settings/SettingChangedEventArgs.cs index 5015086cac..07c51e2b74 100644 --- a/src/app/dev/DevToys.Api/Settings/SettingChangedEventArgs.cs +++ b/src/app/dev/DevToys.Api/Settings/SettingChangedEventArgs.cs @@ -15,6 +15,11 @@ public sealed class SettingChangedEventArgs : EventArgs /// public object? NewValue { get; } + /// + /// Initializes a new instance of the class. + /// + /// The name of the setting that changed. + /// The new value of the setting. public SettingChangedEventArgs(string settingName, object? newValue) { SettingName = settingName; diff --git a/src/app/dev/DevToys.Api/Settings/SettingDefinition.cs b/src/app/dev/DevToys.Api/Settings/SettingDefinition.cs index 21db694919..d9721d08dc 100644 --- a/src/app/dev/DevToys.Api/Settings/SettingDefinition.cs +++ b/src/app/dev/DevToys.Api/Settings/SettingDefinition.cs @@ -18,7 +18,7 @@ public T DefaultValue { get; } /// - /// Initializes a new instance of the structure. + /// Initializes a new instance of the structure. /// /// The name of the setting. Should be unique. /// The default value of the setting. @@ -31,7 +31,7 @@ public SettingDefinition(string name, T defaultValue) // Come one! Make it shorter! ThrowHelper.ThrowArgumentOutOfRangeException(nameof(name), "Setting name is limited to 255 characters."); } - else if (name.Contains("=")) + else if (name.Contains('=')) { // For portable apps, settings are stored in a .ini file where the format is "setting_name=value". // Therefore, the setting name shouldn't contain "=". @@ -42,6 +42,11 @@ public SettingDefinition(string name, T defaultValue) DefaultValue = defaultValue; } + /// + /// Determines whether the specified object is equal to the current object. + /// + /// The object to compare with the current object. + /// true if the specified object is equal to the current object; otherwise, false. public override bool Equals(object? obj) { if (obj is SettingDefinition definition) @@ -52,6 +57,11 @@ public override bool Equals(object? obj) return false; } + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current ; otherwise, false. public bool Equals(SettingDefinition other) { return string.Equals(other.Name, Name, StringComparison.Ordinal) @@ -59,17 +69,33 @@ public bool Equals(SettingDefinition other) && other.DefaultValue.Equals(DefaultValue); } + /// + /// Returns the hash code for this . + /// + /// A 32-bit signed integer hash code. public override int GetHashCode() { return (Name.GetHashCode() ^ 47) * (DefaultValue is null ? 13 : DefaultValue.GetHashCode() ^ 73); } + /// + /// Determines whether two specified objects have the same value. + /// + /// The first to compare. + /// The second to compare. + /// true if the value of left is the same as the value of right; otherwise, false. public static bool operator ==(SettingDefinition left, SettingDefinition right) { return left.Equals(right); } + /// + /// Determines whether two specified objects have different values. + /// + /// The first to compare. + /// The second to compare. + /// true if the value of left is different from the value of right; otherwise, false. public static bool operator !=(SettingDefinition left, SettingDefinition right) { return !(left == right); diff --git a/src/app/dev/DevToys.Api/Tool/CLI/ConsoleProgressBar.cs b/src/app/dev/DevToys.Api/Tool/CLI/ConsoleProgressBar.cs index 4a50cd9fca..ca2bbbc3ed 100644 --- a/src/app/dev/DevToys.Api/Tool/CLI/ConsoleProgressBar.cs +++ b/src/app/dev/DevToys.Api/Tool/CLI/ConsoleProgressBar.cs @@ -20,6 +20,9 @@ public class ConsoleProgressBar : IDisposable, IProgress private bool _disposed = false; private int _animationIndex = 0; + /// + /// Initializes a new instance of the class. + /// public ConsoleProgressBar() { _timer = new Timer(TimerHandler); @@ -33,6 +36,7 @@ public ConsoleProgressBar() } } + /// public void Dispose() { lock (_timer) @@ -44,6 +48,7 @@ public void Dispose() GC.SuppressFinalize(this); } + /// public void Report(double value) { Guard.IsBetweenOrEqualTo(value, 0, 100); diff --git a/src/app/dev/DevToys.Api/Tool/CLI/ICommandLineTool.cs b/src/app/dev/DevToys.Api/Tool/CLI/ICommandLineTool.cs index 18801c0575..9177365a9e 100644 --- a/src/app/dev/DevToys.Api/Tool/CLI/ICommandLineTool.cs +++ b/src/app/dev/DevToys.Api/Tool/CLI/ICommandLineTool.cs @@ -25,7 +25,7 @@ namespace DevToys.Api; /// [CommandLineOption(Name = "utf8", DescriptionResourceName = nameof(Strings.Utf8OptionDescription))] /// internal bool Utf8 { get; set; } = true; // Default value is true. /// -/// public ValueTask InvokeAsync(CancellationToken cancellationToken) +/// public ValueTask<int> InvokeAsync(CancellationToken cancellationToken) /// { /// // [...] /// return 0; // Exit code. diff --git a/src/app/dev/DevToys.Api/Tool/FontDefinition.cs b/src/app/dev/DevToys.Api/Tool/FontDefinition.cs index 515a40f5b3..6e91d6ba48 100644 --- a/src/app/dev/DevToys.Api/Tool/FontDefinition.cs +++ b/src/app/dev/DevToys.Api/Tool/FontDefinition.cs @@ -1,7 +1,15 @@ namespace DevToys.Api; +/// +/// Represents a font definition. +/// public sealed class FontDefinition : IDisposable { + /// + /// Initializes a new instance of the class. + /// + /// The font family. + /// The stream to read the font file. public FontDefinition(string fontFamily, Stream fontReader) { Guard.IsNotNullOrWhiteSpace(fontFamily); @@ -11,10 +19,19 @@ public FontDefinition(string fontFamily, Stream fontReader) FontReader = fontReader; } + /// + /// Gets the font family. + /// public string FontFamily { get; } + /// + /// Gets the stream to read the font file. + /// public Stream FontReader { get; } + /// + /// Disposes the font reader. + /// public void Dispose() { FontReader?.Dispose(); diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs index b3bca59b3e..1f0b52694c 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIButton.cs @@ -131,6 +131,7 @@ public static partial class GUI /// /// Create a component that represents a button, which reacts when clicking on it. /// + /// The created instance. public static IUIButton Button() { return Button(null); @@ -140,6 +141,7 @@ public static IUIButton Button() /// Create a component that represents a button, which reacts when clicking on it. /// /// An optional unique identifier for this UI element. + /// The created instance. public static IUIButton Button(string? id) { return new UIButton(id); @@ -158,6 +160,9 @@ public static IUIButton Button(string? id, string text) /// /// Sets the of the button. /// + /// The instance. + /// The text to display in the button. + /// The updated instance. public static IUIButton Text(this IUIButton element, string? text) { ((UIButton)element).Text = text; @@ -167,6 +172,9 @@ public static IUIButton Text(this IUIButton element, string? text) /// /// Sets the action to run when clicking on the button. /// + /// The instance. + /// The action to run when clicking on the button. + /// The updated instance. public static IUIButton OnClick(this IUIButton element, Func? actionOnClick) { ((UIButton)element).OnClickAction = actionOnClick; @@ -176,6 +184,9 @@ public static IUIButton OnClick(this IUIButton element, Func? actionO /// /// Sets the action to run when clicking on the button. /// + /// The instance. + /// The action to run when clicking on the button. + /// The updated instance. public static IUIButton OnClick(this IUIButton element, Action? actionOnClick) { ((UIButton)element).OnClickAction @@ -190,6 +201,8 @@ public static IUIButton OnClick(this IUIButton element, Action? actionOnClick) /// /// Sets the button to appear as accented. /// + /// The instance. + /// The updated instance. public static IUIButton AccentAppearance(this IUIButton element) { ((UIButton)element).IsAccent = true; @@ -199,6 +212,8 @@ public static IUIButton AccentAppearance(this IUIButton element) /// /// Sets the button to appear as a hyperlink. /// + /// The instance. + /// The updated instance. public static IUIButton HyperlinkAppearance(this IUIButton element) { ((UIButton)element).IsHyperlink = true; @@ -208,6 +223,8 @@ public static IUIButton HyperlinkAppearance(this IUIButton element) /// /// Sets the button to appear as neutral. /// + /// The instance. + /// The updated instance. public static IUIButton NeutralAppearance(this IUIButton element) { ((UIButton)element).IsAccent = false; @@ -217,6 +234,10 @@ public static IUIButton NeutralAppearance(this IUIButton element) /// /// Sets the icon of the button. /// + /// The instance. + /// The name of the font containing the icon. + /// The glyph corresponding to the icon in the . + /// The updated instance. public static IUIButton Icon(this IUIButton element, string fontName, char glyph) { var button = (UIButton)element; diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUICard.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUICard.cs index c53a461a51..e70e30e60a 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUICard.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUICard.cs @@ -1,6 +1,4 @@ -using System.Xml.Linq; - -namespace DevToys.Api; +namespace DevToys.Api; /// /// A component that represents a empty card and for the option value. @@ -23,7 +21,7 @@ internal UICard(string? id, IUIElement uiElement) UIElement = uiElement; } - public IUIElement UIElement { get; } + public IUIElement UIElement { get; } } public static partial class GUI diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDataGrid.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDataGrid.cs index 8072d1cf98..3d17daae0c 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDataGrid.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDataGrid.cs @@ -36,7 +36,7 @@ public interface IUIDataGrid : IUITitledElementWithChildren /// Gets whether the element can be expanded to take the size of the whole tool boundaries. Default is false. /// /// - /// When is false and that the element is in full screen mode, the element goes back to normal mode. + /// When is false and that the element is in full screen mode, the element goes back to normal mode. /// bool IsExtendableToFullScreen { get; } @@ -305,7 +305,7 @@ public static IUIDataGrid ForbidSelectItem(this IUIDataGrid element) /// Indicates that the control can be extended to take the size of the whole tool boundaries. /// /// - /// When is false and that the element is in full screen mode, the element goes back to normal mode. + /// When is false and that the element is in full screen mode, the element goes back to normal mode. /// public static IUIDataGrid Extendable(this IUIDataGrid element) { diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDiffTextInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDiffTextInput.cs index e8c2b32de7..c88496ebff 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDiffTextInput.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIDiffTextInput.cs @@ -27,7 +27,7 @@ public interface IUIDiffTextInput : IUISingleLineTextInput /// Gets whether the element can be expanded to take the size of the whole tool boundaries. /// /// - /// When is false and that the element is in full screen mode, the element goes back to normal mode. + /// When is false and that the element is in full screen mode, the element goes back to normal mode. /// bool IsExtendableToFullScreen { get; } @@ -153,7 +153,7 @@ public static IUIDiffTextInput SplitView(this IUIDiffTextInput element) /// Indicates that the control can be extended to take the size of the whole tool boundaries. /// /// - /// When is false and that the element is in full screen mode, the element goes back to normal mode. + /// When is false and that the element is in full screen mode, the element goes back to normal mode. /// public static IUIDiffTextInput Extendable(this IUIDiffTextInput element) { diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIImageViewer.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIImageViewer.cs index 82db13a5e5..f2f5fa36cc 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIImageViewer.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIImageViewer.cs @@ -43,6 +43,7 @@ internal UIImageViewer(string? id) internal bool DisposeAutomatically { get; set; } + /// public OneOf? ImageSource { get => _imageSource; @@ -57,15 +58,20 @@ internal set } } + /// public IReadOnlyDictionary> CustomActionPerFileExtensionOnSaving { get => _customActionPerFileExtensionOnSaving; internal set => SetPropertyValue(ref _customActionPerFileExtensionOnSaving, value, CustomActionPerFileExtensionOnSavingChanged); } + /// public event EventHandler? ImageSourceChanged; + + /// public event EventHandler? CustomActionPerFileExtensionOnSavingChanged; + /// public void Dispose() { if (ImageSource.HasValue && ImageSource.Value.Value is IDisposable disposable && DisposeAutomatically) @@ -81,6 +87,7 @@ public static partial class GUI /// A component that displays an image and allows the user to perform some read-only actions on it. /// By default, image viewer supports BMP, GIF, JPEG, PBM, PNG, TIFF, TGA, WEBP, SVG formats. /// + /// The created instance. public static IUIImageViewer ImageViewer() { return ImageViewer(id: null); @@ -91,6 +98,7 @@ public static IUIImageViewer ImageViewer() /// By default, image viewer supports BMP, GIF, JPEG, PBM, PNG, TIFF, TGA, WEBP, SVG formats. /// /// An optional unique identifier for this UI element. + /// The created instance. public static IUIImageViewer ImageViewer(string? id) { return new UIImageViewer(id); @@ -99,6 +107,9 @@ public static IUIImageViewer ImageViewer(string? id) /// /// Sets the from a . /// + /// The instance. + /// The representing the image file. + /// The updated instance. public static IUIImageViewer WithFile(this IUIImageViewer element, FileInfo imageFile) { ValidateFileExtension(imageFile.Name); @@ -109,8 +120,10 @@ public static IUIImageViewer WithFile(this IUIImageViewer element, FileInfo imag /// /// Sets the from a . /// - /// The file to display. - /// Indicates whether should be disposed when not displayed in the UI anymore. + /// The instance. + /// The representing the picked file. + /// Indicates whether the should be disposed when not displayed in the UI anymore. + /// The updated instance. public static IUIImageViewer WithPickedFile(this IUIImageViewer element, SandboxedFileReader pickedFile, bool disposeAutomatically) { ValidateFileExtension(pickedFile.FileName); @@ -123,8 +136,10 @@ public static IUIImageViewer WithPickedFile(this IUIImageViewer element, Sandbox /// /// Sets the from an . /// - /// The image to display - /// Indicates whether should be disposed when not displayed in the UI anymore. + /// The instance. + /// The to display. + /// Indicates whether the should be disposed when not displayed in the UI anymore. + /// The updated instance. public static IUIImageViewer WithImage(this IUIImageViewer element, Image image, bool disposeAutomatically) { var imageViewer = (UIImageViewer)element; @@ -141,8 +156,10 @@ public static IUIImageViewer WithImage(this IUIImageViewer element, Image image, /// When the user saves the image with the specified , the specified will be invoked /// with a pointing to the file to save. The is responsible for writing the image to the file. /// - /// The file extension to handle + /// The instance. + /// The file extension to handle. /// The action to perform when the user wishes to save the image with the given . + /// The updated instance. public static IUIImageViewer ManuallyHandleSaveAs(this IUIImageViewer element, string fileExtension, Func action) { fileExtension = "." + fileExtension.ToLowerInvariant().Trim().TrimStart('.'); @@ -159,7 +176,9 @@ public static IUIImageViewer ManuallyHandleSaveAs(this IUIImageViewer element, s /// /// Removes the custom action to perform when the user saves the image with a specific file extension. /// + /// The instance. /// The file extension to remove. + /// The updated instance. public static IUIImageViewer RemoveManuallyHandleSaveAs(this IUIImageViewer element, string fileExtension) { fileExtension = "." + fileExtension.ToLowerInvariant().Trim().TrimStart('.'); @@ -174,6 +193,8 @@ public static IUIImageViewer RemoveManuallyHandleSaveAs(this IUIImageViewer elem /// /// Clears the value of . /// + /// The instance. + /// The updated instance. public static IUIImageViewer Clear(this IUIImageViewer element) { ((UIImageViewer)element).ImageSource = default; diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultiLineTextInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultiLineTextInput.cs index fb25905f84..b0e7a866a3 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultiLineTextInput.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIMultiLineTextInput.cs @@ -19,7 +19,7 @@ public interface IUIMultiLineTextInput : IUISingleLineTextInput /// Gets whether the element can be expanded to take the size of the whole tool boundaries. Default is false. /// /// - /// When is false and that the element is in full screen mode, the element goes back to normal mode. + /// When is false and that the element is in full screen mode, the element goes back to normal mode. /// bool IsExtendableToFullScreen { get; } @@ -189,7 +189,7 @@ public static IUIMultiLineTextInput Language(this IUIMultiLineTextInput element, /// Indicates that the control can be extended to take the size of the whole tool boundaries. /// /// - /// When is false and that the element is in full screen mode, the element goes back to normal mode. + /// When is false and that the element is in full screen mode, the element goes back to normal mode. /// public static IUIMultiLineTextInput Extendable(this IUIMultiLineTextInput element) { diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUINumberInput.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUINumberInput.cs index 1ff416d67e..a4b05a7f5b 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUINumberInput.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUINumberInput.cs @@ -80,8 +80,12 @@ public double Value { get { - double.TryParse(Text, out double value); - return Math.Min(Math.Max(value, Min), Max); + if (double.TryParse(Text, out double value)) + { + return Math.Min(Math.Max(value, Min), Max); + } + + return Math.Min(Math.Max(0, Min), Max); } } diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIProgressBar.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIProgressBar.cs index 169ef33f3f..4a9f18cdcb 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIProgressBar.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUIProgressBar.cs @@ -47,22 +47,30 @@ internal UIProgressBar(string? id) TimeSpan.FromMilliseconds(10)); } + /// public double Value { get => _value; internal set => SetPropertyValue(ref _value, value, ValueChanged); } + /// public bool IsIndeterminate { get => _isIndeterminate; internal set => SetPropertyValue(ref _isIndeterminate, value, IsIndeterminateChanged); } + /// public event EventHandler? ValueChanged; + + /// public event EventHandler? ValueChangingAsynchronously; + + /// public event EventHandler? IsIndeterminateChanged; + /// public void Dispose() { _asyncProgressReporter.Flush(); @@ -85,6 +93,7 @@ public static partial class GUI /// /// Create a component that indicates the progress of an operation. /// + /// The created instance. public static IUIProgressBar ProgressBar() { return ProgressBar(null); @@ -94,6 +103,7 @@ public static IUIProgressBar ProgressBar() /// Create a component that indicates the progress of an operation. /// /// An optional unique identifier for this UI element. + /// The created instance. public static IUIProgressBar ProgressBar(string? id) { return new UIProgressBar(id); @@ -103,6 +113,7 @@ public static IUIProgressBar ProgressBar(string? id) /// Synchronously set the property. /// /// It is highly recommended to call this method when being on the UI thread. + /// The instance. /// A value between 0 and 100. public static T Progress(this T element, double percentage) where T : IUIProgressBar { @@ -119,6 +130,7 @@ public static T Progress(this T element, double percentage) where T : IUIProg /// progress bar's value without blocking the caller. /// /// It is highly recommended to call this method when being off the UI thread. + /// The instance. /// A value between 0 and 100. public static ValueTask ProgressAsync(this T element, double percentage) where T : IUIProgressBar { @@ -134,6 +146,7 @@ public static ValueTask ProgressAsync(this T element, double percentage) wher /// /// Indicates the progress bar should a generic, continuous progress feedback. /// + /// The instance. public static T StartIndeterminateProgress(this T element) where T : IUIProgressBar { if (element is UIProgressBar progressBar) @@ -147,6 +160,7 @@ public static T StartIndeterminateProgress(this T element) where T : IUIProgr /// /// Indicates the progress bar should show actual values. /// + /// The instance. public static T StopIndeterminateProgress(this T element) where T : IUIProgressBar { if (element is UIProgressBar progressBar) diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs index 4247d644ce..f4398fa832 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISetting.cs @@ -67,33 +67,44 @@ protected override IEnumerable GetChildren() } } + /// public string? Description { get => _description; internal set => SetPropertyValue(ref _description, value, DescriptionChanged); } + /// public string? StateDescription { get => _stateDescription; internal set => SetPropertyValue(ref _stateDescription, value, StateDescriptionChanged); } + /// public IUIIcon? Icon { get => _icon; internal set => SetPropertyValue(ref _icon, value, IconChanged); } + /// public IUIElement? InteractiveElement { get => _interactiveElement; internal set => SetPropertyValue(ref _interactiveElement, value, InteractiveElementChanged); } + /// public event EventHandler? DescriptionChanged; + + /// public event EventHandler? StateDescriptionChanged; + + /// public event EventHandler? IconChanged; + + /// public event EventHandler? InteractiveElementChanged; } @@ -102,6 +113,7 @@ public static partial class GUI /// /// A component that represents a setting, with a title, description, icon and for the option value. /// + /// The created instance. public static IUISetting Setting() { return Setting(null); @@ -111,6 +123,7 @@ public static IUISetting Setting() /// A component that represents a setting, with a title, description, icon and for the option value. /// /// An optional unique identifier for this UI element. + /// The created instance. public static IUISetting Setting(string? id) { return new UISetting(id); @@ -119,6 +132,9 @@ public static IUISetting Setting(string? id) /// /// Sets the of the setting. /// + /// The instance. + /// The description text. + /// The updated instance. public static IUISetting Description(this IUISetting element, string? text) { ((UISetting)element).Description = text; @@ -128,6 +144,9 @@ public static IUISetting Description(this IUISetting element, string? text) /// /// Sets the of the setting. /// + /// The instance. + /// The state description text. + /// The updated instance. public static IUISetting StateDescription(this IUISetting element, string? text) { ((UISetting)element).StateDescription = text; @@ -137,6 +156,10 @@ public static IUISetting StateDescription(this IUISetting element, string? text) /// /// Sets the of the setting. /// + /// The instance. + /// The font name of the icon. + /// The glyph of the icon. + /// The updated instance. public static IUISetting Icon(this IUISetting element, string fontName, char glyph) { ((UISetting)element).Icon = Icon(fontName, glyph); @@ -146,6 +169,9 @@ public static IUISetting Icon(this IUISetting element, string fontName, char gly /// /// Sets the of the setting. /// + /// The instance. + /// The interactive UI element. + /// The updated instance. public static IUISetting InteractiveElement(this IUISetting element, IUIElement? uiElement) { ((UISetting)element).InteractiveElement = uiElement; @@ -156,9 +182,11 @@ public static IUISetting InteractiveElement(this IUISetting element, IUIElement? /// Sets a to and automatically associate the /// given to the switch state. /// + /// The instance. /// The settings provider used for handling the given . - /// The definition of the setting to associate to this . - /// (optional) A method to invoke when the setting value changed. + /// The definition of the setting to associate with this . + /// (optional) A method to invoke when the setting value changes. + /// The updated instance. public static IUISetting Handle( this IUISetting element, ISettingsProvider settingsProvider, @@ -179,9 +207,11 @@ public static IUISetting Handle( /// Sets a to and automatically associate the /// given to the switch state. /// + /// The instance. /// The settings provider used for handling the given . - /// The definition of the setting to associate to this . - /// (optional) A method to invoke when the setting value changed. + /// The definition of the setting to associate with this . + /// (optional) A method to invoke when the setting value changes. + /// The updated instance. public static IUISetting Handle( this IUISetting element, ISettingsProvider settingsProvider, @@ -206,11 +236,13 @@ public static IUISetting Handle( /// Sets a to and automatically associate the /// given to the switch state. /// + /// The instance. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// The to use when the option is On. /// The to use when the option is Off. /// (optional) A method to invoke when the setting value changed. + /// The updated instance. public static IUISetting Handle( this IUISetting element, ISettingsProvider settingsProvider, @@ -233,11 +265,13 @@ public static IUISetting Handle( /// Sets a to and automatically associate the /// given to the switch state. /// + /// The instance. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// The to use when the option is On. /// The to use when the option is Off. /// (optional) A method to invoke when the setting value changed. + /// The updated instance. public static IUISetting Handle( this IUISetting element, ISettingsProvider settingsProvider, @@ -264,10 +298,12 @@ public static IUISetting Handle( /// Sets a to and automatically associate the /// given to the switch state. /// + /// The instance. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// (optional) A method to invoke when the setting value changed. /// (optional) A list of items to be displayed in the drop down list. should be of type . + /// The updated instance. public static IUISetting Handle( this IUISetting element, ISettingsProvider settingsProvider, @@ -291,10 +327,12 @@ public static IUISetting Handle( /// Sets a to and automatically associate the /// given to the switch state. /// + /// The instance. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// (optional) A method to invoke when the setting value changed. /// (optional) A list of items to be displayed in the drop down list. should be of type . + /// The updated instance. public static IUISetting Handle( this IUISetting element, ISettingsProvider settingsProvider, diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs index 6f9f7e3d64..715c6df7b5 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/IUISettingGroup.cs @@ -50,14 +50,17 @@ protected override IEnumerable GetChildren() } } + /// public IUIElement[]? Children { get => _children; internal set => SetPropertyValue(ref _children, value, ChildrenChanged); } + /// public bool ChildrenAreAllSettings { get; internal set; } + /// public event EventHandler? ChildrenChanged; } @@ -81,17 +84,24 @@ public static IUISettingGroup SettingGroup(string? id) } /// - /// Sets the of the setting. + /// Sets the of the setting. /// - public static IUISettingGroup Description(this IUISettingGroup element, string? text) + /// The element. + /// The description. + /// The updated element. + public static IUISettingGroup Description(this IUISettingGroup element, string? description) { - ((UISettingGroup)element).Description = text; + ((UISettingGroup)element).Description = description; return element; } /// - /// Sets the of the setting. + /// Sets the of the setting. /// + /// The element. + /// The font name. + /// The glyph character. + /// The updated element. public static IUISettingGroup Icon(this IUISettingGroup element, string fontName, char glyph) { ((UISettingGroup)element).Icon = Icon(fontName, glyph); @@ -99,8 +109,11 @@ public static IUISettingGroup Icon(this IUISettingGroup element, string fontName } /// - /// Sets the of the setting. + /// Sets the of the setting. /// + /// The element. + /// The interactive UI element. + /// The updated element. public static IUISettingGroup InteractiveElement(this IUISettingGroup element, IUIElement? uiElement) { ((UISettingGroup)element).InteractiveElement = uiElement; @@ -108,12 +121,14 @@ public static IUISettingGroup InteractiveElement(this IUISettingGroup element, I } /// - /// Sets a to and automatically associate the + /// Sets a to and automatically associate the /// given to the switch state. /// + /// The element. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// (optional) A method to invoke when the setting value changed. + /// The updated element. public static IUISettingGroup Handle( this IUISettingGroup element, ISettingsProvider settingsProvider, @@ -127,10 +142,13 @@ public static IUISettingGroup Handle( /// Sets a to and automatically associate the /// given to the switch state. /// + /// The type of the setting value. + /// The element. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// (optional) A method to invoke when the setting value changed. /// (optional) A list of items to be displayed in the drop down list. should be of type . + /// The updated element. public static IUISettingGroup Handle( this IUISettingGroup element, ISettingsProvider settingsProvider, @@ -143,12 +161,14 @@ public static IUISettingGroup Handle( } /// - /// Sets a to and automatically associate the + /// Sets a to and automatically associate the /// given to the switch state. /// + /// The element. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// (optional) A method to invoke when the setting value changed. + /// The updated element. public static IUISettingGroup Handle( this IUISettingGroup element, ISettingsProvider settingsProvider, @@ -166,10 +186,13 @@ public static IUISettingGroup Handle( /// Sets a to and automatically associate the /// given to the switch state. /// + /// The type of the setting value. + /// The element. /// The settings provider used for handling the given . /// The definition of the setting to associate to this . /// (optional) A method to invoke when the setting value changed. /// (optional) A list of items to be displayed in the drop down list. should be of type . + /// The updated element. public static IUISettingGroup Handle( this IUISettingGroup element, ISettingsProvider settingsProvider, @@ -188,6 +211,9 @@ public static IUISettingGroup Handle( /// /// Sets the children to be displayed in the group. /// + /// The element. + /// The child elements. + /// The updated element. public static IUISettingGroup WithChildren(this IUISettingGroup element, params IUIElement[] children) { var settingGroup = (UISettingGroup)element; @@ -199,6 +225,9 @@ public static IUISettingGroup WithChildren(this IUISettingGroup element, params /// /// Sets the children to be displayed in the group. /// + /// The element. + /// The settings to be displayed in the group. + /// The updated element. public static IUISettingGroup WithSettings(this IUISettingGroup element, params IUISetting[] settings) { var settingGroup = (UISettingGroup)element; diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIDialog.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIDialog.cs index e9f6341367..a0140bf229 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIDialog.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIDialog.cs @@ -1,14 +1,28 @@ namespace DevToys.Api; +/// +/// Represents a modal dialog. +/// public sealed class UIDialog : IDisposable { private readonly TaskCompletionSource _dialogCloseCompletionSource = new(); + /// + /// Initializes a new instance of the class with the specified dialog content and dismissible flag. + /// + /// The dialog content. + /// A flag indicating whether the dialog can be closed by clicking outside of it. internal UIDialog(IUIElement dialogContent, bool isDismissible) : this(dialogContent, null, isDismissible) { } + /// + /// Initializes a new instance of the class with the specified dialog content, footer content, and dismissible flag. + /// + /// The dialog content. + /// The footer content. + /// A flag indicating whether the dialog can be closed by clicking outside of it. internal UIDialog(IUIElement dialogContent, IUIElement? footerContent, bool isDismissible) { DialogContent = dialogContent; @@ -18,18 +32,39 @@ internal UIDialog(IUIElement dialogContent, IUIElement? footerContent, bool isDi DialogCloseAwaiter = _dialogCloseCompletionSource.Task; } + /// + /// Gets a value indicating whether the dialog is opened. + /// public bool IsOpened { get; private set; } + /// + /// Gets a value indicating whether the dialog can be closed by clicking outside of it, pressing Escape key, or losing focus. + /// public bool IsDismissible { get; } + /// + /// Gets the dialog content. + /// public IUIElement? DialogContent { get; } + /// + /// Gets the footer content. + /// public IUIElement? FooterContent { get; } + /// + /// Gets the task that completes when the dialog closes. + /// public Task DialogCloseAwaiter { get; } + /// + /// Occurs when the property changes. + /// public event EventHandler? IsOpenedChanged; + /// + /// Closes the dialog. + /// public void Close() { IsOpened = false; @@ -37,6 +72,9 @@ public void Close() _dialogCloseCompletionSource.TrySetResult(); } + /// + /// Disposes the dialog. + /// public void Dispose() { Close(); diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridLength.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridLength.cs index 85de656ec2..22576a5883 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridLength.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridLength.cs @@ -1,5 +1,8 @@ namespace DevToys.Api; +/// +/// Represents the length of a row or column. +/// [DebuggerDisplay($"{{{nameof(ToString)}}}")] public readonly struct UIGridLength : IEquatable { @@ -135,6 +138,10 @@ public override int GetHashCode() return _value.GetHashCode() ^ _type.GetHashCode(); } + /// + /// Returns a string that represents the current . + /// + /// A string that represents the current . public override string ToString() { if (IsAuto) diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridUnitType.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridUnitType.cs index 38460d0857..cfbc6a4730 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridUnitType.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIGridUnitType.cs @@ -1,5 +1,8 @@ namespace DevToys.Api; +/// +/// Represents the unit type of a row or column. +/// public enum UIGridUnitType { /// diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpan.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpan.cs index 7241ea0040..b041101128 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpan.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpan.cs @@ -1,13 +1,27 @@ namespace DevToys.Api; +/// +/// Represents a highlighted span in a text. +/// public record UIHighlightedTextSpan : TextSpan { + /// + /// Initializes a new instance of the class. + /// + /// The start position of the highlighted text span. + /// The length of the highlighted text span. + /// The color of the highlighted text span. public UIHighlightedTextSpan(int startPosition, int length, UIHighlightedTextSpanColor color = UIHighlightedTextSpanColor.Default) : base(startPosition, length) { Color = color; } + /// + /// Initializes a new instance of the class based on the original . + /// + /// The original . + /// The color of the highlighted text span. protected UIHighlightedTextSpan(TextSpan original, UIHighlightedTextSpanColor color = UIHighlightedTextSpanColor.Default) : base(original) { diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpanColor.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpanColor.cs index 56e4cf35a1..904a155dc8 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpanColor.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIHighlightedTextSpanColor.cs @@ -1,12 +1,42 @@ namespace DevToys.Api; +/// +/// Represents the color options for a highlighted text span in the UI. +/// public enum UIHighlightedTextSpanColor { + /// + /// The default color. + /// Default, + + /// + /// The blue color. + /// Blue, + + /// + /// The green color. + /// Green, + + /// + /// The red color. + /// Red, + + /// + /// The yellow color. + /// Yellow, + + /// + /// The purple color. + /// Purple, + + /// + /// The teal color. + /// Teal } diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIInfoBarSeverity.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIInfoBarSeverity.cs index e059c9def4..3fc8e4bd42 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIInfoBarSeverity.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIInfoBarSeverity.cs @@ -1,9 +1,27 @@ namespace DevToys.Api; +/// +/// Represents the severity level of a . +/// public enum UIInfoBarSeverity { + /// + /// Informational severity. + /// Informational, + + /// + /// Error severity. + /// Error, + + /// + /// Success severity. + /// Success, + + /// + /// Warning severity. + /// Warning } diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UILabelStyle.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UILabelStyle.cs index bb3350364c..056f043d56 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UILabelStyle.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UILabelStyle.cs @@ -1,13 +1,47 @@ namespace DevToys.Api; +/// +/// Represents the style of a . +/// public enum UILabelStyle { + /// + /// The caption style. + /// Caption, + + /// + /// The body style. + /// Body, + + /// + /// The strong body style. + /// BodyStrong, + + /// + /// The large body style. + /// BodyLarge, + + /// + /// The subtitle style. + /// Subtitle, + + /// + /// The title style. + /// Title, + + /// + /// The large title style. + /// TitleLarge, + + /// + /// The display style. + /// Display } diff --git a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs index 77bb58c368..c8f8a26546 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/Components/UIToolView.cs @@ -33,7 +33,6 @@ public UIToolView(IUIElement? rootElement) /// Creates a new instance of the class. /// /// Indicates whether the UI of the tool is scrollable or should fits to the window boundaries. - /// The root element of the tool's UI. public UIToolView(bool isScrollable) : this(isScrollable, null) { @@ -92,6 +91,9 @@ public IUIElement? RootElement /// public event EventHandler? RootElementChanged; + /// + /// Raised when a property value changes. + /// public event PropertyChangedEventHandler? PropertyChanged; /// @@ -159,6 +161,14 @@ private void Dialog_IsOpenedChanged(object? sender, EventArgs e) } } + /// + /// Sets the property value and raises the property changed event if the value has changed. + /// + /// The type of the property. + /// The reference to the field storing the property value. + /// The new value to set. + /// The event handler to raise the property changed event. + /// The name of the property. Automatically inferred if not provided. protected void SetPropertyValue( ref T field, T value, @@ -173,6 +183,10 @@ protected void SetPropertyValue( } } + /// + /// Raises the property changed event for the specified property. + /// + /// The name of the property. Automatically inferred if not provided. protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new(propertyName)); diff --git a/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs b/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs index b0f613e08a..9dddb0d94f 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/IGuiTool.cs @@ -54,7 +54,7 @@ public interface IGuiTool /// The expected behavior of this method is to pass the to the /// that fits the given data. /// - /// The data type name, as defined by . + /// The data type name, as defined by . /// The data returned by the corresponding . void OnDataReceived(string dataTypeName, object? parsedData); } diff --git a/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs b/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs index e3c4547c51..235a7a258b 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs @@ -1,12 +1,42 @@ namespace DevToys.Api; +/// +/// Represents the predefined common tool group names. +/// public static class PredefinedCommonToolGroupNames { + /// + /// Represents the tool group for encoders and decoders. + /// public const string EncodersDecoders = "Encoders / Decoders"; + + /// + /// Represents the tool group for converters. + /// public const string Converters = "Converters"; + + /// + /// Represents the tool group for formatters. + /// public const string Formatters = "Formatters"; + + /// + /// Represents the tool group for generators. + /// public const string Generators = "Generators"; + + /// + /// Represents the tool group for graphics. + /// public const string Graphic = "Graphic"; + + /// + /// Represents the tool group for testers. + /// public const string Testers = "Testers"; + + /// + /// Represents the tool group for text. + /// public const string Text = "Text"; } diff --git a/src/app/dev/DevToys.Api/Tool/GUI/PredefinedSupportedImageFormats.cs b/src/app/dev/DevToys.Api/Tool/GUI/PredefinedSupportedImageFormats.cs index bd215cac9c..aeeb3107b3 100644 --- a/src/app/dev/DevToys.Api/Tool/GUI/PredefinedSupportedImageFormats.cs +++ b/src/app/dev/DevToys.Api/Tool/GUI/PredefinedSupportedImageFormats.cs @@ -1,5 +1,8 @@ namespace DevToys.Api; +/// +/// Represents a predefined list of supported image formats. +/// public static class PredefinedSupportedImageFormats { /// diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/AcceptedDataTypeNameAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/AcceptedDataTypeNameAttribute.cs index 210c527504..e63a8fc303 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/AcceptedDataTypeNameAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/AcceptedDataTypeNameAttribute.cs @@ -9,8 +9,15 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class AcceptedDataTypeNameAttribute : Attribute { + /// + /// Gets the name of the accepted data type. + /// public string DataTypeName { get; } + /// + /// Initializes a new instance of the class. + /// + /// The name of the accepted data type. public AcceptedDataTypeNameAttribute(string name) { Guard.IsNotEmpty(name); diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/CommandLineOptionAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/CommandLineOptionAttribute.cs index 37d3183537..e51295c880 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/CommandLineOptionAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/CommandLineOptionAttribute.cs @@ -9,7 +9,7 @@ public sealed class CommandLineOptionAttribute : CommandNameAttribute { /// /// Gets the name of the option. Example, "file". - /// Implicitly, an option named "file" will be usable in a command line through "--file ". + /// Implicitly, an option named "file" will be usable in a command line through "--file <value>". /// public new string Name { @@ -19,7 +19,7 @@ public sealed class CommandLineOptionAttribute : CommandNameAttribute /// /// Gets or sets the alias name of the option. Example, "f". - /// Implicitly, an option named "f" will be usable in a command line through "-f ". + /// Implicitly, an option named "f" will be usable in a command line through "-f <value>". /// public new string Alias { diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/DataTypeNameAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/DataTypeNameAttribute.cs index ce44e271f9..e8860e040b 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/DataTypeNameAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/DataTypeNameAttribute.cs @@ -7,10 +7,21 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class DataTypeNameAttribute : Attribute { + /// + /// Gets the data type name. + /// public string DataTypeName { get; } + /// + /// Gets the data type base name. + /// public string? DataTypeBaseName { get; } + /// + /// Initializes a new instance of the class. + /// + /// The data type name. + /// The data type base name. public DataTypeNameAttribute(string name, string? baseName = null) { Guard.IsNotEmpty(name); diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacement.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacement.cs index cb1aa8a574..aaba32f885 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacement.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacement.cs @@ -1,7 +1,17 @@ namespace DevToys.Api; +/// +/// Represents the placement of a menu. +/// public enum MenuPlacement { + /// + /// The menu is placed in the body. + /// Body, + + /// + /// The menu is placed in the footer. + /// Footer } diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacementAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacementAttribute.cs index a11b269464..35adf581c5 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacementAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/MenuPlacementAttribute.cs @@ -7,8 +7,15 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class MenuPlacementAttribute : Attribute { + /// + /// Gets the menu placement for the . + /// public MenuPlacement MenuPlacement { get; } + /// + /// Initializes a new instance of the class with the specified menu placement. + /// + /// The menu placement for the . public MenuPlacementAttribute(MenuPlacement menuPlacement) { MenuPlacement = menuPlacement; diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NameAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NameAttribute.cs index ee2c97c1f7..741bb0825a 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NameAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NameAttribute.cs @@ -7,8 +7,15 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class NameAttribute : Attribute { + /// + /// Gets the internal name of this component. + /// public string InternalComponentName { get; } + /// + /// Initializes a new instance of the class with the specified internal component name. + /// + /// The internal name of the component. public NameAttribute(string internalComponentName) { Guard.IsNotEmpty(internalComponentName); diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NoCompactOverlaySupportAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NoCompactOverlaySupportAttribute.cs index e8514eccd9..f622a8c88f 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NoCompactOverlaySupportAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NoCompactOverlaySupportAttribute.cs @@ -7,5 +7,8 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class NoCompactOverlaySupportAttribute : Attribute { + /// + /// Gets a value indicating whether the supports Compact Overlay mode. + /// public bool NoCompactOverlaySupport { get; } = true; } diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotFavorableAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotFavorableAttribute.cs index 8e5910e03a..f671b6c0ed 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotFavorableAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotFavorableAttribute.cs @@ -7,5 +7,8 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class NotFavorableAttribute : Attribute { + /// + /// Gets a value indicating whether the is not favorable. + /// public bool NotFavorable { get; } = true; } diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotSearchableAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotSearchableAttribute.cs index 9371dea954..c7f969f293 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotSearchableAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/NotSearchableAttribute.cs @@ -7,5 +7,8 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class NotSearchableAttribute : Attribute { + /// + /// Gets a value indicating whether the is not searchable. + /// public bool NotSearchable { get; } = true; } diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs index 07cedc7503..9128de6af3 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs @@ -1,9 +1,27 @@ namespace DevToys.Api; +/// +/// Represents the platform on which the application runs. +/// public enum Platform { + /// + /// The Windows platform. + /// Windows, - MacCatalyst, + + /// + /// The MacOS or MacCatalyst platform. + /// + MacOS, + + /// + /// The Linux platform. + /// Linux, + + /// + /// The WebAssembly platform. + /// WASM } diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/TargetPlatformAttribute.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/TargetPlatformAttribute.cs index c6d60ccbbc..73188ecc5d 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/TargetPlatformAttribute.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/TargetPlatformAttribute.cs @@ -7,8 +7,15 @@ [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class TargetPlatformAttribute : Attribute { + /// + /// Gets the target platform. + /// public Platform TargetPlatform { get; } + /// + /// Initializes a new instance of the class. + /// + /// The target platform. public TargetPlatformAttribute(Platform platform) { TargetPlatform = platform; diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Metadata/IOrderableMetadata.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Metadata/IOrderableMetadata.cs index 6033a4bab5..a4e99d96c0 100644 --- a/src/app/dev/DevToys.Api/Tool/Metadata/Metadata/IOrderableMetadata.cs +++ b/src/app/dev/DevToys.Api/Tool/Metadata/Metadata/IOrderableMetadata.cs @@ -1,10 +1,22 @@ namespace DevToys.Api; +/// +/// Represents an orderable component. +/// public interface IOrderableMetadata { + /// + /// Gets the list of items that should come before this component. + /// IReadOnlyList Before { get; } + /// + /// Gets the list of items that should come after this component. + /// IReadOnlyList After { get; } + /// + /// Gets the internal component name. + /// string InternalComponentName { get; } } diff --git a/src/app/dev/DevToys.Api/Tool/SmartDetection/DataDetectionResult.cs b/src/app/dev/DevToys.Api/Tool/SmartDetection/DataDetectionResult.cs index 58ae412620..98bfa71637 100644 --- a/src/app/dev/DevToys.Api/Tool/SmartDetection/DataDetectionResult.cs +++ b/src/app/dev/DevToys.Api/Tool/SmartDetection/DataDetectionResult.cs @@ -1,8 +1,29 @@ namespace DevToys.Api; +/// +/// Represents the result of data detection. +/// +/// A value indicating whether the data detection was successful. +/// The detected data. public record DataDetectionResult(bool Success, object? Data) { - public static readonly DataDetectionResult Unsuccessful = new(false, null); + /// + /// Gets a value indicating whether the data detection was successful. + /// + public bool Success { get; init; } = Success; + + /// + /// Gets the detected data. + /// + public object? Data { get; init; } = Data; + /// + /// Gets the type of the detected data. + /// public Type? DataType => Data?.GetType(); + + /// + /// Represents an unsuccessful data detection result. + /// + public static readonly DataDetectionResult Unsuccessful = new(false, null); } diff --git a/src/app/dev/DevToys.Api/Tool/SmartDetection/IDataTypeDetector.cs b/src/app/dev/DevToys.Api/Tool/SmartDetection/IDataTypeDetector.cs index 7b1cd148c3..f26d4afb1d 100644 --- a/src/app/dev/DevToys.Api/Tool/SmartDetection/IDataTypeDetector.cs +++ b/src/app/dev/DevToys.Api/Tool/SmartDetection/IDataTypeDetector.cs @@ -19,7 +19,7 @@ public interface IDataTypeDetector { /// - /// Tries to detect whether the given match the expected format known by this + /// Tries to detect whether the given match the expected format known by this /// , often by trying to reading and/or parsing it. /// /// @@ -34,6 +34,7 @@ public interface IDataTypeDetector /// The data to analyze, often coming from the OS's clipboard. /// The result coming from the corresponding to the given . /// Since, the is optional, this parameter can be null. + /// A that gets canceled within 2 seconds. /// /// Returns a that indicates whether the data could be analyzed / parsed / read /// correctly, along with the parsed data, if any change has been made to it during parsing (for example, string to diff --git a/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs b/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs index de3ab80dd0..2989189441 100644 --- a/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs +++ b/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs @@ -1,19 +1,77 @@ namespace DevToys.Api; +/// +/// Predefined common data type names. +/// public static class PredefinedCommonDataTypeNames { + /// + /// Represents the text data type. + /// public const string Text = "text"; + + /// + /// Represents the JSON data type. + /// public const string Json = "json"; + + /// + /// Represents the JSON array data type. + /// public const string JsonArray = "jsonArray"; + + /// + /// Represents the YAML data type. + /// public const string Yaml = "yaml"; + + /// + /// Represents the XML data type. + /// public const string Xml = "xml"; + + /// + /// Represents the XSD data type. + /// public const string Xsd = "xsd"; + + /// + /// Represents the Base64 text data type. + /// public const string Base64Text = "base64Text"; + + /// + /// Represents the Base64 image data type. + /// public const string Base64Image = "base64Image"; + + /// + /// Represents the "mage data type. + /// public const string Image = "image"; + + /// + /// Represents the image file data type. + /// public const string ImageFile = "imageFile"; + + /// + /// Represents the file data type. + /// public const string File = "file"; + + /// + /// Represents the files data type. + /// public const string Files = "files"; + + /// + /// Represents the GZIP data type. + /// public const string GZip = "gzip"; + + /// + /// Represents the date data type. + /// public const string Date = "date"; } diff --git a/src/app/dev/DevToys.Blazor/BuiltInTools/ExtensionsManager/ExtensionsManagerGuiTool.cs b/src/app/dev/DevToys.Blazor/BuiltInTools/ExtensionsManager/ExtensionsManagerGuiTool.cs index be0f29dd5d..4d81c47424 100644 --- a/src/app/dev/DevToys.Blazor/BuiltInTools/ExtensionsManager/ExtensionsManagerGuiTool.cs +++ b/src/app/dev/DevToys.Blazor/BuiltInTools/ExtensionsManager/ExtensionsManagerGuiTool.cs @@ -22,7 +22,7 @@ namespace DevToys.Blazor.BuiltInTools.ExtensionsManager; [Order(Before = SettingsGuiTool.SettingsInternalToolName)] [TargetPlatform(Platform.Windows)] [TargetPlatform(Platform.Linux)] -[TargetPlatform(Platform.MacCatalyst)] +[TargetPlatform(Platform.MacOS)] internal sealed class ExtensionsManagerGuiTool : IGuiTool { internal const string ExtensionmanagerToolName = "Extensions Manager"; diff --git a/src/app/dev/DevToys.Blazor/Components/BasicInput/ComboBox/ComboBox.razor.cs b/src/app/dev/DevToys.Blazor/Components/BasicInput/ComboBox/ComboBox.razor.cs index 7a74a77f2d..ce9bb4515f 100644 --- a/src/app/dev/DevToys.Blazor/Components/BasicInput/ComboBox/ComboBox.razor.cs +++ b/src/app/dev/DevToys.Blazor/Components/BasicInput/ComboBox/ComboBox.razor.cs @@ -50,7 +50,7 @@ private void ToggleDropDown(MouseEventArgs ev) } } - private void OpenDropDown(MouseEventArgs ev) + private void OpenDropDown(MouseEventArgs _) { if (IsActuallyEnabled && ContextMenuService.TryOpenContextMenu()) { @@ -70,7 +70,7 @@ private void OpenDropDown(MouseEventArgs ev) } } - private void CloseDropDown(MouseEventArgs? ev) + private void CloseDropDown(MouseEventArgs? __) { ContextMenuService.CloseContextMenuRequested -= ContextMenuService_CloseContextMenuRequested; ContextMenuService.CloseContextMenu(); diff --git a/src/app/dev/DevToys.Blazor/Components/BasicInput/DropDownButton/DropDownButton.razor.cs b/src/app/dev/DevToys.Blazor/Components/BasicInput/DropDownButton/DropDownButton.razor.cs index 00e806fe03..6b8c7103a4 100644 --- a/src/app/dev/DevToys.Blazor/Components/BasicInput/DropDownButton/DropDownButton.razor.cs +++ b/src/app/dev/DevToys.Blazor/Components/BasicInput/DropDownButton/DropDownButton.razor.cs @@ -90,7 +90,7 @@ private void ToggleDropDown(MouseEventArgs ev) } } - private void OpenDropDown(MouseEventArgs ev) + private void OpenDropDown(MouseEventArgs _) { if (IsActuallyEnabled && ContextMenuService.TryOpenContextMenu()) { @@ -100,7 +100,7 @@ private void OpenDropDown(MouseEventArgs ev) } } - private void CloseDropDown(MouseEventArgs? ev) + private void CloseDropDown(MouseEventArgs? _) { ContextMenuService.CloseContextMenuRequested -= ContextMenuService_CloseContextMenuRequested; ContextMenuService.CloseContextMenu(); @@ -116,7 +116,7 @@ private void OnEscapeKeyPressed() } } - private void OnDropDowlListItemSelected(int itemIndex) + private void OnDropDowlListItemSelected(int _) { if (_listBox is not null && _listBox.SelectedItem is not null && _listBox.SelectedItem.IsEnabled) { diff --git a/src/app/dev/DevToys.Blazor/Components/Menu/ContextMenu/ContextMenu.razor.cs b/src/app/dev/DevToys.Blazor/Components/Menu/ContextMenu/ContextMenu.razor.cs index cb2acf78a6..0553f211cd 100644 --- a/src/app/dev/DevToys.Blazor/Components/Menu/ContextMenu/ContextMenu.razor.cs +++ b/src/app/dev/DevToys.Blazor/Components/Menu/ContextMenu/ContextMenu.razor.cs @@ -88,7 +88,7 @@ private async Task OpenMenuAsync(MouseEventArgs ev) } } - private async Task CloseMenuAsync(MouseEventArgs? ev) + private async Task CloseMenuAsync(MouseEventArgs? _) { ContextMenuService.CloseContextMenuRequested -= ContextMenuService_CloseContextMenuRequested; ContextMenuService.CloseContextMenu(); diff --git a/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorHelper.cs b/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorHelper.cs index d4fd32da60..d4714ee57b 100644 --- a/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorHelper.cs +++ b/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorHelper.cs @@ -11,6 +11,12 @@ namespace DevToys.Blazor.Components; internal static class MonacoEditorHelper { + private static readonly JsonSerializerOptions jsonSerializerOptions = new() + { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + /// /// Create a new editor under `domElement`. /// `domElement` should be empty (not contain other dom nodes). @@ -29,11 +35,7 @@ internal static class MonacoEditorHelper Guard.IsNotNull(dotnetObjectRef); // Convert the options object into a JsonElement to get rid of the properties with null values - string optionsJson = JsonSerializer.Serialize(options, new JsonSerializerOptions - { - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - PropertyNamingPolicy = JsonNamingPolicy.CamelCase - }); + string optionsJson = JsonSerializer.Serialize(options, jsonSerializerOptions); JsonElement optionsDict = JsonSerializer.Deserialize(optionsJson); // Create the editor @@ -64,11 +66,7 @@ await runtime.InvokeVoidAsync( options ??= new StandaloneDiffEditorConstructionOptions(); // Convert the options object into a JsonElement to get rid of the properties with null values - string optionsJson = JsonSerializer.Serialize(options, new JsonSerializerOptions - { - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - PropertyNamingPolicy = JsonNamingPolicy.CamelCase - }); + string optionsJson = JsonSerializer.Serialize(options, jsonSerializerOptions); JsonElement optionsDict = JsonSerializer.Deserialize(optionsJson); // Create the editor diff --git a/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/RicherMonacoEditorDiffBase.cs b/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/RicherMonacoEditorDiffBase.cs index 5db2468638..80f0aab1d2 100644 --- a/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/RicherMonacoEditorDiffBase.cs +++ b/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/RicherMonacoEditorDiffBase.cs @@ -8,6 +8,12 @@ namespace DevToys.Blazor.Components; public abstract class RicherMonacoEditorDiffBase : MonacoEditorBase { + private static readonly JsonSerializerOptions jsonSerializerOptions = new() + { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + protected RicherMonacoEditorBase? _originalEditor; protected RicherMonacoEditorBase? _modifiedEditor; @@ -346,11 +352,7 @@ public ValueTask SetModelAsync(DiffEditorModel model) public async ValueTask UpdateOptionsAsync(DiffEditorOptions newOptions) { // Convert the options object into a JsonElement to get rid of the properties with null values - string optionsJson = JsonSerializer.Serialize(newOptions, new JsonSerializerOptions - { - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - PropertyNamingPolicy = JsonNamingPolicy.CamelCase - }); + string optionsJson = JsonSerializer.Serialize(newOptions, jsonSerializerOptions); JsonElement optionsDict = JsonSerializer.Deserialize(optionsJson); bool success = await JSRuntime.InvokeVoidWithErrorHandlingAsync("devtoys.MonacoEditor.updateOptions", Id, optionsDict); diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor.cs index 2a9a8e934f..3c4099a673 100644 --- a/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor.cs +++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UITextInputWrapper.razor.cs @@ -351,7 +351,7 @@ private void TriggerSmartDetection() CancellationTokenSource? cancellationSourceToken = _cancellationTokenSource; cancellationSourceToken?.Cancel(); cancellationSourceToken?.Dispose(); - Interlocked.Exchange(ref _cancellationTokenSource, new(TimeSpan.FromSeconds(5))); + Interlocked.Exchange(ref _cancellationTokenSource, new(TimeSpan.FromSeconds(2))); SmartDetectToolsAsync(UITextInput.Text, _cancellationTokenSource.Token).ForgetSafely(); } } diff --git a/src/app/dev/DevToys.Blazor/Core/Converters/PolymorphicConverterFactory.cs b/src/app/dev/DevToys.Blazor/Core/Converters/PolymorphicConverterFactory.cs index 50ad531bd9..7df49e7579 100644 --- a/src/app/dev/DevToys.Blazor/Core/Converters/PolymorphicConverterFactory.cs +++ b/src/app/dev/DevToys.Blazor/Core/Converters/PolymorphicConverterFactory.cs @@ -19,7 +19,7 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer typeof(PolymorphicConverter<>).MakeGenericType(typeToConvert), BindingFlags.Instance | BindingFlags.Public, null, - new object[] { }, + Array.Empty(), null)!; } } diff --git a/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs b/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs index 0690c2a4df..cbd61571fe 100644 --- a/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs +++ b/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs @@ -8,7 +8,7 @@ public static async Task WaitForDebuggerAsync(TimeSpan? limit = null) limit ??= TimeSpan.FromSeconds(60); using var source = new CancellationTokenSource(limit.Value); - Console.WriteLine($"◉ Waiting {limit.Value.TotalSeconds} secs for debugger (PID: {Process.GetCurrentProcess().Id})..."); + Console.WriteLine($"◉ Waiting {limit.Value.TotalSeconds} secs for debugger (PID: {Environment.ProcessId})..."); try { diff --git a/src/app/dev/DevToys.Api/Core/ExtensionOrderer.cs b/src/app/dev/DevToys.Core/ExtensionOrderer.cs similarity index 78% rename from src/app/dev/DevToys.Api/Core/ExtensionOrderer.cs rename to src/app/dev/DevToys.Core/ExtensionOrderer.cs index 1f08cb88df..105a3f02d5 100644 --- a/src/app/dev/DevToys.Api/Core/ExtensionOrderer.cs +++ b/src/app/dev/DevToys.Core/ExtensionOrderer.cs @@ -1,8 +1,18 @@ -namespace DevToys.Api; +namespace DevToys.Core; -public static class ExtensionOrderer +/// +/// Provides methods for ordering and checking cycles in extensions. +/// +internal static class ExtensionOrderer { - public static IEnumerable> Order( + /// + /// Orders the extensions based on their metadata. + /// + /// The type of the extension. + /// The type of the metadata. + /// The extensions to be ordered. + /// The ordered extensions. + internal static IEnumerable> Order( IEnumerable> extensions) where TMetadata : IOrderableMetadata { @@ -10,7 +20,13 @@ public static IEnumerable> Order( + /// + /// Checks for cycles in the extensions. + /// + /// The type of the extension. + /// The type of the metadata. + /// The extensions to be checked. + internal static void CheckForCycles( IEnumerable> extensions) where TMetadata : IOrderableMetadata { diff --git a/src/app/dev/DevToys.Core/Mef/RecursiveDirectoryCatalog.cs b/src/app/dev/DevToys.Core/Mef/RecursiveDirectoryCatalog.cs index 45ea682340..3791d5e0c7 100644 --- a/src/app/dev/DevToys.Core/Mef/RecursiveDirectoryCatalog.cs +++ b/src/app/dev/DevToys.Core/Mef/RecursiveDirectoryCatalog.cs @@ -41,17 +41,6 @@ public RecursiveDirectoryCatalog(string path, string searchPattern) Initialize(path, searchPattern); } - private static IEnumerable GetFoldersRecursive(string path) - { - var result = new List { path }; - foreach (string child in Directory.GetDirectories(path)) - { - result.AddRange(GetFoldersRecursive(child)); - } - - return result; - } - private void Initialize(string path, string searchPattern) { IEnumerable files diff --git a/src/app/dev/DevToys.Core/OSHelper.cs b/src/app/dev/DevToys.Core/OSHelper.cs index b491b33b2f..79a066739c 100644 --- a/src/app/dev/DevToys.Core/OSHelper.cs +++ b/src/app/dev/DevToys.Core/OSHelper.cs @@ -13,7 +13,7 @@ public static bool IsOsSupported(IReadOnlyList targetPlatforms) } else if (OperatingSystem.IsMacOS() || OperatingSystem.IsMacCatalyst()) { - currentPlatform = Platform.MacCatalyst; + currentPlatform = Platform.MacOS; } else if (OperatingSystem.IsWindows()) { diff --git a/src/app/dev/DevToys.Core/Tools/SmartDetectionService.cs b/src/app/dev/DevToys.Core/Tools/SmartDetectionService.cs index a54587e67c..bad905f632 100644 --- a/src/app/dev/DevToys.Core/Tools/SmartDetectionService.cs +++ b/src/app/dev/DevToys.Core/Tools/SmartDetectionService.cs @@ -121,7 +121,7 @@ public async Task> DetectAsync(object? rawData, DetectorNode detectorNode = detectorHierarchy[i]; // Detect data types from raw data using the current detector. - DataDetectionResult resultFromDetector = await DetectAsync(cancellationToken, detectorNode.Detector.Value, rawData, resultFromBaseDetector); + DataDetectionResult resultFromDetector = await DetectAsync(detectorNode.Detector.Value, rawData, resultFromBaseDetector, cancellationToken); // If the detection was successful if (resultFromDetector.Success) @@ -162,10 +162,10 @@ public async Task> DetectAsync(object? rawData, } private async ValueTask DetectAsync( - CancellationToken cancellationToken, IDataTypeDetector detector, object rawData, - DataDetectionResult? resultFromBaseDetector) + DataDetectionResult? resultFromBaseDetector, + CancellationToken cancellationToken) { try { diff --git a/src/app/dev/DevToys.Tools/Helpers/Base64Helper.cs b/src/app/dev/DevToys.Tools/Helpers/Base64Helper.cs index 62f9f281a9..1f5c835c42 100644 --- a/src/app/dev/DevToys.Tools/Helpers/Base64Helper.cs +++ b/src/app/dev/DevToys.Tools/Helpers/Base64Helper.cs @@ -56,14 +56,12 @@ internal static bool IsBase64DataStrict(string? data) return false; } -#pragma warning disable IDE0078 // Use pattern matching if (!(current == 0x9 || current == 0xA || current == 0xD || current >= 0x20 && current <= 0xD7FF || current >= 0xE000 && current <= 0xFFFD || current >= 0x10000 && current <= 0x10FFFF)) -#pragma warning restore IDE0078 // Use pattern matching { return false; } diff --git a/src/app/dev/DevToys.Tools/Helpers/Core/CryptoRandom.cs b/src/app/dev/DevToys.Tools/Helpers/Core/CryptoRandom.cs index 4e2fef8b8a..1f2385fcd8 100644 --- a/src/app/dev/DevToys.Tools/Helpers/Core/CryptoRandom.cs +++ b/src/app/dev/DevToys.Tools/Helpers/Core/CryptoRandom.cs @@ -62,8 +62,7 @@ public override int Next() /// public override int Next(int maxValue) { - if (maxValue < 0) - throw new ArgumentOutOfRangeException(nameof(maxValue)); + ArgumentOutOfRangeException.ThrowIfNegative(maxValue); return Next(0, maxValue); } @@ -81,8 +80,7 @@ public override int Next(int maxValue) /// public override int Next(int minValue, int maxValue) { - if (minValue > maxValue) - throw new ArgumentOutOfRangeException(nameof(minValue)); + ArgumentOutOfRangeException.ThrowIfGreaterThan(minValue, maxValue); if (minValue == maxValue) return minValue; @@ -123,8 +121,7 @@ public override double NextDouble() /// public override void NextBytes(byte[] buffer) { - if (buffer == null) - throw new ArgumentNullException(nameof(buffer)); + ArgumentNullException.ThrowIfNull(buffer); Rng.GetBytes(buffer); } diff --git a/src/app/dev/DevToys.Tools/Helpers/JsonHelper.cs b/src/app/dev/DevToys.Tools/Helpers/JsonHelper.cs index 7ca200f37c..8743aa7b0b 100644 --- a/src/app/dev/DevToys.Tools/Helpers/JsonHelper.cs +++ b/src/app/dev/DevToys.Tools/Helpers/JsonHelper.cs @@ -265,7 +265,7 @@ internal static ResultInfo ConvertFromYaml( } catch (Exception ex) { - logger.LogError("Yaml to Json Converter", ex); + logger.LogError(ex, "Yaml to Json Converter"); return new(string.Empty, false); } } diff --git a/src/app/dev/DevToys.Tools/Helpers/LoremIpsum/LipsumGenerator.cs b/src/app/dev/DevToys.Tools/Helpers/LoremIpsum/LipsumGenerator.cs index b839448752..2fa127f97b 100644 --- a/src/app/dev/DevToys.Tools/Helpers/LoremIpsum/LipsumGenerator.cs +++ b/src/app/dev/DevToys.Tools/Helpers/LoremIpsum/LipsumGenerator.cs @@ -12,7 +12,7 @@ internal sealed class LipsumGenerator { private const string LoremIpsumStartText = "Lorem ipsum dolor sit amet"; - private LipsumsCorpus _lipsum = LipsumsCorpus.LoremIpsum; + private readonly LipsumsCorpus _lipsum = LipsumsCorpus.LoremIpsum; private StringBuilder _lipsumText = new(); private IReadOnlyList _preparedWords = Array.Empty(); @@ -165,7 +165,7 @@ internal string[] GenerateParagraphs(int count, Paragraph options) * refactored into one method that takes a count * and a TextFeature. */ string[] paragraphs = new string[count]; - string[] sentences = new string[] { }; + string[] sentences; for (int i = 0; i < count; i++) { /* Get a random amount of sentences based on the @@ -216,7 +216,7 @@ private string[] GenerateSentences(int count, string formatString) internal string[] GenerateSentences(int count, Sentence options) { string[] sentences = new string[count]; - string[] words = new string[] { }; + string[] words; for (int i = 0; i < count; i++) { diff --git a/src/app/dev/DevToys.Tools/Helpers/XmlHelper.cs b/src/app/dev/DevToys.Tools/Helpers/XmlHelper.cs index eb21a103a6..8b786d7b42 100644 --- a/src/app/dev/DevToys.Tools/Helpers/XmlHelper.cs +++ b/src/app/dev/DevToys.Tools/Helpers/XmlHelper.cs @@ -118,7 +118,7 @@ internal static ResultInfo Format(string? input, Indentation indentation } catch (Exception ex) // some other exception { - logger.LogError(ex, "Xml formatter", $"Indentation: {indentationMode}"); + logger.LogError(ex, "Xml formatter. Indentation: {indentationMode}", indentationMode); return new(ex.Message, false); } } diff --git a/src/app/dev/DevToys.Tools/Helpers/XsdHelper.cs b/src/app/dev/DevToys.Tools/Helpers/XsdHelper.cs index 6654451c90..8329543cce 100644 --- a/src/app/dev/DevToys.Tools/Helpers/XsdHelper.cs +++ b/src/app/dev/DevToys.Tools/Helpers/XsdHelper.cs @@ -78,8 +78,8 @@ void ValidationErrorCallBack(object? sender, ValidationEventArgs e) { // XML will always be valid if it doesn't define a namespace. Let's verify that namespaces aren't missing. var xsdDocument = XDocument.Parse(xsd); - IEnumerable xsdNamespaces = GetAllNamespaces(xsdDocument); - IEnumerable xmlNamespaces = GetAllNamespaces(xmlDocument); + IReadOnlyList xsdNamespaces = GetAllNamespaces(xsdDocument); + IReadOnlyList xmlNamespaces = GetAllNamespaces(xmlDocument); cancellationToken.ThrowIfCancellationRequested(); @@ -187,7 +187,7 @@ private static IEnumerable GetNamespacesFromXsd(IEnumerable /// XML document containing namespaces. /// - private static IEnumerable GetAllNamespaces(XDocument xmlDocument) + private static IReadOnlyList GetAllNamespaces(XDocument xmlDocument) { XPathNavigator? navigator = xmlDocument.CreateNavigator(); navigator.MoveToFollowing(XPathNodeType.Element); diff --git a/src/app/dev/DevToys.Tools/Helpers/YamlHelper.cs b/src/app/dev/DevToys.Tools/Helpers/YamlHelper.cs index b8ffeed6c4..cd532d1518 100644 --- a/src/app/dev/DevToys.Tools/Helpers/YamlHelper.cs +++ b/src/app/dev/DevToys.Tools/Helpers/YamlHelper.cs @@ -103,7 +103,7 @@ var serializer } catch (Exception ex) { - logger.LogError("Yaml to Json Converter", ex); + logger.LogError(ex, "Yaml to Json Converter"); return new(string.Empty, false); } } diff --git a/src/app/dev/DevToys.Tools/SmartDetection/DateDataTypeDetector.cs b/src/app/dev/DevToys.Tools/SmartDetection/DateDataTypeDetector.cs index 3b7b8b59e8..6b152c1a22 100644 --- a/src/app/dev/DevToys.Tools/SmartDetection/DateDataTypeDetector.cs +++ b/src/app/dev/DevToys.Tools/SmartDetection/DateDataTypeDetector.cs @@ -11,7 +11,6 @@ public ValueTask TryDetectDataAsync(object data, DataDetect && !long.TryParse(dataString, out _) && !string.IsNullOrWhiteSpace(dataString)) { - if (long.TryParse(dataString, out long potentialTimestamp)) { try @@ -28,8 +27,8 @@ public ValueTask TryDetectDataAsync(object data, DataDetect { return ValueTask.FromResult(new DataDetectionResult(Success: true, Data: dateTimeOffset)); } - } + return ValueTask.FromResult(DataDetectionResult.Unsuccessful); } } diff --git a/src/app/dev/DevToys.Tools/SmartDetection/JsonArrayDataTypeDetector.cs b/src/app/dev/DevToys.Tools/SmartDetection/JsonArrayDataTypeDetector.cs index cec2aab60f..15a3ac8d9a 100644 --- a/src/app/dev/DevToys.Tools/SmartDetection/JsonArrayDataTypeDetector.cs +++ b/src/app/dev/DevToys.Tools/SmartDetection/JsonArrayDataTypeDetector.cs @@ -10,14 +10,6 @@ namespace DevToys.Tools.SmartDetection; [DataTypeName(PredefinedCommonDataTypeNames.JsonArray, baseName: PredefinedCommonDataTypeNames.Json)] internal sealed partial class JsonArrayDataTypeDetector : IDataTypeDetector { - private readonly ILogger _logger; - - [ImportingConstructor] - public JsonArrayDataTypeDetector() - { - _logger = this.Log(); - } - public ValueTask TryDetectDataAsync( object data, DataDetectionResult? resultFromBaseDetector, diff --git a/src/app/dev/DevToys.Tools/Tools/Converters/Date/DateConverterGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Converters/Date/DateConverterGuiTool.cs index 9dfc356818..3b828f1ae0 100644 --- a/src/app/dev/DevToys.Tools/Tools/Converters/Date/DateConverterGuiTool.cs +++ b/src/app/dev/DevToys.Tools/Tools/Converters/Date/DateConverterGuiTool.cs @@ -82,7 +82,7 @@ private IUIDropDownListItem SelectedTimeZoneDropDownItem } set { - _settingsProvider.SetSetting(timeZoneIdSettings, value.Value!.ToString()); + _settingsProvider.SetSetting(timeZoneIdSettings, value.Value!.ToString() ?? string.Empty); } } diff --git a/src/app/dev/DevToys.Tools/Tools/Formatters/Json/JsonFormatterGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Formatters/Json/JsonFormatterGuiTool.cs index 54521353fc..383541a34f 100644 --- a/src/app/dev/DevToys.Tools/Tools/Formatters/Json/JsonFormatterGuiTool.cs +++ b/src/app/dev/DevToys.Tools/Tools/Formatters/Json/JsonFormatterGuiTool.cs @@ -106,7 +106,7 @@ public UIToolView View GridRow.Content, GridColumn.Content, SplitGrid() - .Vertical() + .Vertical() .WithLeftPaneChild( _inputTextArea .Title(JsonFormatter.Input) diff --git a/src/app/dev/DevToys.Tools/Tools/Generators/HashAndChecksum/HashAndChecksumGeneratorGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Generators/HashAndChecksum/HashAndChecksumGeneratorGuiTool.cs index 191fd34ffe..df2be30f13 100644 --- a/src/app/dev/DevToys.Tools/Tools/Generators/HashAndChecksum/HashAndChecksumGeneratorGuiTool.cs +++ b/src/app/dev/DevToys.Tools/Tools/Generators/HashAndChecksum/HashAndChecksumGeneratorGuiTool.cs @@ -353,7 +353,7 @@ string hash } } - private async Task ComputeHashFromStreamAsync( + private static async Task ComputeHashFromStreamAsync( Stream inputStream, HashAlgorithmType hashAlgorithm, bool uppercase, diff --git a/src/app/dev/DevToys.Tools/Tools/Text/EscapeUnescape/EscapeUnescapeGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Text/EscapeUnescape/EscapeUnescapeGuiTool.cs index 457a43bbfb..8c93648ee6 100644 --- a/src/app/dev/DevToys.Tools/Tools/Text/EscapeUnescape/EscapeUnescapeGuiTool.cs +++ b/src/app/dev/DevToys.Tools/Tools/Text/EscapeUnescape/EscapeUnescapeGuiTool.cs @@ -39,7 +39,6 @@ private enum GridColumns Stretch } - private readonly DisposableSemaphore _semaphore = new(); private readonly ILogger _logger; private readonly ISettingsProvider _settingsProvider; diff --git a/src/app/dev/platforms/desktop/DevToys.CLI/OptionToICommandLineToolMap.cs b/src/app/dev/platforms/desktop/DevToys.CLI/OptionToICommandLineToolMap.cs index 882583d255..8cb3b0aa3a 100644 --- a/src/app/dev/platforms/desktop/DevToys.CLI/OptionToICommandLineToolMap.cs +++ b/src/app/dev/platforms/desktop/DevToys.CLI/OptionToICommandLineToolMap.cs @@ -133,7 +133,7 @@ private static Option CreateOption( return option; } - private static Option CreateOneOfTypeOption( + private static OneOfOption CreateOneOfTypeOption( CommandLineOptionAttribute commandLineOptionAttribute, string optionName, string? optionDescription, diff --git a/src/app/tests/DevToys.UnitTests/Api/Core/ObservableHashSetTests.cs b/src/app/tests/DevToys.UnitTests/Api/Core/ObservableHashSetTests.cs index 91d7f32121..2abcaad21c 100644 --- a/src/app/tests/DevToys.UnitTests/Api/Core/ObservableHashSetTests.cs +++ b/src/app/tests/DevToys.UnitTests/Api/Core/ObservableHashSetTests.cs @@ -38,7 +38,7 @@ public void CanAdd() int collectionChanged = 0; int currentCount = 0; int countChange = 1; - string[] adding = Array.Empty(); + string[] adding = []; hashSet.PropertyChanging += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging); hashSet.PropertyChanged += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged); @@ -50,28 +50,28 @@ public void CanAdd() collectionChanged++; }; - adding = new[] { "Palmer" }; + adding = ["Palmer"]; hashSet.Add("Palmer").Should().BeTrue(); countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.Should().BeEquivalentTo(new[] { "Palmer" }); + hashSet.Should().BeEquivalentTo(["Palmer"]); - adding = new[] { "Carmack" }; + adding = ["Carmack"]; hashSet.Add("Carmack").Should().BeTrue(); countChanging.Should().Be(2); countChanged.Should().Be(2); collectionChanged.Should().Be(2); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Carmack", "Palmer" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Carmack", "Palmer"]); hashSet.Add("Palmer").Should().BeFalse(); countChanging.Should().Be(2); countChanged.Should().Be(2); collectionChanged.Should().Be(2); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Carmack", "Palmer" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Carmack", "Palmer"]); } [Fact] @@ -167,7 +167,7 @@ public void CanRemove() int collectionChanged = 0; int currentCount = 2; int countChange = -1; - string[] removing = Array.Empty(); + string[] removing = []; hashSet.PropertyChanging += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging); hashSet.PropertyChanged += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged); @@ -179,15 +179,15 @@ public void CanRemove() collectionChanged++; }; - removing = new[] { "Palmer" }; + removing = ["Palmer"]; hashSet.Remove("Palmer").Should().BeTrue(); countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.Should().BeEquivalentTo(new[] { "Carmack" }); + hashSet.Should().BeEquivalentTo(["Carmack"]); - removing = new[] { "Carmack" }; + removing = ["Carmack"]; hashSet.Remove("Carmack").Should().BeTrue(); countChanging.Should().Be(2); @@ -216,7 +216,7 @@ public void CanUnionWith() int collectionChanged = 0; int currentCount = 2; int countChange = 2; - string[] adding = new[] { "Brendan", "Nate" }; + string[] adding = ["Brendan", "Nate"]; hashSet.PropertyChanging += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging); hashSet.PropertyChanged += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged); @@ -233,14 +233,14 @@ public void CanUnionWith() countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Brendan", "Carmack", "Nate", "Palmer" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Brendan", "Carmack", "Nate", "Palmer"]); hashSet.UnionWith(new[] { "Brendan" }); countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Brendan", "Carmack", "Nate", "Palmer" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Brendan", "Carmack", "Nate", "Palmer"]); } [Fact] @@ -258,7 +258,7 @@ public void CanIntersectWith() int collectionChanged = 0; int currentCount = 4; int countChange = -2; - string[] removing = new[] { "Brendan", "Nate" }; + string[] removing = ["Brendan", "Nate"]; hashSet.PropertyChanging += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging); hashSet.PropertyChanged += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged); @@ -275,14 +275,14 @@ public void CanIntersectWith() countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Carmack", "Palmer" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Carmack", "Palmer"]); hashSet.IntersectWith(new[] { "Carmack", "Palmer", "Abrash" }); countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Carmack", "Palmer" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Carmack", "Palmer"]); } [Fact] @@ -300,7 +300,7 @@ public void CanExceptWith() int collectionChanged = 0; int currentCount = 4; int countChange = -2; - string[] removing = new[] { "Carmack", "Palmer" }; + string[] removing = ["Carmack", "Palmer"]; hashSet.PropertyChanging += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging); hashSet.PropertyChanged += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged); @@ -317,14 +317,14 @@ public void CanExceptWith() countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Brendan", "Nate" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Brendan", "Nate"]); hashSet.ExceptWith(new[] { "Abrash", "Carmack", "Palmer" }); countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Brendan", "Nate" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Brendan", "Nate"]); } [Fact] @@ -342,8 +342,8 @@ public void CanSymmetricalExceptWith() int collectionChanged = 0; int currentCount = 4; int countChange = -1; - string[] removing = new[] { "Carmack", "Palmer" }; - string[] adding = new[] { "Abrash" }; + string[] removing = ["Carmack", "Palmer"]; + string[] adding = ["Abrash"]; hashSet.PropertyChanging += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging); hashSet.PropertyChanged += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged); @@ -360,14 +360,14 @@ public void CanSymmetricalExceptWith() countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Abrash", "Brendan", "Nate" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Abrash", "Brendan", "Nate"]); hashSet.SymmetricExceptWith(Array.Empty()); countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Abrash", "Brendan", "Nate" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Abrash", "Brendan", "Nate"]); } [Fact] @@ -454,7 +454,7 @@ public void CanRemoveWithPredicate() int collectionChanged = 0; int currentCount = 4; int countChange = -2; - string[] removing = new[] { "Carmack", "Palmer" }; + string[] removing = ["Carmack", "Palmer"]; hashSet.PropertyChanging += (s, a) => AssertCountChanging(hashSet, s, a, currentCount, ref countChanging); hashSet.PropertyChanged += (s, a) => AssertCountChanged(hashSet, s, a, ref currentCount, countChange, ref countChanged); @@ -471,14 +471,14 @@ public void CanRemoveWithPredicate() countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Brendan", "Nate" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Brendan", "Nate"]); hashSet.RemoveWhere(i => i.Contains('m')).Should().Be(0); countChanging.Should().Be(1); countChanged.Should().Be(1); collectionChanged.Should().Be(1); - hashSet.OrderBy(i => i).Should().BeEquivalentTo(new[] { "Brendan", "Nate" }); + hashSet.OrderBy(i => i).Should().BeEquivalentTo(["Brendan", "Nate"]); } private static void AssertCountChanging( diff --git a/src/app/tests/DevToys.UnitTests/Blazor/Core/Helpers/CssBuilderTests.cs b/src/app/tests/DevToys.UnitTests/Blazor/Core/Helpers/CssBuilderTests.cs index b71682175a..ba83f283c1 100644 --- a/src/app/tests/DevToys.UnitTests/Blazor/Core/Helpers/CssBuilderTests.cs +++ b/src/app/tests/DevToys.UnitTests/Blazor/Core/Helpers/CssBuilderTests.cs @@ -31,7 +31,7 @@ public void ShouldBuildConditionalCssClasses() //arrange bool hasTwo = false; bool hasThree = true; - Func hasFive = () => false; + static bool hasFive() => false; //act string classToRender = new CssBuilder("item-one") @@ -50,7 +50,7 @@ public void ShouldBuildConditionalCssBuilderClasses() //arrange bool hasTwo = false; bool hasThree = true; - Func hasFive = () => false; + static bool hasFive() => false; //act string classToRender = new CssBuilder("item-one") @@ -86,7 +86,7 @@ public void ShouldBuildClassesWithFunc() { //arrange // Simulates Razor Components attribute splatting feature - IDictionary attributes = new Dictionary { { "class", "my-custom-class-1" } }; + var attributes = new Dictionary { { "class", "my-custom-class-1" } }; //act string classToRender = new CssBuilder("item-one") @@ -103,7 +103,7 @@ public void ShouldBuildClassesFromAttributes() { //arrange // Simulates Razor Components attribute splatting feature - IDictionary attributes = new Dictionary { { "class", "my-custom-class-1" } }; + var attributes = new Dictionary { { "class", "my-custom-class-1" } }; //act string classToRender = new CssBuilder("item-one") @@ -154,7 +154,7 @@ public void ShouldNotThrowNoKeyExceptionWithDictionary() { //arrange // Simulates Razor Components attribute splatting feature - IDictionary attributes = new Dictionary { { "foo", "bar" } }; + var attributes = new Dictionary { { "foo", "bar" } }; //act string classToRender = new CssBuilder("item-one") diff --git a/src/app/tests/DevToys.UnitTests/Api/Core/ExtensionOrdererTests.cs b/src/app/tests/DevToys.UnitTests/Core/ExtensionOrdererTests.cs similarity index 98% rename from src/app/tests/DevToys.UnitTests/Api/Core/ExtensionOrdererTests.cs rename to src/app/tests/DevToys.UnitTests/Core/ExtensionOrdererTests.cs index 87962e8887..16dce91a41 100644 --- a/src/app/tests/DevToys.UnitTests/Api/Core/ExtensionOrdererTests.cs +++ b/src/app/tests/DevToys.UnitTests/Core/ExtensionOrdererTests.cs @@ -1,4 +1,6 @@ -namespace DevToys.UnitTests.Api.Core; +using DevToys.Core; + +namespace DevToys.UnitTests.Core; public class ExtensionOrdererTests { diff --git a/src/app/tests/DevToys.UnitTests/Mocks/MockIFileStorage.cs b/src/app/tests/DevToys.UnitTests/Mocks/MockIFileStorage.cs index 1421dc8f94..cfc4ff3d8b 100644 --- a/src/app/tests/DevToys.UnitTests/Mocks/MockIFileStorage.cs +++ b/src/app/tests/DevToys.UnitTests/Mocks/MockIFileStorage.cs @@ -50,7 +50,7 @@ public ValueTask PickFolderAsync() throw new NotImplementedException(); } - public FileInfo CreateSelfDestroyingTempFile(string? desiredFileExtension = null) + public FileInfo CreateSelfDestroyingTempFile(string desiredFileExtension = null) { var assembly = Assembly.GetExecutingAssembly(); string assemblyDirectory = Path.GetDirectoryName(assembly.Location); diff --git a/src/app/tests/DevToys.UnitTests/Tools/Converters/DateConverterCommandLineToolTests.cs b/src/app/tests/DevToys.UnitTests/Tools/Converters/DateConverterCommandLineToolTests.cs index 099dd8d98c..be99af6418 100644 --- a/src/app/tests/DevToys.UnitTests/Tools/Converters/DateConverterCommandLineToolTests.cs +++ b/src/app/tests/DevToys.UnitTests/Tools/Converters/DateConverterCommandLineToolTests.cs @@ -303,5 +303,4 @@ public async Task ConvertValidTicksWithTicksFormatShouldReturnValidDateTime( string consoleOutput = _consoleWriter.ToString().Trim(); consoleOutput.Should().Be(exceptedDateTimeString); } - } diff --git a/src/app/tests/DevToys.UnitTests/Tools/Helpers/PasswordGeneratorHelperTests.cs b/src/app/tests/DevToys.UnitTests/Tools/Helpers/PasswordGeneratorHelperTests.cs index 2bf4ae6e15..017a960e27 100644 --- a/src/app/tests/DevToys.UnitTests/Tools/Helpers/PasswordGeneratorHelperTests.cs +++ b/src/app/tests/DevToys.UnitTests/Tools/Helpers/PasswordGeneratorHelperTests.cs @@ -12,7 +12,7 @@ public class PasswordGeneratorHelperTests [InlineData(100, true, true, true, true, null)] [InlineData(100, true, true, true, true, "bcdefghijklmnopqrstuvwxyz")] [InlineData(100, false, true, false, false, "bcdefghijklmnopqrstuvwxyz")] - internal void GeneratePassword(int length, bool hasUppercase, bool hasLowercase, bool hasNumber, bool hasSpecialCharacters, string? excludedCharacters) + internal void GeneratePassword(int length, bool hasUppercase, bool hasLowercase, bool hasNumber, bool hasSpecialCharacters, string excludedCharacters) { string password = PasswordGeneratorHelper.GeneratePassword( diff --git a/src/app/tests/DevToys.UnitTests/Tools/Helpers/UuidHelperTests.cs b/src/app/tests/DevToys.UnitTests/Tools/Helpers/UuidHelperTests.cs index 00e3ac57ae..30513f7628 100644 --- a/src/app/tests/DevToys.UnitTests/Tools/Helpers/UuidHelperTests.cs +++ b/src/app/tests/DevToys.UnitTests/Tools/Helpers/UuidHelperTests.cs @@ -24,10 +24,10 @@ string newUuid TestUuid(newUuid, hyphens, uppercase); } - private void TestUuid(string uuid, bool hyphens, bool uppercase) + private static void TestUuid(string uuid, bool hyphens, bool uppercase) { Guid.TryParse(uuid, out _).Should().BeTrue(); - uuid.Contains("-").Should().Be(hyphens); + uuid.Contains('-').Should().Be(hyphens); uuid.Length.Should().Be(hyphens ? 36 : 32); uuid.Should().Be(uppercase ? uuid.ToUpperInvariant() : uuid.ToLowerInvariant()); }