Ejemplo n.º 1
0
        /// <summary>
        /// 销毁时清理watchTable
        /// </summary>
        private void OnDestroy()
        {
            //如果当前的物体是动态创建,则释放其使用的动态id
            DynamicIdSupport.ReleaseUsedId(DataEntity.objectID);

            watchTable.Dispose();
            RestoreSystem.RemoveDataModel(DataEntity.objectID);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 重新绑定实体对象
        /// </summary>
        /// <param name="entity"></param>
        public void Rebinding(BaseDataModelEntity entity)
        {
            //如果绑定对象为空则返回
            if (entity == null)
            {
                return;
            }

            //如果绑定对象为空实体则返回
            if (entity is EmptyEntity)
            {
                return;
            }

            //取消绑定、Watch、初始化状态
            RestoreSystem.RemoveDataModel(DataEntity.objectID);

            _bindingTable.Reset();
            isViewInitialized = false;

            //重新设置实体对象并监听实体对象
            this.DataEntity = entity;

            //当entity的ID为-1时表示对象为新创建对象,
            //此时需要生成一个ID
            if (entity.objectID == -1)
            {
                // this.DataEntity.objectID = ObjectIdentity.GenerateRuntimeId().id;
                //注册动态id,并添加到存储字典中
                DynamicIds.SetId(this);
            }

            //重监听
            ReWatch(this);

            //根据继承类属性和字段的Binding注解添加绑定条目
            PropertyInfo[] pInfos = this.GetType().GetProperties();
            FieldInfo[]    fInfos = this.GetType().GetFields();
            //获取公有属性

            foreach (PropertyInfo info in pInfos)
            {
                Binding attr = info.GetCustomAttribute <Binding>();
                if (attr == null)
                {
                    continue;
                }
                _bindingTable.AddItem(this.DataEntity, attr.EntityPropertyName, info.GetValue(this), "Value");
            }
            //获取公有字段
            foreach (FieldInfo info in fInfos)
            {
                Binding attr = info.GetCustomAttribute <Binding>();
                if (attr == null)
                {
                    continue;
                }
                _bindingTable.AddItem(this.DataEntity, attr.EntityPropertyName, info.GetValue(this), "Value");
            }

            //执行绑定过程
            List <BindingItem> items = _bindingTable.GetItems();

            foreach (BindingItem item in items)
            {
                this.watchTable.Watch(item.BindedView, item.BindedViewProperty, OnViewValueChanged);
            }
        }