mirror of
https://gitgud.io/lutepickle/rjw_menstruation.git
synced 2024-08-14 22:46:52 +00:00
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
|
using System;
|
|||
|
using System.Reflection;
|
|||
|
|
|||
|
namespace RJW_Menstruation
|
|||
|
{
|
|||
|
public static class Reflector
|
|||
|
{
|
|||
|
public static object GetMemberValue(this Type type, string name)
|
|||
|
{
|
|||
|
BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
|
|||
|
FieldInfo fieldInfo = type?.GetField(name, flags);
|
|||
|
return fieldInfo?.GetValue(null);
|
|||
|
}
|
|||
|
|
|||
|
public static object GetMemberValue(this object obj, string name)
|
|||
|
{
|
|||
|
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|||
|
FieldInfo fieldInfo = obj?.GetType().GetField(name, flags);
|
|||
|
return fieldInfo?.GetValue(obj);
|
|||
|
}
|
|||
|
|
|||
|
public static object GetPropertyValue(this Type type, string name)
|
|||
|
{
|
|||
|
BindingFlags flags = BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|||
|
PropertyInfo propertyInfo = type?.GetProperty(name, flags);
|
|||
|
return propertyInfo?.GetValue(null);
|
|||
|
}
|
|||
|
|
|||
|
public static object GetPropertyValue(this object obj, string name)
|
|||
|
{
|
|||
|
BindingFlags flags = BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|||
|
PropertyInfo propertyInfo = obj?.GetType().GetProperty(name, flags);
|
|||
|
return propertyInfo?.GetValue(obj);
|
|||
|
}
|
|||
|
|
|||
|
public static void SetMemberValue(this Type type, string name, object value)
|
|||
|
{
|
|||
|
BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
|
|||
|
FieldInfo fieldInfo = type?.GetField(name, flags);
|
|||
|
if (fieldInfo != null)
|
|||
|
{
|
|||
|
fieldInfo.SetValue(null, value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static void SetMemberValue(this object obj, string name, object value)
|
|||
|
{
|
|||
|
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|||
|
FieldInfo fieldInfo = obj?.GetType().GetField(name, flags);
|
|||
|
if (fieldInfo != null)
|
|||
|
{
|
|||
|
fieldInfo.SetValue(obj, value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|