mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-30 00:10:36 +00:00
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Dynamic;
|
|||
|
using System.Reflection;
|
|||
|
|
|||
|
namespace Toolbox.Library
|
|||
|
{
|
|||
|
public class StaticDynamic : DynamicObject
|
|||
|
{
|
|||
|
private Type _type;
|
|||
|
public StaticDynamic(Type type) { _type = type; }
|
|||
|
|
|||
|
// Handle static properties
|
|||
|
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
|||
|
{
|
|||
|
PropertyInfo prop = _type.GetProperty(binder.Name, BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public);
|
|||
|
if (prop == null)
|
|||
|
{
|
|||
|
result = null;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
result = prop.GetValue(null, null);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
// Handle static methods
|
|||
|
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
|
|||
|
{
|
|||
|
MethodInfo method = _type.GetMethod(binder.Name, BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public);
|
|||
|
if (method == null)
|
|||
|
{
|
|||
|
result = null;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
result = method.Invoke(null, args);
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|