public void Convert(ConvertTypeRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if ((request.Value as string)?.Length == 0)
            {
                if (request.ConversionType == typeof(string))
                {
                    request.Converted(request.Value);
                }
                else if (request.ConversionTypeAllowsNull)
                {
                    request.Converted(null);
                }
            }
        }
        public void Convert(ConvertTypeRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (request.Value == null && request.ConversionTypeAllowsNull)
            {
                request.Converted(null);
            }
        }
        public void Convert(ConvertTypeRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // All Nullable<T> instances box as their UnderlyingType.
            if (request.Value?.GetType() == request.ConversionType.FlattenGenericNullable())
            {
                request.Converted(request.Value);
            }
        }
Beispiel #4
0
        public void Convert(ConvertTypeRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            Type conversionType = request.ConversionType.FlattenGenericNullable();

            if (request.Value != null && request.Value.GetType().IsEnumUnderlyingType() && conversionType.IsEnum)
            {
                request.Converted(Enum.ToObject(conversionType, request.Value));
            }
        }
Beispiel #5
0
        public void Convert(ConvertTypeRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // System.Convert.ChangeType requires that value implements IConvertible.
            // https://docs.microsoft.com/en-us/dotnet/api/system.convert.changetype?view=netstandard-2.0
            //
            // TODO : Check that ConversionType is supported by IConvertible.
            if ((request.Value == null && !request.ConversionType.IsValueType) || request.Value is IConvertible)
            {
                request.Converted(System.Convert.ChangeType(request.Value, request.ConversionType.FlattenGenericNullable(), request.Provider));
            }
        }