Exemplo n.º 1
0
 public BindEntity(BindableObject bind, string propertyName, BindableObjectHandler handler, Type type)
 {
     this._propertyName = propertyName;
     this._bind         = bind;
     this._handler      = handler;
     this._type         = type;
 }
        /// <summary>
        /// 初始化环境,3.5 使用
        /// </summary>
        /// <param name="types">需要初始化调用的静态类</param>
        public void Init(IEnumerable <Type> types)
        {
            if (_haveInit)
            {
                return;
            }
            currentEnv = this;

            bindHandler     = new BindableObjectHandler();
            container       = new FrameworkContainer();
            _modules        = new FrameworkModules(this);
            cycleCollection = new RecyclableObjectCollection();
            if (types != null)
            {
                types.ForEach((type) =>
                {
                    TypeAttributes ta = type.Attributes;
                    if ((ta & TypeAttributes.Abstract) != 0 && ((ta & TypeAttributes.Sealed) != 0))
                    {
                        RuntimeHelpers.RunClassConstructor(type.TypeHandle);
                    }
                });
            }

            if (onInit != null)
            {
                onInit();
            }
            deltaTime = TimeSpan.Zero;
            _haveInit = true;
            sw_delta  = new Stopwatch();

            sw_init = new Stopwatch();
            sw_init.Start();
        }
Exemplo n.º 3
0
 public BindEntity(BindableObject bind, string propertyName, BindableObjectHandler handler, Type type)
 {
     this._propertyName = propertyName;
     this._bind         = bind;
     this._handler      = handler;
     this._type         = type;
     setValueAction     = null;
     operation          = BindableObject.BindOperation.Both;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 绑定
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="setter"></param>
        /// <param name="getter"></param>
        /// <returns></returns>
        public BindableObjectHandler BindProperty <T>(Action <T> setter, Func <T> getter)
        {
            Type type = typeof(T);

            if (!_callmap.ContainsKey(type))
            {
                _callmap.Add(type, new Dictionary <string, Action <string, object> >());
            }
            if (!_valuemap.ContainsKey(type))
            {
                _valuemap.Add(type, new Dictionary <string, object>());
            }
            handler = this;
            T tvalue = getter.Invoke();

            handler = null;

            Action <string, object> action = (name, obj) => {
                _valuemap[type][name] = obj;
                T t = (T)obj;
                setter(t);
            };
            object value = _valuemap[type][this._propertyName];

            if (!EqualityComparer <T> .Default.Equals(tvalue, (T)value))
            {
                action.Invoke(this._propertyName, value);
            }

            _callmap[type][this._propertyName] += action;

            for (int i = 0; i < _entitys.Count; i++)
            {
                if (_entitys[i].type == type && _entitys[i].propertyName == this._propertyName)
                {
                    _entitys[i].UnBind();
                    _entitys[i].Bind();
                }
            }
            this._propertyName = string.Empty;
            return(this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 绑定
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="setter"></param>
        /// <param name="getter"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        public BindableObjectHandler BindProperty <T>(Action <T> setter, Func <T> getter, BindableObject.BindOperation operation = BindableObject.BindOperation.Both)
        {
            Type type = typeof(T);

            if (!_callmap.ContainsKey(type))
            {
                _callmap.Add(type, new Dictionary <string, Action <string, object> >());
            }
            handler = this;
            T tvalue = getter.Invoke();

            handler = null;
            var    lastEntity   = _entitys[_entitys.Count - 1];
            string propertyName = lastEntity.propertyName;

            lastEntity.operation      = operation;
            lastEntity.setValueAction = (name, obj) => {
                T t;
                if (obj == null)
                {
                    t = default(T);
                }
                else
                {
                    t = (T)obj;
                }
                _valuemap.Set <T>(name, t);

                if (setter != null)
                {
                    setter(t);
                }
            };

            _entitys[_entitys.Count - 1] = lastEntity;
            T value = _valuemap.Get <T>(propertyName);

            if (value == null)
            {
                if (!EqualityComparer <T> .Default.Equals(tvalue, default(T)))
                {
                    _entitys[_entitys.Count - 1].setValueAction.Invoke(propertyName, value);
                }
            }
            else
            {
                if (!EqualityComparer <T> .Default.Equals(tvalue, value))
                {
                    _entitys[_entitys.Count - 1].setValueAction.Invoke(propertyName, value);
                }
            }


            //此处更改
            for (int i = 0; i < _entitys.Count; i++)
            {
                if (_entitys[i].type == type && _entitys[i].propertyName == propertyName)
                {
                    _entitys[i].UnBind(false);
                }
            }

            _callmap[type][propertyName] += _entitys[_entitys.Count - 1].setValueAction;

            for (int i = 0; i < _entitys.Count; i++)
            {
                if (_entitys[i].type == type && _entitys[i].propertyName == propertyName)
                {
                    _entitys[i].Bind();
                }
            }
            return(this);
        }