Exemple #1
0
 internal static void OnConverterRequested(ConverterRequestedEventArgs args)
 {
     if (args.InputType != typeof(string) || args.OutputType != typeof(int))
     {
         return;
     }
     args.ObjectConverter = _objectConverter;
 }
Exemple #2
0
        static ObjectConverter _TryGetConverterStatic(ref KeyValuePair <Type, Type> key)
        {
            ObjectConverter result;
            Action <ConverterRequestedEventArgs> converterRequested;

            lock (_staticConverters)
            {
                if (_staticConverters.TryGetValue(key, out result))
                {
                    return(result);
                }
                converterRequested = StaticConverterRequested;
            }

            if (converterRequested != null)
            {
                var args     = new ConverterRequestedEventArgs(key.Key, key.Value);
                var handlers = converterRequested.GetInvocationList();

                Action <ConverterRequestedEventArgs> matchingHandler = null;
                for (int i = 0; i < handlers.Length; i++)
                {
                    var handler = (Action <ConverterRequestedEventArgs>)handlers[i];
                    handler(args);
                    result = args.ObjectConverter;
                    if (result != null)
                    {
                        matchingHandler = handler;
                        break;
                    }
                }

                if (matchingHandler != null)
                {
                    lock (_staticConverters)
                    {
                        StaticConverterRequested -= matchingHandler;
                        _staticConverters[key]    = result;
                    }
                }
            }

            return(result);
        }