Use generic Enum methods

This commit is contained in:
Berkan Diler
2022-12-27 09:55:33 +01:00
parent c11f0ecd33
commit 67fa8d1553
11 changed files with 16 additions and 16 deletions

View File

@@ -14,7 +14,7 @@ namespace osu.Framework.Audio
/// </summary>
public class AudioAdjustments : IAdjustableAudioComponent
{
private static readonly AdjustableProperty[] all_adjustments = (AdjustableProperty[])Enum.GetValues(typeof(AdjustableProperty));
private static readonly AdjustableProperty[] all_adjustments = Enum.GetValues<AdjustableProperty>();
/// <summary>
/// The volume of this component.

View File

@@ -165,7 +165,7 @@ namespace osu.Framework.Graphics.Performance
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
ChildrenEnumerable =
from StatisticsCounterType t in Enum.GetValues(typeof(StatisticsCounterType))
from StatisticsCounterType t in Enum.GetValues<StatisticsCounterType>()
where monitor.ActiveCounters[(int)t]
select counterBars[t] = new CounterBar
{
@@ -212,7 +212,7 @@ namespace osu.Framework.Graphics.Performance
Spacing = new Vector2(5, 1),
Padding = new MarginPadding { Right = 5 },
ChildrenEnumerable =
from PerformanceCollectionType t in Enum.GetValues(typeof(PerformanceCollectionType))
from PerformanceCollectionType t in Enum.GetValues<PerformanceCollectionType>()
select legendMapping[(int)t] = new SpriteText
{
Colour = getColour(t),

View File

@@ -122,7 +122,7 @@ namespace osu.Framework.Graphics.Rendering
static Renderer()
{
var sources = Enum.GetValues(typeof(FlushBatchSource));
var sources = Enum.GetValues<FlushBatchSource>();
flush_source_statistics = new GlobalStatistic<int>[sources.Length];
foreach (FlushBatchSource source in sources)

View File

@@ -17,7 +17,7 @@ namespace osu.Framework.Graphics.Shaders
static GlobalPropertyManager()
{
var values = Enum.GetValues(typeof(GlobalProperty)).OfType<GlobalProperty>().ToArray();
var values = Enum.GetValues<GlobalProperty>();
global_properties = new IUniformMapping[values.Length];

View File

@@ -54,7 +54,7 @@ namespace osu.Framework.Graphics.Visualisation
Horizontal = 10,
Vertical = 5
},
Items = Enum.GetValues(typeof(Tab)).Cast<Tab>().ToList()
Items = Enum.GetValues<Tab>().ToList()
},
tabContentContainer = new Container
{

View File

@@ -152,7 +152,7 @@ namespace osu.Framework.Input
CurrentState = CreateInitialState();
RelativeSizeAxes = Axes.Both;
foreach (var button in Enum.GetValues(typeof(MouseButton)).Cast<MouseButton>())
foreach (var button in Enum.GetValues<MouseButton>())
{
var manager = CreateButtonEventManagerFor(button);
manager.RequestFocus = ChangeFocusFromClick;

View File

@@ -15,7 +15,7 @@ namespace osu.Framework.Input.States
/// <summary>
/// The maximum amount of touches this can handle.
/// </summary>
public static readonly int MAX_TOUCH_COUNT = Enum.GetValues(typeof(TouchSource)).Length;
public static readonly int MAX_TOUCH_COUNT = Enum.GetValues<TouchSource>().Length;
/// <summary>
/// The list of currently active touch sources.

View File

@@ -89,7 +89,7 @@ namespace osu.Framework.Logging
private readonly GlobalStatistic<int> logCount;
private static readonly HashSet<string> reserved_names = new HashSet<string>(Enum.GetNames(typeof(LoggingTarget)).Select(n => n.ToLowerInvariant()));
private static readonly HashSet<string> reserved_names = new HashSet<string>(Enum.GetNames<LoggingTarget>().Select(n => n.ToLowerInvariant()));
private Logger(LoggingTarget target = LoggingTarget.Runtime)
: this(target.ToString(), false)

View File

@@ -135,7 +135,7 @@ namespace osu.Framework.Platform
/// <summary>
/// Returns the window modes that the platform should support by default.
/// </summary>
protected virtual IEnumerable<WindowMode> DefaultSupportedWindowModes => Enum.GetValues(typeof(WindowMode)).OfType<WindowMode>();
protected virtual IEnumerable<WindowMode> DefaultSupportedWindowModes => Enum.GetValues<WindowMode>();
private Point position;

View File

@@ -39,13 +39,13 @@ namespace osu.Framework
if (OperatingSystem.IsWindows())
OS = Platform.Windows;
if (OperatingSystem.IsIOS())
OS = OS == 0 ? Platform.iOS : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.iOS)}, but is already {Enum.GetName(typeof(Platform), OS)}");
OS = OS == 0 ? Platform.iOS : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.iOS)}, but is already {Enum.GetName<Platform>(OS)}");
if (OperatingSystem.IsAndroid())
OS = OS == 0 ? Platform.Android : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.Android)}, but is already {Enum.GetName(typeof(Platform), OS)}");
OS = OS == 0 ? Platform.Android : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.Android)}, but is already {Enum.GetName<Platform>(OS)}");
if (OperatingSystem.IsMacOS())
OS = OS == 0 ? Platform.macOS : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.macOS)}, but is already {Enum.GetName(typeof(Platform), OS)}");
OS = OS == 0 ? Platform.macOS : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.macOS)}, but is already {Enum.GetName<Platform>(OS)}");
if (OperatingSystem.IsLinux())
OS = OS == 0 ? Platform.Linux : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.Linux)}, but is already {Enum.GetName(typeof(Platform), OS)}");
OS = OS == 0 ? Platform.Linux : throw new InvalidOperationException($"Tried to set OS Platform to {nameof(Platform.Linux)}, but is already {Enum.GetName<Platform>(OS)}");
if (OS == 0)
throw new PlatformNotSupportedException("Operating system could not be detected correctly.");

View File

@@ -15,8 +15,8 @@ namespace osu.Framework.Statistics
internal readonly List<int> GarbageCollections = new List<int>();
public double FramesPerSecond { get; set; }
internal static readonly int NUM_STATISTICS_COUNTER_TYPES = Enum.GetValues(typeof(StatisticsCounterType)).Length;
internal static readonly int NUM_PERFORMANCE_COLLECTION_TYPES = Enum.GetValues(typeof(PerformanceCollectionType)).Length;
internal static readonly int NUM_STATISTICS_COUNTER_TYPES = Enum.GetValues<StatisticsCounterType>().Length;
internal static readonly int NUM_PERFORMANCE_COLLECTION_TYPES = Enum.GetValues<PerformanceCollectionType>().Length;
internal static readonly long[] COUNTERS = new long[NUM_STATISTICS_COUNTER_TYPES];