General uncontroversial cleanup:

- Made private methods static where possible (runtime can elide checking the object for null).
- Declared attribute classes as sealed (allows reflection on attributes to complete faster).
- Moved some static cctor's into field initializers (static cctor's are slower than static field initializers).
- Made classes static if they contained only static methods (can't create instances of useless objects).
- Use inferable Exts.Lazy and not new Lazy<T>().
- Added required STAThread attribute to CrashDialog.
- Removed unused parameters in private methods.
- Added Serializable attribute to exceptions.
- Added parameter name in calls to ArgumentNullException.
- Use of as operator instead of is + cast.
- Changed (x as Foo).Bar anti-pattern into ((Foo)x).Bar. Results in sensible cast exceptions on error rather than null dereferences.
- Removed unused method in NullShader.
This commit is contained in:
RoosterDragon
2014-05-23 11:07:41 +01:00
parent db08357e36
commit b733465f33
92 changed files with 177 additions and 179 deletions

View File

@@ -34,13 +34,13 @@ namespace OpenRA.Scripting
}
// For traitinfos that provide actor / player commands
public class ScriptPropertyGroupAttribute : Attribute
public sealed class ScriptPropertyGroupAttribute : Attribute
{
public readonly string Category;
public ScriptPropertyGroupAttribute(string category) { Category = category; }
}
public class ScriptActorPropertyActivityAttribute : Attribute { }
public sealed class ScriptActorPropertyActivityAttribute : Attribute { }
public abstract class ScriptActorProperties
{
@@ -75,7 +75,7 @@ namespace OpenRA.Scripting
}
}
public class ScriptGlobalAttribute : Attribute
public sealed class ScriptGlobalAttribute : Attribute
{
public readonly string Name;
public ScriptGlobalAttribute(string name) { Name = name; }

View File

@@ -49,23 +49,23 @@ namespace OpenRA.Scripting
public static string LuaDocString(this MemberInfo mi)
{
if (mi is MethodInfo)
var methodInfo = mi as MethodInfo;
if (methodInfo != null)
{
var methodInfo = mi as MethodInfo;
var parameters = methodInfo.GetParameters().Select(pi => pi.LuaDocString());
return "{0} {1}({2})".F(methodInfo.ReturnType.LuaDocString(), mi.Name, parameters.JoinWith(", "));
}
if (mi is PropertyInfo)
var propertyInfo = mi as PropertyInfo;
if (propertyInfo != null)
{
var pi = mi as PropertyInfo;
var types = new List<string>();
if (pi.GetGetMethod() != null)
if (propertyInfo.GetGetMethod() != null)
types.Add("get;");
if (pi.GetSetMethod() != null)
if (propertyInfo.GetSetMethod() != null)
types.Add("set;");
return "{0} {1} {{ {2} }}".F(pi.PropertyType.LuaDocString(), mi.Name, types.JoinWith(" "));
return "{0} {1} {{ {2} }}".F(propertyInfo.PropertyType.LuaDocString(), mi.Name, types.JoinWith(" "));
}
return "Unknown field: {0}".F(mi.Name);

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Scripting
if (!IsMethod)
throw new LuaException("Trying to invoke a ScriptMemberWrapper that isn't a method!");
var mi = Member as MethodInfo;
var mi = (MethodInfo)Member;
var pi = mi.GetParameters();
object[] clrArgs = new object[pi.Length];
@@ -71,7 +71,7 @@ namespace OpenRA.Scripting
throw new LuaException("Unable to convert parameter {0} to {1}".F(i, pi[i].ParameterType.Name));
}
var ret = (Member as MethodInfo).Invoke(Target, clrArgs);
var ret = (mi.Invoke(Target, clrArgs));
return ret.ToLuaValue(context);
}