CSharp examples for System.Reflection:MethodInfo
Looks class that is the method container using Roslyn.
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis; public class Main{ /// <summary> /// Looks class that is the method container. /// </summary> /// <param name="methodSyntax"></param> /// <returns></returns> public static ClassDeclarationSyntax DeclaringClass(this MethodDeclarationSyntax methodSyntax) {//from ww w . j a va2 s . co m if (methodSyntax.Parent is ClassDeclarationSyntax) return methodSyntax.Parent as ClassDeclarationSyntax; return null; } }