Replace CntrlComparison with LeafGasComparison

This commit is contained in:
2016-04-22 11:18:21 -04:00
parent 9e25521034
commit 8f5cbfe3db
20 changed files with 398 additions and 193 deletions
+24
View File
@@ -132,6 +132,7 @@ namespace LeafWeb.Core.Utility
return string.IsNullOrEmpty(value) || value == "NA" || value == "-9999";
}
// TODO: this call maybe could be cached
private static PropertyInfo MatchProperty(PropertyInfo[] properties, string title, int position)
{
return
@@ -139,6 +140,7 @@ namespace LeafWeb.Core.Utility
properties.FirstOrDefault(p => p.Attribute<ParseInfoAttribute>().IsPositionMatch(position));
}
// TODO: this call maybe could be cached
private static PropertyInfo MatchPropertyExact(PropertyInfo[] properties, string title, int position)
{
return
@@ -180,6 +182,7 @@ namespace LeafWeb.Core.Utility
{
// http://stackoverflow.com/questions/3531318/convert-changetype-fails-on-nullable-types
var t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
value = HandleBoolEncodedProperty(property, value);
// convertedValue = Convert.ChangeType(value, t);
var converter = TypeDescriptor.GetConverter(t);
convertedValue = converter.ConvertTo(value, t);
@@ -191,5 +194,26 @@ namespace LeafWeb.Core.Utility
}
return true;
}
private static object HandleBoolEncodedProperty(PropertyInfo property, object value)
{
var boolEncodedPosition = property.Attribute<ParseInfoAttribute>().BoolEncodedPosition;
if (boolEncodedPosition == null) return value;
var v = (value as string)?.Substring(boolEncodedPosition.Value -1, 1);
switch (v)
{
// these values are False=1, True=2
case "1":
value = false;
break;
case "2":
value = true;
break;
default:
throw new ArgumentOutOfRangeException($"{property.Name} {boolEncodedPosition} {value} {v}");
}
return value;
}
}
}