Skip to content
/ Merror Public

A simple C# Reflection wrapper to access to private class members.

License

Notifications You must be signed in to change notification settings

oika/Merror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Merror

A simple C# Reflection wrapper to access to private class members.

How to use

You can make a Reflector instance with the target type

var reflector = new Reflector(typeof(TargetClass));

or the target type name and another type in the target assembly when the target class isn't public.

var reflector = new Reflector("FooNameSpace.TargetClass", typeof(AnotherClass));

Get a static field value.

var val = reflector.GetStaticField("fieldName");

Create an instance, and invoke a method.

var paramOfConstructor = "abc";
var obj = reflector.NewInstance(paramOfConstructor);
var result = (int)reflector.Invoke(obj, "Sum", 123, 456);

In some cases, members not found with passed parameters. In that case, try to use ReflectorParam and Exact methods.

var paramOfConstructor = ReflectorParam.New<string>(null);
var obj = reflector.NewInstanceExact(paramOfConstructor);

var inParam1 = ReflectorParam.New(123);
var inParam2 = ReflectorParam.New(456);
var outParam = ReflectorParam.New(0, true);
reflector.InvokeExact(obj, "Sum", inParam1, inParam2, outParam);
var result = (int)outParam.Value;

About

A simple C# Reflection wrapper to access to private class members.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages