mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-07-29 17:37:44 -05:00
Fixed batch editor and database searches on properties of type DateTime?
This commit is contained in:
parent
43cf2370f2
commit
32ec5c392c
|
|
@ -11,13 +11,13 @@ internal static bool GetValueEquals(object obj, string propertyName, object valu
|
|||
{
|
||||
PropertyInfo pi = obj.GetType().GetProperty(propertyName);
|
||||
var v = pi.GetValue(obj, null);
|
||||
var c = Convert.ChangeType(value, pi.PropertyType);
|
||||
var c = ConvertValue(value, pi.PropertyType);
|
||||
return v.Equals(c);
|
||||
}
|
||||
internal static void SetValue(object obj, string propertyName, object value)
|
||||
{
|
||||
PropertyInfo pi = obj.GetType().GetProperty(propertyName);
|
||||
pi.SetValue(obj, Convert.ChangeType(value, pi.PropertyType), null);
|
||||
pi.SetValue(obj, ConvertValue(value, pi.PropertyType), null);
|
||||
}
|
||||
internal static object GetValue(object obj, string propertyName)
|
||||
{
|
||||
|
|
@ -38,5 +38,26 @@ internal static bool HasProperty(this Type type, string name)
|
|||
{
|
||||
return type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Any(p => p.Name == name);
|
||||
}
|
||||
|
||||
internal static object ConvertValue(object value, Type type)
|
||||
{
|
||||
if (type == typeof(DateTime?)) // Used for PKM.MetDate and other similar properties
|
||||
{
|
||||
DateTime dateValue;
|
||||
if (DateTime.TryParse(value.ToString(), out dateValue))
|
||||
{
|
||||
return new DateTime?(dateValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert.ChangeType is suitable for most things
|
||||
return Convert.ChangeType(value, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user