Fix CA2263: Prefer generic overload when type is known

This commit is contained in:
Haselnussbomber 2025-10-24 02:52:13 +02:00
parent a8b8bce628
commit e34c480290
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
7 changed files with 9 additions and 32 deletions

View file

@ -23,23 +23,7 @@ public class PartyFinderSlot
/// <summary> /// <summary>
/// Gets a list of jobs that this slot is accepting. /// Gets a list of jobs that this slot is accepting.
/// </summary> /// </summary>
public IReadOnlyCollection<JobFlags> Accepting public IReadOnlyCollection<JobFlags> Accepting => this.listAccepting ??= Enum.GetValues<JobFlags>().Where(flag => this[flag]).ToArray();
{
get
{
if (this.listAccepting != null)
{
return this.listAccepting;
}
this.listAccepting = Enum.GetValues(typeof(JobFlags))
.Cast<JobFlags>()
.Where(flag => this[flag])
.ToArray();
return this.listAccepting;
}
}
/// <summary> /// <summary>
/// Tests if this slot is accepting a job. /// Tests if this slot is accepting a job.

View file

@ -16,14 +16,7 @@ public static class FontAwesomeHelpers
/// <returns>list of font awesome icons.</returns> /// <returns>list of font awesome icons.</returns>
public static List<FontAwesomeIcon> GetIcons() public static List<FontAwesomeIcon> GetIcons()
{ {
var icons = new List<FontAwesomeIcon>(); return [.. Enum.GetValues<FontAwesomeIcon>().Where(icon => !icon.IsObsolete())];
foreach (var icon in Enum.GetValues(typeof(FontAwesomeIcon)).Cast<FontAwesomeIcon>().ToList())
{
if (icon.IsObsolete()) continue;
icons.Add(icon);
}
return icons;
} }
/// <summary> /// <summary>

View file

@ -683,7 +683,7 @@ internal class DalamudInterface : IInternalDisposableService
if (ImGui.BeginMenu("Set log level..."u8)) if (ImGui.BeginMenu("Set log level..."u8))
{ {
foreach (var logLevel in Enum.GetValues(typeof(LogEventLevel)).Cast<LogEventLevel>()) foreach (var logLevel in Enum.GetValues<LogEventLevel>())
{ {
if (ImGui.MenuItem(logLevel + "##logLevelSwitch", (byte*)null, EntryPoint.LogLevelSwitch.MinimumLevel == logLevel)) if (ImGui.MenuItem(logLevel + "##logLevelSwitch", (byte*)null, EntryPoint.LogLevelSwitch.MinimumLevel == logLevel))
{ {

View file

@ -41,7 +41,7 @@ public unsafe partial class AddonTree
{ {
foreach (var t in from t in ClientStructsAssembly.GetTypes() foreach (var t in from t in ClientStructsAssembly.GetTypes()
where t.IsPublic where t.IsPublic
let xivAddonAttr = (AddonAttribute?)t.GetCustomAttribute(typeof(AddonAttribute), false) let xivAddonAttr = t.GetCustomAttribute<AddonAttribute>(false)
where xivAddonAttr != null where xivAddonAttr != null
where xivAddonAttr.AddonIdentifiers.Contains(this.AddonName) where xivAddonAttr.AddonIdentifiers.Contains(this.AddonName)
select t) select t)
@ -83,7 +83,7 @@ public unsafe partial class AddonTree
foreach (var field in baseType.GetFields(Static | Public | NonPublic | Instance)) foreach (var field in baseType.GetFields(Static | Public | NonPublic | Instance))
{ {
if (field.GetCustomAttribute(typeof(FieldOffsetAttribute)) is FieldOffsetAttribute offset) if (field.GetCustomAttribute<FieldOffsetAttribute>() is FieldOffsetAttribute offset)
{ {
try try
{ {

View file

@ -403,7 +403,7 @@ internal class ProfileManagerWidget
ImGui.Text(Locs.StartupBehavior); ImGui.Text(Locs.StartupBehavior);
if (ImGui.BeginCombo("##startupBehaviorPicker"u8, Locs.PolicyToLocalisedName(profile.StartupPolicy))) if (ImGui.BeginCombo("##startupBehaviorPicker"u8, Locs.PolicyToLocalisedName(profile.StartupPolicy)))
{ {
foreach (var policy in Enum.GetValues(typeof(ProfileModelV1.ProfileStartupPolicy)).Cast<ProfileModelV1.ProfileStartupPolicy>()) foreach (var policy in Enum.GetValues<ProfileModelV1.ProfileStartupPolicy>())
{ {
var name = Locs.PolicyToLocalisedName(policy); var name = Locs.PolicyToLocalisedName(policy);
if (ImGui.Selectable(name, profile.StartupPolicy == policy)) if (ImGui.Selectable(name, profile.StartupPolicy == policy))

View file

@ -292,7 +292,7 @@ public static class SafeMemory
return bytes; return bytes;
} }
public T Read<T>(int offset = 0) => (T)Marshal.PtrToStructure(this.hGlobal + offset, typeof(T)); public T Read<T>(int offset = 0) => Marshal.PtrToStructure<T>(this.hGlobal + offset);
public object? Read(Type type, int offset = 0) => Marshal.PtrToStructure(this.hGlobal + offset, type); public object? Read(Type type, int offset = 0) => Marshal.PtrToStructure(this.hGlobal + offset, type);

View file

@ -1116,8 +1116,8 @@ public static partial class Util
foreach (var f in obj.GetType() foreach (var f in obj.GetType()
.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance)) .GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance))
{ {
var fixedBuffer = (FixedBufferAttribute)f.GetCustomAttribute(typeof(FixedBufferAttribute)); var fixedBuffer = f.GetCustomAttribute<FixedBufferAttribute>();
var offset = (FieldOffsetAttribute)f.GetCustomAttribute(typeof(FieldOffsetAttribute)); var offset = f.GetCustomAttribute<FieldOffsetAttribute>();
if (fixedBuffer != null) if (fixedBuffer != null)
{ {