实验了好久才弄出来,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()());

 

相关文章:

  • 2021-08-02
  • 2021-11-17
  • 2021-12-03
  • 2021-08-04
  • 2021-05-27
  • 2022-12-23
  • 2021-05-31
  • 2021-08-17
猜你喜欢
  • 2021-10-09
  • 2022-12-23
  • 2021-06-25
  • 2021-12-19
  • 2021-05-28
相关资源
相似解决方案