private static void WriteParametersToTranslation(MethodBase method, TranslationBuffer buffer) { var parameters = method.GetParameters(); if (!parameters.Any()) { buffer.WriteToTranslation("()"); return; } buffer.WriteNewLineToTranslation(); buffer.WriteToTranslation('('); buffer.Indent(); for (var i = 0; ;) { var parameter = parameters[i]; var parameterType = parameter.ParameterType; buffer.WriteNewLineToTranslation(); if (parameter.IsOut) { buffer.WriteToTranslation("out "); parameterType = parameterType.GetElementType(); } else if (parameterType.IsByRef) { buffer.WriteToTranslation("ref "); parameterType = parameterType.GetElementType(); } buffer.WriteFriendlyName(parameterType); buffer.WriteSpaceToTranslation(); buffer.WriteToTranslation(parameter.Name); if (++i == parameters.Length) { break; } buffer.WriteToTranslation(','); } buffer.Unindent(); buffer.WriteNewLineToTranslation(); buffer.WriteToTranslation(')'); }
/// <summary> /// Translates the given <paramref name="method"/> into a readable string. /// </summary> /// <param name="method">The MethodInfo to translate.</param> /// <returns>A readable string version of the given <paramref name="method"/>.</returns> public static string Translate(MethodInfo method) { if (method == null) { return("[Method not found]"); } var buffer = new TranslationBuffer(method.ToString().Length); WriteModifiersToTranslation(method, buffer); var isProperty = method.IsPropertyGetterOrSetterCall(out var property); buffer.WriteFriendlyName(isProperty ? property.PropertyType : method.ReturnType); buffer.WriteSpaceToTranslation(); if (method.DeclaringType != null) { buffer.WriteFriendlyName(method.DeclaringType); buffer.WriteToTranslation('.'); } if (isProperty) { buffer.WriteToTranslation(property.Name); buffer.WriteToTranslation((method.ReturnType != typeof(void)) ? " { get; }" : " { set; }"); return(buffer.GetContent()); } buffer.WriteToTranslation(method.Name); if (method.IsGenericMethod) { WriteGenericArgumentsToTranslation(method.GetGenericArguments(), buffer); } WriteParametersToTranslation(method, buffer); return(buffer.GetContent()); }