Abl.Data.SortExpressionConverter.ConvertTo C# (CSharp) Method

ConvertTo() public method

public ConvertTo ( ITypeDescriptorContext context, System culture, object value, Type destinationType ) : object
context ITypeDescriptorContext
culture System
value object
destinationType System.Type
return object
        public override object ConvertTo(
            ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture,
            object value,
            Type destinationType)
        {
            if ((value != null) && (!(value is SortExpression)))
            {
                string msg = $"Unable to convert type '{value.GetType()}'!";
                throw new Exception(msg);
            }

            if (destinationType == typeof (string))
            {
                if (value == null)
                {
                    return String.Empty;
                }

                SortExpression sort = value as SortExpression;
                string data = String.Format(
                    "{1}{0}{2}{0}{3}",
                    SortExpressionFieldDelimiter, sort.Title, sort.Expression,
                    sort.Direction);

                return data;
            }

            return base.ConvertTo(context, culture, value, destinationType);
        }