public MethodMap(MethodBase method, string[] paramNames, Type[] paramTypes, object[] sampleParamValues, bool mustUseAllParameters) { type = method.DeclaringType; this.method = method; this.paramNames = paramNames; this.paramTypes = paramTypes; requiredParameterCount = method.Parameters().Count; this.mustUseAllParameters = mustUseAllParameters; parameters = method.Parameters(); InitializeBitArrays(Math.Max(parameters.Count, paramNames.Length)); InitializeMethodMap(sampleParamValues); }
/// <summary> /// Gets the method signature in string format. /// </summary> /// <param name="method">The method signature.</param> /// <returns></returns> private string GetMethodSignature(MethodBase method) { var parameters = from m in method.Parameters() select m.ParameterType.ToString(); return string.Format("{0}+{1}", TargetAttribute.FullName, MethodSignatureFormatter.Create(method, parameters.ToArray())); }
/// <summary> /// Gets the formatting strings representing a method. /// </summary> /// <param name="method">A <see cref="MethodBase"/>.</param> /// <param name="methodParameters">The method parameters.</param> /// <returns></returns> public static string Create(MethodBase method, object[] methodParameters) { bool methodIsGeneric; var stringBuilder = new StringBuilder(); var typeFormat = GetTypeFormatString(method.DeclaringType); var typeIsGeneric = method.DeclaringType.IsGenericTypeDefinition; // Build the format string for the method name. stringBuilder.Length = 0; stringBuilder.Append("::"); stringBuilder.Append(method.Name); if (method.IsGenericMethodDefinition) { methodIsGeneric = true; stringBuilder.Append("<"); for (var i = 0; i < method.GetGenericArguments().Length; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.AppendFormat("{{{0}}}", i); } stringBuilder.Append(">"); } else { methodIsGeneric = false; } var methodFormat = stringBuilder.ToString(); // Build the format string for parameters. stringBuilder.Length = 0; var parameters = method.Parameters(); stringBuilder.Append("("); for (var i = 0; i < parameters.Count; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append("{{{"); stringBuilder.Append(i); stringBuilder.Append("}}}"); } stringBuilder.Append(")"); var parameterFormat = stringBuilder.ToString(); var signature = new MethodSignature { MethodFormat = methodFormat, MethodIsGeneric = methodIsGeneric, ParameterFormat = parameterFormat, TypeFormat = typeFormat, TypeIsGeneric = typeIsGeneric }; return Format(signature, method, methodParameters); }