Esempio n. 1
0
		protected string GetDelegate (MethodInfo method)
		{
			var parameters = method.GetParameters();
			if (parameters.Length == 0)
				return method.IsVoid () ? "Action" : "Func<" + GetTypeName(method.ReturnType) + ">";

			if (method.HasOutOrRef ()) {
				// In this case the template will generate a custom delegate with the 
				// method name and all parameter types, to ensure uniqueness, i.e. FooInt32BooleanString
				return method.Name + string.Join ("", parameters.Select (x => x.ParameterType.Name.TrimEnd ('&')));
			} else {
				var typeParams = string.Join(", ", parameters.Select(x => GetTypeName(x.ParameterType)));
				return method.IsVoid () ?
					"Action<" + typeParams + ">" :
					"Func<" + typeParams + ", " + GetTypeName(method.ReturnType) + ">";
			}
		}
 /// <summary>
 /// Determines whether a method can be mocked.
 /// </summary>
 /// <param name="method">The candidate method.</param>
 /// <returns>Whether <paramref name="method"/> can be configured.</returns>
 private static bool CanBeConfigured(MethodInfo method)
 {
     return method.IsOverridable() &&
            !method.IsGenericMethod &&
            !method.HasRefParameters() &&
            (!method.IsVoid() || method.HasOutParameters());
 }