diff --git a/OpenRA.Mods.Common/Lint/CheckActorReferences.cs b/OpenRA.Mods.Common/Lint/CheckActorReferences.cs index 1bbb6c611c..f59d51bf58 100644 --- a/OpenRA.Mods.Common/Lint/CheckActorReferences.cs +++ b/OpenRA.Mods.Common/Lint/CheckActorReferences.cs @@ -41,24 +41,10 @@ namespace OpenRA.Mods.Common.Lint } } - string[] GetFieldValues(ITraitInfo traitInfo, FieldInfo fieldInfo) - { - var type = fieldInfo.FieldType; - if (type == typeof(string)) - return new string[] { (string)fieldInfo.GetValue(traitInfo) }; - if (type == typeof(string[])) - return (string[])fieldInfo.GetValue(traitInfo); - - emitError("Bad type for reference on {0}.{1}. Supported types: string, string[]" - .F(traitInfo.GetType().Name, fieldInfo.Name)); - - return new string[] { }; - } - void CheckReference(ActorInfo actorInfo, ITraitInfo traitInfo, FieldInfo fieldInfo, IReadOnlyDictionary dict, string type) { - var values = GetFieldValues(traitInfo, fieldInfo); + var values = LintExts.GetFieldValues(traitInfo, fieldInfo, emitError); foreach (var v in values) if (v != null && !dict.ContainsKey(v.ToLowerInvariant())) emitError("{0}.{1}.{2}: Missing {3} `{4}`." diff --git a/OpenRA.Mods.Common/Lint/LintExts.cs b/OpenRA.Mods.Common/Lint/LintExts.cs new file mode 100644 index 0000000000..04dfecb045 --- /dev/null +++ b/OpenRA.Mods.Common/Lint/LintExts.cs @@ -0,0 +1,33 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Reflection; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Lint +{ + public class LintExts + { + public static string[] GetFieldValues(object ruleInfo, FieldInfo fieldInfo, Action emitError) + { + var type = fieldInfo.FieldType; + if (type == typeof(string)) + return new string[] { (string)fieldInfo.GetValue(ruleInfo) }; + if (type == typeof(string[])) + return (string[])fieldInfo.GetValue(ruleInfo); + + emitError("Bad type for reference on {0}.{1}. Supported types: string, string[]" + .F(ruleInfo.GetType().Name, fieldInfo.Name)); + + return new string[] { }; + } + } +} diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index e9a77ec2b8..88c7471ccc 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -186,6 +186,7 @@ +