Project Description

Do reflection very easily and fluently and Emit (in future)

Install

via NuGet https://nuget.org/packages/ElasticReflection/

Example

using ElasticReflection;

Instance directly
string s = "hi";
object length = s.Property("Length").Get();
s.Property("Length").Set(5); //thorws exception

s.Method("Substring"); //returns enumeration for the 2 overloads
var s1 = s.Method("Substring").Call(0) as string; //Call parameters match first overload
var s2 = s.Method("Substring").Call(0,1) as string; //Match second overload

s.Event("event name").Add(delegate)


via type object (statics)
var T = typeof (string).ToElastic();
T.Property("property name").Get();
T.Property("property name").Set(value);

T.Instance = "asd"; //Provide instance for non static member access

T.Method("method name"); //enumeration
T.Event("event name");

Generics
instanceHasGenericMethod.Method("Add", typeof (int) ).Call();//notice typeof (int)


Enumrable
var array = new Point[]{new Point(), new Point()};
array.Bulk().Property("x").Set(1); //make all x properties of all items 1

array.Bulk().Property("x").Set(new Func<int>(() => { return 0; })()); all x are back to 0
array.Bulk(p=>p.x++).Bulk(p=>p.x++); //all x are now 2

Beta Elastic Emit for dynamic type creation

var Asm = ElasticEmit.Assembly("dAsm", "Mod") //dynamic asembly
                       .DefineType("type1")
                              .DefineMethod<Func<int, int, int>>("Add", (a, b) => a + b)
                                    .Parameter( typeof(int))
                                    .Parameter( typeof(int))
                                    .Return(typeof(int))
                              .End()
                              .DefineProperty<int>("Length", () => 3, a => null)
                       .End()
                 .End();

var type1 = Asm.GetTypes().First().ToElastic();

var result = (int)type1.Method("Add").Call(1, 2);