using ImpromptuInterface;
using System;
using System.Dynamic;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            dynamic expando = new ExpandoObject();
            expando.name = "cys";
            expando.Add = new Func<int, int>(i=> { return i; });
            var expando_result = expando.Add(1);
            Console.WriteLine(expando.GetType().Name);

            dynamic dobject = new BB { name="aaa" };
            var dobject_result =  dobject.ADD();
            dobject.Name = "cys";
            Console.WriteLine(dobject.Name);
            Console.WriteLine(dobject.GetType().Name);
        }
    }
    public class BB : DynamicObject
    {
        public string name { get; set; }
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            result = "a";
            return true;
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = name;
            return true;
        }
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            name = value.ToString();
            return true;
        }

    }
   
}

 

posted on 2019-01-04 10:09  chester·chen  阅读(1021)  评论(1编辑  收藏  举报