public DispatchResult <R> Typed <R>()
        {
            DispatchResult <R> result = new DispatchResult <R>(_status);

            if (this.ReturnValue != null)
            {
                result.ReturnValue = (R)this.ReturnValue;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public DispatchResult Dispatch(object target, params object[] args)
        {
            if (TargetOrArgumentIsNull(target, args))
            {
                return(new DispatchResult(DispatchStatus.NoMatch));
            }

            MethodInvoker method = _dispatchTable.Match(args);

            if (method != null)
            {
                return(InvokeMethod(method, target, args));
            }

            try
            {
                MethodInfo info = TryReflectionMatch(args);

                if (info.MethodHandle != _multiMethod.MethodHandle)                 // always use MethodInfo.MethodHandle to compare!
                {
                    method = MethodInvokerHelper.CreateInvoker(info);
                }
                else
                {
                    method = delegate
                    {
                        return(new DispatchResult(DispatchStatus.NoMatch));
                    };
                }
            }
            catch (AmbiguousMatchException)
            {
                method = delegate
                {
                    return(new DispatchResult(DispatchStatus.AmbiguousMatch));
                };
            }

            _dispatchTable.Add(args, method);

            DispatchResult result = InvokeMethod(method, target, args);

            result.IsDynamicInvoke = true;

            return(result);
        }
Ejemplo n.º 3
0
        private DispatchResult InvokeMethod(MethodInvoker method, object target, object[] args)
        {
            object returnValue = method(target, args);

            DispatchResult result = new DispatchResult(DispatchStatus.Success);

            if (returnValue != null && returnValue is DispatchResult)             // we registered a NoMatch / AmbiguousMatch
            {
                result = (DispatchResult)returnValue;
            }
            else
            {
                result.ReturnValue = returnValue;
            }

            return(result);
        }