Esempio n. 1
0
        private bool TryConvertValue(object value, Type propertyType, out object convertedValue)
        {
            var conversionResult = ConversionResultProvider.ConvertTo(value, propertyType);

            if (!conversionResult.CanBeConverted)
            {
                convertedValue = null;
                return(false);
            }

            convertedValue = conversionResult.ConvertedInstance;
            return(true);
        }
Esempio n. 2
0
        private bool TryConvertValue(object value, out TValue convertedValue, out string errorMessage)
        {
            var conversionResult = ConversionResultProvider.ConvertTo(value, typeof(TValue));

            if (conversionResult.CanBeConverted)
            {
                errorMessage   = null;
                convertedValue = (TValue)conversionResult.ConvertedInstance;
                return(true);
            }
            else
            {
                errorMessage   = Resources.FormatInvalidValueForProperty(value);
                convertedValue = default(TValue);
                return(false);
            }
        }
Esempio n. 3
0
        private bool TryConvertKey(string key, out TKey convertedKey, out string errorMessage)
        {
            var conversionResult = ConversionResultProvider.ConvertTo(key, typeof(TKey));

            if (conversionResult.CanBeConverted)
            {
                errorMessage = null;
                convertedKey = (TKey)conversionResult.ConvertedInstance;
                return(true);
            }
            else
            {
                errorMessage = Resources.FormatInvalidPathSegment(key);
                convertedKey = default(TKey);
                return(false);
            }
        }
Esempio n. 4
0
        private bool TryConvertValue(
            object originalValue,
            Type listTypeArgument,
            string segment,
            out object convertedValue,
            out string errorMessage)
        {
            var conversionResult = ConversionResultProvider.ConvertTo(originalValue, listTypeArgument);

            if (!conversionResult.CanBeConverted)
            {
                convertedValue = null;
                errorMessage   = Resources.FormatInvalidValueForProperty(originalValue);
                return(false);
            }

            convertedValue = conversionResult.ConvertedInstance;
            errorMessage   = null;
            return(true);
        }