Cache reflection calls when running utility lints and commands.

Reduces runtime of --check-yaml command to 70% of original.
This commit is contained in:
RoosterDragon
2023-03-28 19:04:14 +01:00
committed by Matthias Mailänder
parent 1a2aafa17c
commit 9dd4f938da
24 changed files with 116 additions and 87 deletions

View File

@@ -45,21 +45,16 @@ namespace OpenRA
return a.GetTypes().Select(t => t.Namespace).Distinct().Where(n => n != null);
}
public static bool HasAttribute<T>(this MemberInfo mi)
public static bool HasAttribute<TAttribute>(this MemberInfo mi)
where TAttribute : Attribute
{
return Attribute.IsDefined(mi, typeof(T));
return Attribute.IsDefined(mi, typeof(TAttribute));
}
public static T[] GetCustomAttributes<T>(this MemberInfo mi, bool inherit)
where T : class
public static TAttribute[] GetCustomAttributes<TAttribute>(this MemberInfo mi, bool inherit)
where TAttribute : Attribute
{
return (T[])mi.GetCustomAttributes(typeof(T), inherit);
}
public static T[] GetCustomAttributes<T>(this ParameterInfo mi)
where T : class
{
return (T[])mi.GetCustomAttributes(typeof(T), true);
return (TAttribute[])mi.GetCustomAttributes(typeof(TAttribute), inherit);
}
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>