public void CompileNewClass() { var p = Expression.Parameter(typeof(string), "p"); var n = Expression.New(typeof(Gazonk).GetConstructor(new [] { typeof(string) }), p); var fgaz = Expression.Lambda <Func <string, Gazonk> > (n, p).Compile(); var g1 = new Gazonk("foo"); var g2 = new Gazonk("bar"); Assert.IsNotNull(g1); Assert.AreEqual(g1, fgaz("foo")); Assert.IsNotNull(g2); Assert.AreEqual(g2, fgaz("bar")); n = Expression.New(typeof(Bar)); var lbar = Expression.Lambda <Func <Bar> > (n).Compile(); var bar = lbar(); Assert.IsNotNull(bar); Assert.IsNull(bar.Value); }
public Foo() { Gazoo = new Gazonk(); Gaz = new Gazonk(); }