Пример #1
0
 public void xDispose()
 {
     if (BinderIsRunning)
     {
         Stop();
     }
     ObjectLinks.Clear();
     ObjectLinks = null;
     ViewLinks.Clear();
     ViewLinks = null;
     ObservedObjects.Clear();
     ObservedObjects = null;
     ValuesToViewsQue.Clear();
     ValuesToViewsQue = null;
 }
Пример #2
0
        public void ProcessBindable_PropertyChanged(object bindable, string property, bool isInitial = false)
        {
            if ("*".Equals(property))
            {
                foreach (var olnk in ObjectLinks)
                {
                    ProcessBindable_PropertyChanged(olnk.Value.Object, olnk.Value.Property.Name, isInitial);
                }
            }
            else
            {
                string cObjectPropID = string.Concat(bindable.GetType().Name, bindable.GetHashCode(), property);

                var links = ViewLinks.Where(x => x.Key == cObjectPropID);
                if (links.Count() > 0)
                {
                    var newVal = bindable.GetType().GetProperty(property).GetValue(bindable);
                    SendNewValueToViews(newVal, links, isInitial);
                }
            }
        }
Пример #3
0
        public bool BindViewProperty(object view, string viewProperty, BaseObservable bindable, string bindableProperty, BindMode bindMode)
        {
            if (view == null)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(viewProperty))
            {
                return(false);
            }
            if (bindable == null)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(bindableProperty))
            {
                return(false);
            }

            var vProp = view.GetType().GetProperty(viewProperty);

            if (vProp == null)
            {
                return(false);
            }
            var bProp = bindable.GetType().GetProperty(bindableProperty);

            if (bProp == null)
            {
                return(false);
            }

            //if (!bProp.PropertyType.Equals(typeof(T)) && !bProp.PropertyType.IsSubclassOf(typeof(T)))
            //  return false;

            string cViewPropID = string.Concat(view.GetType().Name, view.GetHashCode(), viewProperty);

            if (ObjectLinks.ContainsKey(cViewPropID))
            {
                return(false);
            }

            string cObjectPropID = string.Concat(bindable.GetType().Name, bindable.GetHashCode(), bindableProperty);

            ObjectLinks.Add(cViewPropID, new ObjectLink {
                ID = cObjectPropID, Object = bindable, Property = bProp
            });
            BindModes.Add(cViewPropID, bindMode);


            ViewLinks.Add(new KeyValuePair <string, ViewLink>(cObjectPropID, new ViewLink {
                ID = cViewPropID, View = view, Property = vProp
            }));

            if (!ObservedObjects.Contains(bindable))
            {
                ObservedObjects.Add(bindable);
            }

            return(true);
        }