From a810a41dd3984161d222a073ff12c1cf235d3665 Mon Sep 17 00:00:00 2001 From: "mika@stocksharp.com" Date: Wed, 26 Feb 2025 15:25:06 +0300 Subject: [PATCH] Code cleanup. --- Common/OperatingSystemEx.cs | 5 ++--- Compilation.Python/PythonContext.cs | 5 ++--- Compilation/CompilationResult.cs | 2 +- Compilation/ICompilerExtensions.cs | 2 +- ComponentModel/IItemsSource.cs | 2 +- ComponentModel/ObservableCollectionEx.cs | 4 ++-- Configuration/ConfigManager.cs | 2 +- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Common/OperatingSystemEx.cs b/Common/OperatingSystemEx.cs index b70b3e9c..6e620999 100644 --- a/Common/OperatingSystemEx.cs +++ b/Common/OperatingSystemEx.cs @@ -41,11 +41,10 @@ public static bool IsOSPlatform(this OSPlatform platform) /// Gets all available operating system platforms defined in . /// public static IEnumerable Platforms => - typeof(OSPlatform) + [.. typeof(OSPlatform) .GetProperties() .Where(p => p.PropertyType == typeof(OSPlatform)) - .Select(p => (OSPlatform)p.GetValue(null)) - .ToArray(); + .Select(p => (OSPlatform)p.GetValue(null))]; /// /// Gets a value indicating whether the current runtime framework is .NET Framework. diff --git a/Compilation.Python/PythonContext.cs b/Compilation.Python/PythonContext.cs index 6a2ded61..9635aa2a 100644 --- a/Compilation.Python/PythonContext.cs +++ b/Compilation.Python/PythonContext.cs @@ -673,10 +673,9 @@ public object CreateInstance(params object[] args) public AssemblyImpl(ScriptEngine engine, IEnumerable types) { - _types = types + _types = [.. types .Where(t => t.GetUnderlyingSystemType()?.IsPythonType() == true) - .Select(t => new TypeImpl(this, t, engine)) - .ToArray(); + .Select(t => new TypeImpl(this, t, engine))]; } public override Type[] GetTypes() => GetExportedTypes(); diff --git a/Compilation/CompilationResult.cs b/Compilation/CompilationResult.cs index 1031fd22..42d5249d 100644 --- a/Compilation/CompilationResult.cs +++ b/Compilation/CompilationResult.cs @@ -14,7 +14,7 @@ public abstract class CompilationResult(IEnumerable errors) /// /// Gets the collection of compilation errors. /// - public IEnumerable Errors { get; } = errors.ToArray(); + public IEnumerable Errors { get; } = [.. errors]; /// /// Loads the compiled assembly using the provided compiler context. diff --git a/Compilation/ICompilerExtensions.cs b/Compilation/ICompilerExtensions.cs index 6d62b4c4..396862fd 100644 --- a/Compilation/ICompilerExtensions.cs +++ b/Compilation/ICompilerExtensions.cs @@ -88,7 +88,7 @@ public static (string name, byte[] body) ToRef(this string path) if (references is null) throw new ArgumentNullException(nameof(references)); - return (await references.Where(r => r.IsValid).Select(r => r.GetImages(cancellationToken)).WhenAll()).SelectMany(i => i).ToArray(); + return [.. (await references.Where(r => r.IsValid).Select(r => r.GetImages(cancellationToken)).WhenAll()).SelectMany(i => i)]; } /// diff --git a/ComponentModel/IItemsSource.cs b/ComponentModel/IItemsSource.cs index 2b334d76..37620f90 100644 --- a/ComponentModel/IItemsSource.cs +++ b/ComponentModel/IItemsSource.cs @@ -366,7 +366,7 @@ private IEnumerable> FilterItems(IEnumerable item.DisplayName, StringComparer.CurrentCultureIgnoreCase) : items.OrderByDescending(item => item.DisplayName, StringComparer.CurrentCultureIgnoreCase); - return items.ToArray(); + return [.. items]; } private IEnumerable> CreateItems(IEnumerable values) => FilterItems(values?.Select(CreateNewItem)); diff --git a/ComponentModel/ObservableCollectionEx.cs b/ComponentModel/ObservableCollectionEx.cs index db6c496c..93935a58 100644 --- a/ComponentModel/ObservableCollectionEx.cs +++ b/ComponentModel/ObservableCollectionEx.cs @@ -63,7 +63,7 @@ public virtual void AddRange(IEnumerable items) /// public virtual void RemoveRange(IEnumerable items) { - items = items.ToArray(); + items = [.. items]; if (items.Count() > 10000 || items.Count() > Count * 0.1) { @@ -264,7 +264,7 @@ protected void OnPropertyChanged(string propertyName) private void OnIndexerPropertyChanged() => OnPropertyChanged("Item[]"); private void OnCollectionChanged(NotifyCollectionChangedAction action, IList items, int index) => OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, (IList)items, index)); - private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index) => OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index)); + private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index) => OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index)); private void OnCollectionChanged(NotifyCollectionChangedAction action, object item, int index, int oldIndex) => OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, item, index, oldIndex)); private void OnCollectionChanged(NotifyCollectionChangedAction action, object oldItem, object newItem, int index) => OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, newItem, oldItem, index)); diff --git a/Configuration/ConfigManager.cs b/Configuration/ConfigManager.cs index 7a42737b..f841e57b 100644 --- a/Configuration/ConfigManager.cs +++ b/Configuration/ConfigManager.cs @@ -335,7 +335,7 @@ public static T GetService(string name) public static IEnumerable GetServices() { lock (_sync) - return GetDict().Values.Cast().Distinct().ToArray(); + return [.. GetDict().Values.Cast().Distinct()]; } } } \ No newline at end of file