实验了好久才弄出来,msdn上怎么就不给下示例。。。

            var eo = new System.Dynamic.ExpandoObject();
            dynamic o = eo;
            o.hello = "world";
            var oDynamic = Expression.Lambda<Func<string>>(
                Expression.MakeDynamic(
                    typeof(Func<System.Runtime.CompilerServices.CallSite, object, string>),
                    Microsoft.CSharp.RuntimeBinder.Binder.Convert(0, typeof(string), typeof(Program)),
                    Expression.MakeDynamic(typeof(Func<System.Runtime.CompilerServices.CallSite, object, object>),
                        Microsoft.CSharp.RuntimeBinder.Binder.GetMember(
                            Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.None,
                            "hello",
                            typeof(Program),
                            new Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo[] { Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(0, null) }),
                        Expression.Constant(eo)
                    )
                )
            );
            Console.WriteLine(oDynamic.Compile()());

 

posted on 2013-03-04 16:52  Zhenway  阅读(606)  评论(0编辑  收藏  举报