StyleCop clean FieldLoader
remove SA1510 for FileFormats
This commit is contained in:
@@ -11,9 +11,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
@@ -61,6 +61,7 @@ namespace OpenRA.FileFormats
|
|||||||
throw new InvalidOperationException("The field {0} has multiple definitions:\n{1}"
|
throw new InvalidOperationException("The field {0} has multiple definitions:\n{1}"
|
||||||
.F(fieldName, n.Select(m => "\t- " + m.Location).JoinWith("\n")));
|
.F(fieldName, n.Select(m => "\t- " + m.Location).JoinWith("\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidOperationException("TryGetValueFromYaml: unable to load field {0} (of type {1})".F(fieldName, fieldType));
|
throw new InvalidOperationException("TryGetValueFromYaml: unable to load field {0} (of type {1})".F(fieldName, fieldType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +104,7 @@ namespace OpenRA.FileFormats
|
|||||||
public static object GetValue(string field, Type fieldType, string x)
|
public static object GetValue(string field, Type fieldType, string x)
|
||||||
{
|
{
|
||||||
if (x != null) x = x.Trim();
|
if (x != null) x = x.Trim();
|
||||||
|
|
||||||
if (fieldType == typeof(int))
|
if (fieldType == typeof(int))
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
@@ -151,6 +153,7 @@ namespace OpenRA.FileFormats
|
|||||||
else if (fieldType == typeof(HSLColor))
|
else if (fieldType == typeof(HSLColor))
|
||||||
{
|
{
|
||||||
var parts = x.Split(',');
|
var parts = x.Split(',');
|
||||||
|
|
||||||
// Allow old ColorRamp format to be parsed as HSLColor
|
// Allow old ColorRamp format to be parsed as HSLColor
|
||||||
if (parts.Length == 3 || parts.Length == 4)
|
if (parts.Length == 3 || parts.Length == 4)
|
||||||
return new HSLColor(
|
return new HSLColor(
|
||||||
@@ -213,6 +216,7 @@ namespace OpenRA.FileFormats
|
|||||||
if (int.TryParse(x, out rr) && int.TryParse(x, out rp) && int.TryParse(x, out ry))
|
if (int.TryParse(x, out rr) && int.TryParse(x, out rp) && int.TryParse(x, out ry))
|
||||||
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
|
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
|
||||||
}
|
}
|
||||||
|
|
||||||
return InvalidValueAction(x, fieldType, field);
|
return InvalidValueAction(x, fieldType, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,11 +242,13 @@ namespace OpenRA.FileFormats
|
|||||||
ret.SetValue(GetValue(field, fieldType.GetElementType(), parts[i].Trim()), i);
|
ret.SetValue(GetValue(field, fieldType.GetElementType(), parts[i].Trim()), i);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(int2))
|
else if (fieldType == typeof(int2))
|
||||||
{
|
{
|
||||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
return new int2(int.Parse(parts[0]), int.Parse(parts[1]));
|
return new int2(int.Parse(parts[0]), int.Parse(parts[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(float2))
|
else if (fieldType == typeof(float2))
|
||||||
{
|
{
|
||||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -255,11 +261,13 @@ namespace OpenRA.FileFormats
|
|||||||
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
|
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
|
||||||
return new float2(xx, yy);
|
return new float2(xx, yy);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(Rectangle))
|
else if (fieldType == typeof(Rectangle))
|
||||||
{
|
{
|
||||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
return new Rectangle(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
|
return new Rectangle(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bits<>))
|
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bits<>))
|
||||||
{
|
{
|
||||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@@ -321,9 +329,9 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
internal Func<MiniYaml, object> LoaderFunc(FieldInfo field)
|
internal Func<MiniYaml, object> LoaderFunc(FieldInfo field)
|
||||||
{
|
{
|
||||||
const BindingFlags bf = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
|
const BindingFlags BindingFlag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
|
||||||
if (loaderFuncCache == null)
|
if (loaderFuncCache == null)
|
||||||
loaderFuncCache = (Func<MiniYaml, object>)Delegate.CreateDelegate( typeof( Func<MiniYaml, object> ), field.DeclaringType.GetMethod( Loader, bf ) );
|
loaderFuncCache = (Func<MiniYaml, object>)Delegate.CreateDelegate(typeof(Func<MiniYaml, object>), field.DeclaringType.GetMethod(Loader, BindingFlag));
|
||||||
return loaderFuncCache;
|
return loaderFuncCache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,9 +363,7 @@ namespace OpenRA.FileFormats
|
|||||||
var fields = o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
|
var fields = o.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
|
||||||
.Where(f => FormatValue(o, f) != FormatValue(from, f));
|
.Where(f => FormatValue(o, f) != FormatValue(from, f));
|
||||||
|
|
||||||
return new MiniYaml( null, fields.Select( f => new MiniYamlNode(
|
return new MiniYaml(null, fields.Select(f => new MiniYamlNode(f.Name, FormatValue(o, f))).ToList());
|
||||||
f.Name,
|
|
||||||
FormatValue( o, f ) ) ).ToList() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MiniYamlNode SaveField(object o, string field)
|
public static MiniYamlNode SaveField(object o, string field)
|
||||||
|
|||||||
@@ -252,6 +252,11 @@
|
|||||||
<BooleanProperty Name="Enabled">False</BooleanProperty>
|
<BooleanProperty Name="Enabled">False</BooleanProperty>
|
||||||
</RuleSettings>
|
</RuleSettings>
|
||||||
</Rule>
|
</Rule>
|
||||||
|
<Rule Name="ChainedStatementBlocksMustNotBePrecededByBlankLine">
|
||||||
|
<RuleSettings>
|
||||||
|
<BooleanProperty Name="Enabled">False</BooleanProperty>
|
||||||
|
</RuleSettings>
|
||||||
|
</Rule>
|
||||||
</Rules>
|
</Rules>
|
||||||
<AnalyzerSettings />
|
<AnalyzerSettings />
|
||||||
</Analyzer>
|
</Analyzer>
|
||||||
|
|||||||
Reference in New Issue
Block a user