Add field helper

This commit is contained in:
BlubbFish 2019-12-25 23:48:26 +01:00
parent 65fdcdc12c
commit b4e17972b9

View File

@ -44,6 +44,17 @@ namespace BlubbFish.Utils {
} }
#endregion #endregion
#region FieldHelper
public static Object GetField(this Object o, String name) {
FieldInfo field = o.GetType().GetField(name);
return field.IsPublic ? field.GetValue(o) : null;
}
public static Object GetField(this Type o, String name) {
FieldInfo field = o.GetField(name);
return field.IsPublic ? field.GetValue(o) : null;
}
#endregion
#region InterfaceHelper #region InterfaceHelper
public static Boolean HasInterface(this Type o, Type interf) { public static Boolean HasInterface(this Type o, Type interf) {
foreach (Type item in o.GetInterfaces()) { foreach (Type item in o.GetInterfaces()) {