ArcGISPortalViewer.Common.BiConditionalConverter.ConvertValue C# (CSharp) Method

ConvertValue() private method

private ConvertValue ( object value, Type targetType, bool invert = false ) : object
value object
targetType System.Type
invert bool
return object
        private object ConvertValue(object value, Type targetType, bool invert = false)
        {
            if (value == null)
            {
                if (targetType == typeof(Visibility))
                    return (invert) ? Visibility.Visible : Visibility.Collapsed;
                if (targetType == typeof(bool))
                    return (invert);
            }
            else
            {
                if (value is Visibility)
                {
                    if (targetType == typeof(bool))
                        return (((Visibility)value == Visibility.Visible) != invert);
                }
                else if (value is bool)
                {
                    if (targetType == typeof(Visibility))
                        return (((bool)value) != invert) ? Visibility.Visible : Visibility.Collapsed;
                    if (targetType == typeof(bool))
                        return (((bool)value) != invert);
                }
                else if (value is int)
                {
                    if (targetType == typeof(Visibility))
                        return ((((int)value) > 0) != invert) ? Visibility.Visible : Visibility.Collapsed;
                }
                else if (value is IEnumerable)
                {
                    if (targetType == typeof(Visibility))
                        return ((value as IEnumerable).GetEnumerator().MoveNext() && !invert) ? Visibility.Visible : Visibility.Collapsed;
                }
                else
                {
                    if (targetType == typeof(Visibility))
                        return (!invert) ? Visibility.Visible : Visibility.Collapsed;
                    if (targetType == typeof(bool))
                        return (!invert);
                }
            }

            return value;
        }