internal BindingBridge(IBindingSourceInternal source, PropertyInfo sourcePropery, PropertyInfo[] targetProperyChain)
 {
     MyBindingSource = source;
     SourcePropertyInfo = sourcePropery;
     TargetPropertyChain = targetProperyChain;
     bool fromSource = SourcePropertyInfo.CanRead && TargetPropertyChain.Last ().CanWrite;
     bool fromTarget = SourcePropertyInfo.CanWrite && TargetPropertyChain.Last ().CanRead
         && MyBindingSource.Controler.BackwardProperties.Contains (TargetPropertyName);
     if (fromSource && fromTarget)
         Mode = BridgeMode.TwoWay;
     else if (fromSource)
         Mode = BridgeMode.OnlyFromSource;
     else if (fromTarget)
         Mode = BridgeMode.BackwardFromTarget;
     else
         throw new ArgumentException ("Невозможно вычислить направление биндинга, необходимо что бы хотябы одно свойство имело возможность записи, а другое чтение.");
 }
Esempio n. 2
0
        public object GetValue(object entity, PropertyInfo[] accessorList)
        {
            var obj = entity;
            for (int x = 0; x < accessorList.Length - 1; x++)
            {
                obj = accessorList[x].GetValue(obj, null);
            }

            return accessorList.Last().GetValue(obj, null);
        }
Esempio n. 3
0
        public void SetValue(object entity, PropertyInfo[] accessorList, object propertyValue)
        {
            if (propertyValue == DBNull.Value) return;

            var obj = entity;
            for (int x = 0; x < accessorList.Length - 1; x++)
            {
                obj = accessorList[x].GetValue(obj, null);
            }

            var accessor = accessorList.Last();
            if (accessor.PropertyType.IsEnum)
            {
                propertyValue = Enum.ToObject(accessor.PropertyType, propertyValue);
            }
            else if (!accessor.PropertyType.IsAssignableFrom(propertyValue.GetType()))
            {
                propertyValue = Convert.ChangeType(propertyValue, accessor.PropertyType);
            }
            accessor.SetValue(obj, propertyValue, null);
        }