Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasoukhov committed Feb 26, 2025
1 parent 12a5c9c commit a810a41
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions Common/OperatingSystemEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public static bool IsOSPlatform(this OSPlatform platform)
/// Gets all available operating system platforms defined in <see cref="OSPlatform"/>.
/// </summary>
public static IEnumerable<OSPlatform> 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))];

/// <summary>
/// Gets a value indicating whether the current runtime framework is .NET Framework.
Expand Down
5 changes: 2 additions & 3 deletions Compilation.Python/PythonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,9 @@ public object CreateInstance(params object[] args)

public AssemblyImpl(ScriptEngine engine, IEnumerable<PythonType> 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();
Expand Down
2 changes: 1 addition & 1 deletion Compilation/CompilationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class CompilationResult(IEnumerable<CompilationError> errors)
/// <summary>
/// Gets the collection of compilation errors.
/// </summary>
public IEnumerable<CompilationError> Errors { get; } = errors.ToArray();
public IEnumerable<CompilationError> Errors { get; } = [.. errors];

/// <summary>
/// Loads the compiled assembly using the provided compiler context.
Expand Down
2 changes: 1 addition & 1 deletion Compilation/ICompilerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ComponentModel/IItemsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private IEnumerable<IItemsSourceItem<T>> FilterItems(IEnumerable<IItemsSourceIte
items.OrderBy(item => item.DisplayName, StringComparer.CurrentCultureIgnoreCase) :
items.OrderByDescending(item => item.DisplayName, StringComparer.CurrentCultureIgnoreCase);

return items.ToArray();
return [.. items];
}

private IEnumerable<IItemsSourceItem<T>> CreateItems(IEnumerable<T> values) => FilterItems(values?.Select(CreateNewItem));
Expand Down
4 changes: 2 additions & 2 deletions ComponentModel/ObservableCollectionEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public virtual void AddRange(IEnumerable<TItem> items)
/// </summary>
public virtual void RemoveRange(IEnumerable<TItem> items)
{
items = items.ToArray();
items = [.. items];

if (items.Count() > 10000 || items.Count() > Count * 0.1)
{
Expand Down Expand Up @@ -264,7 +264,7 @@ protected void OnPropertyChanged(string propertyName)
private void OnIndexerPropertyChanged() => OnPropertyChanged("Item[]");

private void OnCollectionChanged(NotifyCollectionChangedAction action, IList<TItem> 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));

Expand Down
2 changes: 1 addition & 1 deletion Configuration/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public static T GetService<T>(string name)
public static IEnumerable<T> GetServices<T>()
{
lock (_sync)
return GetDict<T>().Values.Cast<T>().Distinct().ToArray();
return [.. GetDict<T>().Values.Cast<T>().Distinct()];
}
}
}

0 comments on commit a810a41

Please sign in to comment.