Skip to content

Latest commit

 

History

History
32 lines (28 loc) · 1.08 KB

README.md

File metadata and controls

32 lines (28 loc) · 1.08 KB

Version
Utility methods for System.Linq.Expressions and objects. The main goal of the package is reducing usage of the reflection code.

PropertyOf

Access properties of an onject by the property names.

object obj = new MyClass();

// Get a property MyProp which is a string
var prop = PropertyOf.Get<string>(obj, "MyProp");

// Set a property MyProp which is a string
PropertyOf.Set(obj, "MyProp", "new value");

CastTo

Cast an object to another type

var obj = new MyDerivedClass();
var baseObj = CastTo<MyBaseClass>.From(obj);

MethodOf

Invoke methods of an object by the method names.

object obj = new MyClass();

// Invoke a method without parameters
var result = MethodOf.Invoke<string>(obj, "GetStringValue");

// Invoke a method with parameters
var result = MethodOf.Invoke<string>(obj, "GetStringValue", "input1", 123);

Limitations

  • Utility MethodOf will probably fail with overloaded methods because of simple caching keys.