コード例 #1
0
        public override object Convert(Type desiredType, Type inputType, object input, out bool conversionSucceeded)
        {
            conversionSucceeded = (input != null && input.ToString() == "");
            if (input == null)
            {
                return(null);
            }
            Type elemType = desiredType.GetGenericArguments()[0];

            input = ConverterUtil.FixInputForMonoIfNeeded(elemType, input);

            Type listType = typeof(List <>).MakeGenericType(elemType);
            var  result   = (IList)Activator.CreateInstance(listType);
            var  values   = input as Array;

            bool elementConversionSucceeded;

            for (int i = 0; i < values.Length; i++)
            {
                object val = parent.Convert(elemType, inputType, values.GetValue(i), out elementConversionSucceeded);
                if (val != null)
                {
                    result.Add(val);
                }

                // if at least one list element get converted
                // we consider the conversion a success
                if (elementConversionSucceeded)
                {
                    conversionSucceeded = true;
                }
            }

            return(result);
        }
コード例 #2
0
        public override object Convert(Type desiredType, Type inputType, object input, out bool conversionSucceeded)
        {
            conversionSucceeded = (input != null && input.ToString() == "");
            if (input == null)
            {
                return(null);
            }

            Type elemType = desiredType.GetElementType();

            input = ConverterUtil.FixInputForMonoIfNeeded(elemType, input);

            var   values = input as Array;
            Array result = Array.CreateInstance(elemType, values.Length);

            for (int i = 0; i < values.Length; i++)
            {
                bool elementConversionSucceeded;

                result.SetValue(parent.Convert(elemType, null, values.GetValue(i), out elementConversionSucceeded), i);

                // if at least one array element get converted
                // we consider the conversion a success
                if (elementConversionSucceeded)
                {
                    conversionSucceeded = true;
                }
            }

            return(result);
        }
コード例 #3
0
        public override object Convert(Type desiredType, Type inputType, object input, out bool conversionSucceeded)
        {
            conversionSucceeded = true;

            String value = ConverterUtil.NormalizeInput(input);

            if (IsBool(desiredType))
            {
                return(SpecialBoolConversion(value, input, ref conversionSucceeded));
            }
            else if (input == null)
            {
                conversionSucceeded = false;
                return(null);
            }
            else if (value == String.Empty)
            {
                conversionSucceeded = true;
                return(null);
            }
            else
            {
                return(System.Convert.ChangeType(input, desiredType));
            }
        }
        /// <summary>
        /// Converts the specified desired type.
        /// </summary>
        /// <param name="desiredType">Type of the desired.</param>
        /// <param name="inputType">Type of the input.</param>
        /// <param name="input">The input.</param>
        /// <param name="conversionSucceeded">if set to <c>true</c> [conversion succeeded].</param>
        /// <returns><see cref="DateTime"/> if conversion successful, <c>null</c> otherwise.</returns>
        public override object Convert(Type desiredType, Type inputType, object input, out bool conversionSucceeded)
        {
            conversionSucceeded = input != null;

            if (input == null)
            {
                return(null);
            }

            string value = ConverterUtil.NormalizeInput(input);

            if (value == String.Empty)
            {
                conversionSucceeded = false;

                return(null);
            }

            return(DateTime.Parse(value));
        }
コード例 #5
0
        public override object Convert(Type desiredType, Type inputType, object input, out bool conversionSucceeded)
        {
            conversionSucceeded = input != null;

            if (input == null)
            {
                return(null);
            }

            String value = ConverterUtil.NormalizeInput(input);

            if (value == String.Empty)
            {
                conversionSucceeded = true;
                return(null);
            }
            else
            {
                return(new Guid(value));
            }
        }