Beispiel #1
0
        public static object[] ParameterSurrogateHook(HookInfo Info, object[] Params)
        {
            var parameters = Info.OriginalMethod.GetParameters();

            for (int i = 0; i < parameters.Length; i++)
            {
                var parameterAttributes = parameters[i].FindAttributes <IParameterSurrogate>().Order();
                if (parameterAttributes.Count == 0)
                {
                    continue;
                }

                foreach (var attribute in parameterAttributes)
                {
                    Params[i] = attribute.InterceptParameter(Params[i]);
                }
            }

            return(Params);
        }
Beispiel #2
0
        public static object MethodSurrogateHook(HookInfo Info, object[] Params)
        {
            var methodAttributes  = Info.OriginalMethod.FindAttributes <IMethodSurrogate>().Order();
            var continueExecution = true;

            foreach (var attribute in methodAttributes)
            {
                continueExecution = attribute.InterceptMethod(Info.TargetObject, Info.OriginalMethod, ref Params);
                if (!continueExecution)
                {
                    break;
                }
            }

            object retVal = Info.OriginalMethod.ReturnType.Default();

            if (continueExecution)
            {
                retVal = Info.BackingMethod.Invoke(Info.TargetObject, Params);
            }

            return(retVal);
        }