Ejemplo n.º 1
0
        private static void CreateConverters()
        {
            // get type list
            var types = GetTypes();

            // get implicit operators
            var operatorDictionary = BindingUtility.GetImplicitOperators(types);

            var converterDictionary = new Dictionary <Tuple <Type, Type>, ImplicitConverter>();

            foreach (var item in operatorDictionary)
            {
                var key       = item.Key;
                var pairedKey = Tuple.Create(key.Item2, key.Item1);

                // get methods
                MethodInfo convertMethod = item.Value;
                MethodInfo convertBackMethod;
                operatorDictionary.TryGetValue(pairedKey, out convertBackMethod);

                // create new converter
                var converter = new ImplicitConverter(convertMethod, convertBackMethod);

                // add it
                converterDictionary.Add(key, converter);
            }

            // add converters
            foreach (var item in converterDictionary)
            {
                var key       = item.Key;
                var converter = item.Value;

                ValueConverterProvider.Instance.AddConverter(key.Item1, key.Item2, converter);
            }
        }