/// <summary> /// Returns ONLY method declaration string. Not intended to work for lambda methods so returns NULL for them. /// Todo: refactor: actually lambda identification must be part of method lister. Bu it would require to make MethodLister generic from underlying source type (e.g. MethodLister(Of MethodDefinitionSyntax)) /// </summary> /// <param name="method"></param> /// <returns></returns> public static string GetMethodDeclarationString(IMethodInfoProvider method) { try { if (method.IsPartialMethodWithoutBody) { return(null); } if (method.IsAbstractClassOrInterfaceMember) { return(null); } if (method.IsExternal) { return(null); } string methodNamePart = GetMethodNamePart(method); if (methodNamePart == null) { return(null); } string typeName = GetFullyQualifiedTypeName(method.DeclaringType); if (typeName == null) { return(null); } string parametersPart = GetMemberParametersPart(method); var parts = new[] { typeName, methodNamePart, parametersPart }; string methodDeclarationString = string.Concat(parts); if (MethodNameNormalizer.SkipProcessingMethod(methodDeclarationString)) { return(null); } return(methodDeclarationString); } catch { Console.WriteLine("Exception stringifying method. Method details: \r\n" + method); throw; } }
public static string GetFullyQualifiedTypeName(ITypeInfoProvider @type) { string typeName = GetTypeName(@type); if (MethodNameNormalizer.IsLambdaMethod(typeName)) { return(null); } string ns = @type.Namespace; if (!string.IsNullOrEmpty(ns)) { typeName = ns + "." + typeName; } return(typeName); }
private static string GetMethodNamePart(IMethodInfoProvider method) { var sb = new StringBuilder(); sb.Append(TypeFromMethodDelimiter); sb.Append(MethodNameNormalizer.Normalize(method.Name)); if (method.IsGenericMethodDefinition) { sb.Append("<"); sb.Append(string.Join(", ", method.GetGenericArguments().Select(a => a.ToString()))); sb.Append(">"); } string methodNamePart = sb.ToString(); // exclude compiler-generated lambda methods like "SomeTestType::<MethodWithLambdasInside>b__0(object actParam)" if (MethodNameNormalizer.IsLambdaMethod(methodNamePart)) { return(null); } return(methodNamePart); }