首页 > 其他 > 详细

ExpandoObject与DynamicObject的使用

时间:2019-01-04 10:55:45      阅读:141      评论:0      收藏:0      [点我收藏+]
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;
        }

    }
   
}

 

ExpandoObject与DynamicObject的使用

原文:https://www.cnblogs.com/chenyishi/p/10218296.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!