update
This commit is contained in:
@@ -308,9 +308,42 @@ namespace VTabs.Libs
|
||||
|
||||
|
||||
|
||||
public static T GetFieldValue<T>(this object o, string fieldName, bool exceptionIfNotFound = true) => (T)o.GetFieldValue(fieldName, exceptionIfNotFound);
|
||||
public static T GetPropertyValue<T>(this object o, string propertyName, bool exceptionIfNotFound = true) => (T)o.GetPropertyValue(propertyName, exceptionIfNotFound);
|
||||
public static T GetMemberValue<T>(this object o, string memberName, bool exceptionIfNotFound = true) => (T)o.GetMemberValue(memberName, exceptionIfNotFound);
|
||||
public static T GetFieldValue<T>(this object o, string fieldName, bool exceptionIfNotFound = true)
|
||||
{
|
||||
var val = o.GetFieldValue(fieldName, exceptionIfNotFound);
|
||||
if (val == null) return default;
|
||||
if (typeof(T) == typeof(List<int>) && val is System.Collections.IEnumerable ienum && !(val is List<int>))
|
||||
{
|
||||
var list = new List<int>();
|
||||
foreach (var item in ienum) { try { list.Add((int)(dynamic)item); } catch { list.Add(item.GetHashCode()); } }
|
||||
return (T)(object)list;
|
||||
}
|
||||
return (T)val;
|
||||
}
|
||||
public static T GetPropertyValue<T>(this object o, string propertyName, bool exceptionIfNotFound = true)
|
||||
{
|
||||
var val = o.GetPropertyValue(propertyName, exceptionIfNotFound);
|
||||
if (val == null) return default;
|
||||
if (typeof(T) == typeof(List<int>) && val is System.Collections.IEnumerable ienum && !(val is List<int>))
|
||||
{
|
||||
var list = new List<int>();
|
||||
foreach (var item in ienum) { try { list.Add((int)(dynamic)item); } catch { list.Add(item.GetHashCode()); } }
|
||||
return (T)(object)list;
|
||||
}
|
||||
return (T)val;
|
||||
}
|
||||
public static T GetMemberValue<T>(this object o, string memberName, bool exceptionIfNotFound = true)
|
||||
{
|
||||
var val = o.GetMemberValue(memberName, exceptionIfNotFound);
|
||||
if (val == null) return default;
|
||||
if (typeof(T) == typeof(List<int>) && val is System.Collections.IEnumerable ienum && !(val is List<int>))
|
||||
{
|
||||
var list = new List<int>();
|
||||
foreach (var item in ienum) { try { list.Add((int)(dynamic)item); } catch { list.Add(item.GetHashCode()); } }
|
||||
return (T)(object)list;
|
||||
}
|
||||
return (T)val;
|
||||
}
|
||||
public static T InvokeMethod<T>(this object o, string methodName, params object[] parameters) => (T)o.InvokeMethod(methodName, parameters);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user