public virtual object GetValue()
        {
            IObtainable obtainable = this.GetObtainable();

            if (obtainable == null)
            {
                return(null);
            }
            return(obtainable.GetValue());
        }
        public virtual TValue GetValue <TValue>()
        {
            IObtainable obtainable = this.GetObtainable();

            if (obtainable == null)
            {
                return(default(TValue));
            }

            return(obtainable.GetValue <TValue>());
        }
Esempio n. 3
0
        protected virtual void UpdateSourceFromTarget()
        {
            try
            {
                if (this.isUpdatingTarget)
                {
                    return;
                }

                this.isUpdatingSource = true;

                Type        valueType  = this.targetProxy.Type;
                IObtainable obtainable = this.targetProxy as IObtainable;
                if (obtainable == null)
                {
                    return;
                }

                IModifiable modifier = this.sourceProxy as IModifiable;
                if (modifier == null)
                {
                    return;
                }
#if NETFX_CORE
                TypeCode typeCode = WinRTLegacy.TypeExtensions.GetTypeCode(valueType);
#else
                TypeCode typeCode = Type.GetTypeCode(valueType);
#endif
                switch (typeCode)
                {
                case TypeCode.Boolean:
                {
                    var value = obtainable.GetValue <bool>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Byte:
                {
                    var value = obtainable.GetValue <byte>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Char:
                {
                    var value = obtainable.GetValue <char>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.DateTime:
                {
                    var value = obtainable.GetValue <DateTime>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Decimal:
                {
                    var value = obtainable.GetValue <decimal>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Double:
                {
                    var value = obtainable.GetValue <double>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Int16:
                {
                    var value = obtainable.GetValue <Int16>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Int32:
                {
                    var value = obtainable.GetValue <Int32>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Int64:
                {
                    var value = obtainable.GetValue <Int64>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.SByte:
                {
                    var value = obtainable.GetValue <sbyte>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Single:
                {
                    var value = obtainable.GetValue <float>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.String:
                {
                    var value = obtainable.GetValue <string>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.UInt16:
                {
                    var value = obtainable.GetValue <UInt16>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.UInt32:
                {
                    var value = obtainable.GetValue <UInt32>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.UInt64:
                {
                    var value = obtainable.GetValue <UInt64>();
                    this.SetSourceValue(modifier, value);
                    break;
                }

                case TypeCode.Object:
                {
                    if (valueType.Equals(typeof(Vector2)))
                    {
                        var value = obtainable.GetValue <Vector2>();
                        this.SetSourceValue(modifier, value);
                    }
                    else if (valueType.Equals(typeof(Vector3)))
                    {
                        var value = obtainable.GetValue <Vector3>();
                        this.SetSourceValue(modifier, value);
                    }
                    else if (valueType.Equals(typeof(Vector4)))
                    {
                        var value = obtainable.GetValue <Vector4>();
                        this.SetSourceValue(modifier, value);
                    }
                    else if (valueType.Equals(typeof(Color)))
                    {
                        var value = obtainable.GetValue <Color>();
                        this.SetSourceValue(modifier, value);
                    }
                    else if (valueType.Equals(typeof(Rect)))
                    {
                        var value = obtainable.GetValue <Rect>();
                        this.SetSourceValue(modifier, value);
                    }
                    else if (valueType.Equals(typeof(Quaternion)))
                    {
                        var value = obtainable.GetValue <Quaternion>();
                        this.SetSourceValue(modifier, value);
                    }
                    else if (valueType.Equals(typeof(Version)))
                    {
                        var value = obtainable.GetValue <Version>();
                        this.SetSourceValue(modifier, value);
                    }
                    else
                    {
                        var value = obtainable.GetValue();
                        this.SetSourceValue(modifier, value);
                    }
                    break;
                }

                default:
                {
                    var value = obtainable.GetValue();
                    this.SetSourceValue(modifier, value);
                    break;
                }
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat("An exception occurs when the source property is updated.Please check the binding \"{0}{1}\" in the view \"{2}\".exception: {3}", this.targetTypeName, this.bindingDescription.ToString(), GetViewName(), e);
                }
            }
            finally
            {
                this.isUpdatingSource = false;
            }
        }
Esempio n. 4
0
        protected virtual void UpdateTargetFromSource()
        {
            lock (_lock)
            {
                //Run on the main thread
                Executors.RunOnMainThread(() =>
                {
                    try
                    {
                        if (this.isUpdatingSource)
                        {
                            return;
                        }

                        this.isUpdatingTarget = true;

                        IObtainable obtainable = this.sourceProxy as IObtainable;
                        if (obtainable == null)
                        {
                            return;
                        }

                        IModifiable modifier = this.targetProxy as IModifiable;
                        if (modifier == null)
                        {
                            return;
                        }

                        TypeCode typeCode = this.sourceProxy.TypeCode;
                        switch (typeCode)
                        {
                        case TypeCode.Boolean:
                            {
                                var value = obtainable.GetValue <bool>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Byte:
                            {
                                var value = obtainable.GetValue <byte>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Char:
                            {
                                var value = obtainable.GetValue <char>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.DateTime:
                            {
                                var value = obtainable.GetValue <DateTime>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Decimal:
                            {
                                var value = obtainable.GetValue <decimal>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Double:
                            {
                                var value = obtainable.GetValue <double>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Int16:
                            {
                                var value = obtainable.GetValue <short>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Int32:
                            {
                                var value = obtainable.GetValue <int>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Int64:
                            {
                                var value = obtainable.GetValue <long>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.SByte:
                            {
                                var value = obtainable.GetValue <sbyte>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Single:
                            {
                                var value = obtainable.GetValue <float>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.String:
                            {
                                var value = obtainable.GetValue <string>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.UInt16:
                            {
                                var value = obtainable.GetValue <ushort>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.UInt32:
                            {
                                var value = obtainable.GetValue <uint>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.UInt64:
                            {
                                var value = obtainable.GetValue <ulong>();
                                this.SetTargetValue(modifier, value);
                                break;
                            }

                        case TypeCode.Object:
                            {
                                Type valueType = this.sourceProxy.Type;
                                if (valueType.Equals(typeof(Vector2)))
                                {
                                    var value = obtainable.GetValue <Vector2>();
                                    this.SetTargetValue(modifier, value);
                                }
                                else if (valueType.Equals(typeof(Vector3)))
                                {
                                    var value = obtainable.GetValue <Vector3>();
                                    this.SetTargetValue(modifier, value);
                                }
                                else if (valueType.Equals(typeof(Vector4)))
                                {
                                    var value = obtainable.GetValue <Vector4>();
                                    this.SetTargetValue(modifier, value);
                                }
                                else if (valueType.Equals(typeof(Color)))
                                {
                                    var value = obtainable.GetValue <Color>();
                                    this.SetTargetValue(modifier, value);
                                }
                                else if (valueType.Equals(typeof(Rect)))
                                {
                                    var value = obtainable.GetValue <Rect>();
                                    this.SetTargetValue(modifier, value);
                                }
                                else if (valueType.Equals(typeof(Quaternion)))
                                {
                                    var value = obtainable.GetValue <Quaternion>();
                                    this.SetTargetValue(modifier, value);
                                }
                                else if (valueType.Equals(typeof(Version)))
                                {
                                    var value = obtainable.GetValue <Version>();
                                    this.SetTargetValue(modifier, value);
                                }
                                else
                                {
                                    var value = obtainable.GetValue();
                                    this.SetTargetValue(modifier, value);
                                }
                                break;
                            }

                        default:
                            {
                                var value = obtainable.GetValue();
                                this.SetTargetValue(modifier, value);
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.ErrorFormat("An exception occurs when the target property is updated.Please check the binding \"{0}{1}\" in the view \"{2}\".exception: {3}", this.targetTypeName, this.bindingDescription.ToString(), GetViewName(), e);
                        }
                    }
                    finally
                    {
                        this.isUpdatingTarget = false;
                    }
                });
            }
        }