ChessBoardVisualLib.Converters.DictionaryValueConverter.Convert C# (CSharp) Метод

Convert() публичный Метод

public Convert ( object value, Type targetType, object parameter, CultureInfo culture ) : object
value object
targetType System.Type
parameter object
culture System.Globalization.CultureInfo
Результат object
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // if key type is not set, get it from the first dictionary value, usually it's the same for all the keys
            if (KeyType == null)
            {
                KeyType = Values.Keys.First().GetType();
            }

            // if key type is an enum
            if (KeyType.IsEnum)
            {
                // convert integral value to enum value
                value = Enum.ToObject(KeyType, value);
            }

            // if dictionary contains the requested key
            if (Values.ContainsKey(value))
            {
                // return the relevant value
                return Values[value];
            }

            // otherwise, don't return a value, this will fall back to the binding FallbackValue
            return DependencyProperty.UnsetValue;
        }