Ejemplo n.º 1
0
        public virtual T GetValueFromObject <T>(object value)
        {
            Type t = typeof(T);

            if (value == null)
            {
                if (t.IsValueType)
                {
                    throw new InvalidCastException("Cannot set an object that have a ValueType to null.");
                }
                return((T)(object)null);
            }

            // value is already of the correct type.
            if (t == typeof(object))
            {
                return((T)(object)value);
            }

            // TODO: Consider calling  Type s = PropFactory.GetTypeFromValue(value);
            Type vType = value.GetType();

            // value is already of the correct type.
            if (vType == t)
            {
                return((T)(object)value);
            }

            object parameter = new TwoTypes(t, vType);

            return((T)ValueConverter.ConvertBack(value, t, parameter, CultureInfo.CurrentCulture));
        }
Ejemplo n.º 2
0
        public virtual T GetValueFromString <T>(string value)
        {
            Type t = typeof(T);
            Type s = typeof(string);

            if (t == s)
            {
                return((T)(object)value);
            }

            object parameter = new TwoTypes(t, s);

            return((T)ValueConverter.ConvertBack(value, t, parameter, CultureInfo.CurrentCulture));
        }