private String GetCallStackFunction(int index) { StackFrame stackFrame = stackTrace.GetFrame(index); if (stackFrame == null) { return(null); } MethodBase mb = stackFrame.GetMethod(); ParameterInfo[] paras = mb.GetParameters(); System.String callingFunc = stackFrame.GetMethod().ToString(); string signatureBeforeFunName = MethodSignatureTranslator.GetTypeString(mb.DeclaringType); System.String[] temps = callingFunc.Split('('); if (temps.Length < 2) { //error handling } temps = temps[0].Split(' '); if (temps.Length < 2) { //error handling } temps[0] = temps[1]; temps[0] = temps[0].Replace('[', '<'); temps[0] = temps[0].Replace(']', '>'); temps[0] = temps[0].Insert(0, signatureBeforeFunName + "."); temps[0] = temps[0].Insert(temps[0].Length, "("); foreach (ParameterInfo p in paras) { String typeString = MethodSignatureTranslator.GetTypeString(p.ParameterType); temps[0] = temps[0].Insert(temps[0].Length, typeString); temps[0] = temps[0].Insert(temps[0].Length, ","); } if (paras != null && paras.Length > 0) { temps[0] = temps[0].Remove(temps[0].Length - 1); } temps[0] = temps[0].Insert(temps[0].Length, ")"); callingFunc = temps[0]; return(callingFunc); }
private static bool CheckReturnType(Type returnTypeOfTrappedMethod, Object returnValue, String currentFunction) { // // If the return type is <T> or List<T>, we simply omit it. // if (returnTypeOfTrappedMethod.IsGenericParameter || returnTypeOfTrappedMethod.ContainsGenericParameters) { return(true); } if (returnTypeOfTrappedMethod != typeof(void)) { if (returnValue == null && returnTypeOfTrappedMethod.IsValueType == true) { throw new FaultInjectionException(string.Format(CultureInfo.InvariantCulture.NumberFormat, FaultDispatcherMessages.ReturnValueTypeNullError, MethodSignatureTranslator.GetTypeString(returnTypeOfTrappedMethod))); } else if (returnValue != null && returnTypeOfTrappedMethod.IsInstanceOfType(returnValue) == false) { throw new FaultInjectionException(string.Format(CultureInfo.InvariantCulture.NumberFormat, FaultDispatcherMessages.ReturnTypeMismatchError, MethodSignatureTranslator.GetTypeString(returnTypeOfTrappedMethod), MethodSignatureTranslator.GetTypeString(returnValue.GetType()))); } } return(true); }