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

ConvertFrom() public method

public ConvertFrom ( ITypeDescriptorContext context, System culture, object value ) : object
context ITypeDescriptorContext
culture System
value object
return object
        public override object ConvertFrom(
            ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture,
            object value)
        {
            if (value == null)
            {
                return new SortExpression();
            }

            string data = value as string;
            if (data != null)
            {
                if (data.Length < 1)
                {
                    return new SortExpression();
                }

                string[] elements =
                    data.Split(new char[] {SortExpressionFieldDelimiter});
                if (elements.Length != 3)
                {
                    throw new Exception("Invalid data format!");
                }

                string title = elements[0];
                string expression = elements[1];
                SortDirection direction =
                    (SortDirection)
                        Enum.Parse(typeof (SortDirection), elements[2], true);

                SortExpression sortExpression = new SortExpression(
                    title, expression, direction);

                return sortExpression;
            }

            return base.ConvertFrom(context, culture, value);
        }