System.Windows.Controls.TypeToBooleanConverter.Convert C# (CSharp) Method

Convert() public method

Convertes the value parameter to a boolean value.
public Convert ( object value, Type targetType, object parameter, CultureInfo culture ) : object
value object The type that is to be converted.
targetType Type The type to which the value is to be converted. In this case it is always boolean.
parameter object A parameter that determines the value to which the type has to be equal to return true.
culture System.Globalization.CultureInfo The culture information of the current culture, so that parsing can be adjusted to cultural conventions.
return object
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Checks if the value provided is null, if so then tell the converter that the value is unset
            if (value == null)
                return DependencyProperty.UnsetValue;

            // Gets the value as type and check if it is null, if so then tells the converter, that the type of the object is used
            Type typeValue = value as Type;
            if (typeValue == null)
                typeValue = value.GetType();

            // Gets the parameter and check if it is null, if so then tells the converter, that the value is unset
            Type parameterValue = parameter as Type;
            if (parameterValue == null)
                return DependencyProperty.UnsetValue;

            // If the parameter equals the value that is to be converted, then returns true, otherwise false is returned
            return typeValue == parameterValue;
        }
TypeToBooleanConverter