网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C#属性绑定-创新互联

C#的反射明显的比AS3的反射要强很多啊。可以从外部访问到类的私有成员。举个例子:

在遂溪等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站制作、成都网站设计 网站设计制作按需定制开发,公司网站建设,企业网站建设,品牌网站建设,营销型网站建设,外贸营销网站建设,遂溪网站建设费用合理。
                Type _class = this.GetType();
                FieldInfo _field = _class.GetField(@fieldName, BindingFlags.Instance | BindingFlags.NonPublic);

枚举 : BindingFlags.NonPublic->非公共成员将包括在内进行搜索,意思就是private成员也可以搜索到。

在model中注册须发的主题(User)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BindLib.com;

namespace BindDemo.com.model
{
    public sealed class User : BaseDataModel
    {
        private int _hp = 1000;
        public int Hp
        {
            get { return _hp; }
            //绑定hp(血量)
            set { this.ChangeValue("Hp","_hp",value); }
        }

        private bool _isLive = false;

        public bool IsLive
        {
            get { return _isLive; }
            set { this.ChangeValue("IsLive", "_isLive", value); }
        }
    }
}

这的注意的是字段_hp和字段_isLive都是private(私用的): 这个和AS3绑定(见 AS3 属性绑定/上一篇)有很大的不同,这得益于C#可以从外部访问private

view中需要绑定(注册侦听)(UserView)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BindLib;

namespace BindDemo.com.model
{
    public sealed class UserView
    {
        public User user;
        private int _hp;
        public int Hp
        {
            set { 
                this._hp = value ;
                Console.WriteLine("血量 {0}", value);
            }
            get { return this._hp; }
        }
        public UserView()
        {
            user = new User();
            BindTools.BindProperty(this, "Hp", user, "Hp", true);
            BindTools.BindSetter(this.UpdateIsLive, user, "IsLive",true);
        }

        private void UpdateIsLive(bool @isLive)
        {
            Console.WriteLine(@isLive ? "活着" : "战死");
        }

    }
}

好了 , 具体参数意思可以参考(《AS3 属性绑定》篇,上篇)

测试:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BindDemo.com.model;

namespace BindDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            UserView _uM = new UserView();
            Console.WriteLine("获得hp : {0}" , _uM.Hp);
            User uR = _uM.user;
            uR.Hp = 89;
            Console.WriteLine("改变获得hp : {0}", _uM.Hp);
            Console.WriteLine("-------------------------------------------------");
            uR.IsLive = true;
            Console.WriteLine("#################################################");
            uR.IsLive = false;
            Console.ReadLine();
        }
    }
}

结果:

C# 属性绑定

附件:http://down.51cto.com/data/2366862

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


新闻标题:C#属性绑定-创新互联
本文网址:http://bjjierui.cn/article/jojoi.html

其他资讯