Esempio n. 1
0
 protected virtual void Validate_3_SpecialCases()
 {
     if (InterceptedMethod.IsConstructor && (HookType != MethodHookType.RunAfter))
     {
         throw new ArgumentException("Intercepted Method appears to be a constructor for a type (" + InterceptedMethod.DeclaringType.FullName + "). Only MethodHookType.RunAfter is currently supported for constructors.");
     }
     if (HookFlags.HasFlag(MethodHookFlags.CanSkipOriginal))
     {
         if (HookType != MethodHookType.RunBefore)
         {
             throw new ArgumentException("MethodHookFlags.CanSkipOriginal requires MethodHookType.RunBefore!");
         }
     }
 }
Esempio n. 2
0
 protected virtual void Validate_5_ReturnType()
 {
     //Return value checking
     if (HookFlags.HasFlag(MethodHookFlags.CanSkipOriginal))
     {
         if (CustomMethod.ReturnType != typeof(bool))
         {
             throw new ArgumentException("Methods that can skip the original method have to return a bool, indicating the skipping state");
         }
     }
     else if ((HasResultAsFirstParameter || (HookType == MethodHookType.Replace)) && (InterceptedMethod is MethodInfo))
     {
         var expected_type = (InterceptedMethod as MethodInfo).ReturnType;
         if (expected_type != CustomMethod.ReturnType)
         {
             Validate_5_ReturnType_WrongReturnType(CustomMethod.ReturnType, expected_type, CustomMethod);
         }
     }
     else if (CustomMethod.ReturnType != typeof(void))
     {
         Validate_5_ReturnType_WrongReturnType(CustomMethod.ReturnType, typeof(void), CustomMethod);
     }
 }