Cache reflection calls when running utility lints and commands.
Reduces runtime of --check-yaml command to 70% of original.
This commit is contained in:
committed by
Matthias Mailänder
parent
1a2aafa17c
commit
9dd4f938da
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
var interfaces = implementingType.GetInterfaces();
|
||||
foreach (var interfaceType in interfaces)
|
||||
{
|
||||
if (!interfaceType.HasAttribute<RequireExplicitImplementationAttribute>())
|
||||
if (!Utility.HasAttribute<RequireExplicitImplementationAttribute>(interfaceType))
|
||||
continue;
|
||||
|
||||
var interfaceMembers = interfaceType.GetMembers();
|
||||
|
||||
@@ -41,10 +41,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
sections.Add("Launch", new LaunchArguments(new Arguments(Array.Empty<string>())));
|
||||
foreach (var section in sections.OrderBy(s => s.Key))
|
||||
{
|
||||
var fields = section.Value.GetType().GetFields();
|
||||
var fields = Utility.GetFields(section.Value.GetType());
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (!field.HasAttribute<DescAttribute>())
|
||||
if (!Utility.HasAttribute<DescAttribute>(field))
|
||||
continue;
|
||||
|
||||
Console.WriteLine(".TP");
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
else
|
||||
Console.WriteLine();
|
||||
|
||||
var lines = field.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines);
|
||||
var lines = Utility.GetCustomAttributes<DescAttribute>(field, false).SelectMany(d => d.Lines);
|
||||
foreach (var line in lines)
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
foreach (var t in globalTables)
|
||||
{
|
||||
var name = t.GetCustomAttributes<ScriptGlobalAttribute>(true).First().Name;
|
||||
var name = Utility.GetCustomAttributes<ScriptGlobalAttribute>(t, true).First().Name;
|
||||
Console.WriteLine("---Global variable provided by the game scripting engine.");
|
||||
|
||||
foreach (var obsolete in t.GetCustomAttributes(false).OfType<ObsoleteAttribute>())
|
||||
@@ -191,9 +191,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
var body = "";
|
||||
|
||||
if (member.HasAttribute<DescAttribute>())
|
||||
if (Utility.HasAttribute<DescAttribute>(member))
|
||||
{
|
||||
var lines = member.GetCustomAttributes<DescAttribute>(true).First().Lines;
|
||||
var lines = Utility.GetCustomAttributes<DescAttribute>(member, true).First().Lines;
|
||||
foreach (var line in lines)
|
||||
Console.WriteLine($" --- {line}");
|
||||
}
|
||||
@@ -258,11 +258,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
Console.WriteLine();
|
||||
|
||||
var isActivity = memberInfo.HasAttribute<ScriptActorPropertyActivityAttribute>();
|
||||
var isActivity = Utility.HasAttribute<ScriptActorPropertyActivityAttribute>(memberInfo);
|
||||
|
||||
if (memberInfo.HasAttribute<DescAttribute>())
|
||||
if (Utility.HasAttribute<DescAttribute>(memberInfo))
|
||||
{
|
||||
var lines = memberInfo.GetCustomAttributes<DescAttribute>(true).First().Lines;
|
||||
var lines = Utility.GetCustomAttributes<DescAttribute>(memberInfo, true).First().Lines;
|
||||
foreach (var line in lines)
|
||||
Console.WriteLine($" --- {line}");
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
foreach (var t in tables)
|
||||
{
|
||||
var name = t.GetCustomAttributes<ScriptGlobalAttribute>(true).First().Name;
|
||||
var name = Utility.GetCustomAttributes<ScriptGlobalAttribute>(t, true).First().Name;
|
||||
var members = ScriptMemberWrapper.WrappableMembers(t);
|
||||
|
||||
Console.WriteLine();
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Console.WriteLine("|---------:|-------------|");
|
||||
foreach (var m in members.OrderBy(m => m.Name))
|
||||
{
|
||||
var desc = m.HasAttribute<DescAttribute>() ? m.GetCustomAttributes<DescAttribute>(true).First().Lines.JoinWith("<br />") : "";
|
||||
var desc = Utility.HasAttribute<DescAttribute>(m) ? Utility.GetCustomAttributes<DescAttribute>(m, true).First().Lines.JoinWith("<br />") : "";
|
||||
Console.WriteLine($"| **{m.LuaDocString()}** | {desc} |");
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
var actorCategories = utility.ModData.ObjectCreator.GetTypesImplementing<ScriptActorProperties>().SelectMany(cg =>
|
||||
{
|
||||
var catAttr = cg.GetCustomAttributes<ScriptPropertyGroupAttribute>(false).FirstOrDefault();
|
||||
var catAttr = Utility.GetCustomAttributes<ScriptPropertyGroupAttribute>(cg, false).FirstOrDefault();
|
||||
var category = catAttr != null ? catAttr.Category : "Unsorted";
|
||||
|
||||
var required = ScriptMemberWrapper.RequiredTraitNames(cg);
|
||||
@@ -106,9 +106,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
var mi = property.mi;
|
||||
var required = property.required;
|
||||
var hasDesc = mi.HasAttribute<DescAttribute>();
|
||||
var hasDesc = Utility.HasAttribute<DescAttribute>(mi);
|
||||
var hasRequires = required.Length > 0;
|
||||
var isActivity = mi.HasAttribute<ScriptActorPropertyActivityAttribute>();
|
||||
var isActivity = Utility.HasAttribute<ScriptActorPropertyActivityAttribute>(mi);
|
||||
|
||||
Console.Write($"| **{mi.LuaDocString()}**");
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Console.Write(" | ");
|
||||
|
||||
if (hasDesc)
|
||||
Console.Write(mi.GetCustomAttributes<DescAttribute>(false).First().Lines.JoinWith("<br />"));
|
||||
Console.Write(Utility.GetCustomAttributes<DescAttribute>(mi, false).First().Lines.JoinWith("<br />"));
|
||||
|
||||
if (hasDesc && hasRequires)
|
||||
Console.Write("<br />");
|
||||
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
var playerCategories = utility.ModData.ObjectCreator.GetTypesImplementing<ScriptPlayerProperties>().SelectMany(cg =>
|
||||
{
|
||||
var catAttr = cg.GetCustomAttributes<ScriptPropertyGroupAttribute>(false).FirstOrDefault();
|
||||
var catAttr = Utility.GetCustomAttributes<ScriptPropertyGroupAttribute>(cg, false).FirstOrDefault();
|
||||
var category = catAttr != null ? catAttr.Category : "Unsorted";
|
||||
|
||||
var required = ScriptMemberWrapper.RequiredTraitNames(cg);
|
||||
@@ -155,9 +155,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
var mi = property.mi;
|
||||
var required = property.required;
|
||||
var hasDesc = mi.HasAttribute<DescAttribute>();
|
||||
var hasDesc = Utility.HasAttribute<DescAttribute>(mi);
|
||||
var hasRequires = required.Length > 0;
|
||||
var isActivity = mi.HasAttribute<ScriptActorPropertyActivityAttribute>();
|
||||
var isActivity = Utility.HasAttribute<ScriptActorPropertyActivityAttribute>(mi);
|
||||
|
||||
Console.Write($"| **{mi.LuaDocString()}**");
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Console.Write(" | ");
|
||||
|
||||
if (hasDesc)
|
||||
Console.Write(mi.GetCustomAttributes<DescAttribute>(false).First().Lines.JoinWith("<br />"));
|
||||
Console.Write(Utility.GetCustomAttributes<DescAttribute>(mi, false).First().Lines.JoinWith("<br />"));
|
||||
|
||||
if (hasDesc && hasRequires)
|
||||
Console.Write("<br />");
|
||||
|
||||
@@ -59,8 +59,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
sections.Add("Launch", new LaunchArguments(new Arguments(Array.Empty<string>())));
|
||||
foreach (var section in sections.OrderBy(s => s.Key))
|
||||
{
|
||||
var fields = section.Value.GetType().GetFields();
|
||||
if (fields.Any(field => field.GetCustomAttributes<DescAttribute>(false).Length > 0))
|
||||
var fields = Utility.GetFields(section.Value.GetType());
|
||||
if (fields.Any(field => Utility.GetCustomAttributes<DescAttribute>(field, false).Length > 0))
|
||||
{
|
||||
Console.WriteLine($"## {section.Key}");
|
||||
if (section.Key == "Launch")
|
||||
@@ -72,11 +72,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (!field.HasAttribute<DescAttribute>())
|
||||
if (!Utility.HasAttribute<DescAttribute>(field))
|
||||
continue;
|
||||
|
||||
Console.WriteLine($"### {field.Name}");
|
||||
var lines = field.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines);
|
||||
var lines = Utility.GetCustomAttributes<DescAttribute>(field, false).SelectMany(d => d.Lines);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
Console.WriteLine(line);
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
type.Namespace,
|
||||
type.Name,
|
||||
Description = string.Join(" ", type.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines)),
|
||||
Description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(type, false).SelectMany(d => d.Lines)),
|
||||
InheritedTypes = type.BaseTypes()
|
||||
.Select(y => y.Name)
|
||||
.Where(y => y != type.Name && y != "Object"),
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
.Where(fi => fi.FieldType.IsGenericType && fi.FieldType.GetGenericTypeDefinition() == typeof(SpriteSequenceField<>))
|
||||
.Select(fi =>
|
||||
{
|
||||
var description = string.Join(" ", fi.GetCustomAttributes<DescAttribute>(false)
|
||||
var description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(fi, false)
|
||||
.SelectMany(d => d.Lines));
|
||||
|
||||
var valueType = fi.FieldType.GetGenericArguments()[0];
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
type.Namespace,
|
||||
Name = type.Name.EndsWith("Info") ? type.Name.Substring(0, type.Name.Length - 4) : type.Name,
|
||||
Description = string.Join(" ", type.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines)),
|
||||
Description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(type, false).SelectMany(d => d.Lines)),
|
||||
RequiresTraits = RequiredTraitTypes(type)
|
||||
.Select(y => y.Name),
|
||||
InheritedTypes = type.BaseTypes()
|
||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
DefaultValue = FieldSaver.SaveField(objectCreator.CreateBasic(type), fi.Field.Name).Value.Value,
|
||||
InternalType = Util.InternalTypeName(fi.Field.FieldType),
|
||||
UserFriendlyType = Util.FriendlyTypeName(fi.Field.FieldType),
|
||||
Description = string.Join(" ", fi.Field.GetCustomAttributes<DescAttribute>(true).SelectMany(d => d.Lines)),
|
||||
Description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(fi.Field, true).SelectMany(d => d.Lines)),
|
||||
OtherAttributes = fi.Field.CustomAttributes
|
||||
.Where(a => a.AttributeType.Name != nameof(DescAttribute) && a.AttributeType.Name != nameof(FieldLoader.LoadUsingAttribute))
|
||||
.Select(a =>
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
type.Namespace,
|
||||
Name = type.Name.EndsWith("Info") ? type.Name.Substring(0, type.Name.Length - 4) : type.Name,
|
||||
Description = string.Join(" ", type.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines)),
|
||||
Description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(type, false).SelectMany(d => d.Lines)),
|
||||
InheritedTypes = type.BaseTypes()
|
||||
.Select(y => y.Name)
|
||||
.Where(y => y != type.Name && y != $"{type.Name}Info" && y != "Object"),
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
DefaultValue = FieldSaver.SaveField(objectCreator.CreateBasic(type), fi.Field.Name).Value.Value,
|
||||
InternalType = Util.InternalTypeName(fi.Field.FieldType),
|
||||
UserFriendlyType = Util.FriendlyTypeName(fi.Field.FieldType),
|
||||
Description = string.Join(" ", fi.Field.GetCustomAttributes<DescAttribute>(true).SelectMany(d => d.Lines)),
|
||||
Description = string.Join(" ", Utility.GetCustomAttributes<DescAttribute>(fi.Field, true).SelectMany(d => d.Lines)),
|
||||
OtherAttributes = fi.Field.CustomAttributes
|
||||
.Where(a => a.AttributeType.Name != nameof(DescAttribute) && a.AttributeType.Name != nameof(FieldLoader.LoadUsingAttribute))
|
||||
.Select(a =>
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
var tables = utility.ModData.ObjectCreator.GetTypesImplementing<ScriptGlobal>().OrderBy(t => t.Name);
|
||||
foreach (var t in tables)
|
||||
{
|
||||
var name = t.GetCustomAttributes<ScriptGlobalAttribute>(true).First().Name;
|
||||
var name = Utility.GetCustomAttributes<ScriptGlobalAttribute>(t, true).First().Name;
|
||||
Console.WriteLine(" " + name + " = {");
|
||||
Console.WriteLine(" type = \"class\",");
|
||||
Console.WriteLine(" childs = {");
|
||||
@@ -64,9 +64,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (propertyInfo != null)
|
||||
Console.WriteLine(" type = \"value\",");
|
||||
|
||||
if (member.HasAttribute<DescAttribute>())
|
||||
if (Utility.HasAttribute<DescAttribute>(member))
|
||||
{
|
||||
var desc = member.GetCustomAttributes<DescAttribute>(true).First().Lines.JoinWith("\n");
|
||||
var desc = Utility.GetCustomAttributes<DescAttribute>(member, true).First().Lines.JoinWith("\n");
|
||||
Console.WriteLine(" description = [[{0}]],", desc);
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (propertyInfo != null)
|
||||
Console.WriteLine(" type = \"value\",");
|
||||
|
||||
if (property.HasAttribute<DescAttribute>())
|
||||
if (Utility.HasAttribute<DescAttribute>(property))
|
||||
{
|
||||
var desc = property.GetCustomAttributes<DescAttribute>(true).First().Lines.JoinWith("\n");
|
||||
var desc = Utility.GetCustomAttributes<DescAttribute>(property, true).First().Lines.JoinWith("\n");
|
||||
Console.WriteLine(" description = [[{0}]],", desc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user