public static CodeType DeclaringType(this CodeFunction element) { var declaringClass = element.DeclaringClass(); if (declaringClass != null) { return(declaringClass as CodeType); } var parent = element.Parent as CodeElement; if (parent == null) { return(null); } switch (parent.Kind) { case vsCMElement.vsCMElementClass: case vsCMElement.vsCMElementEnum: case vsCMElement.vsCMElementInterface: return(parent as CodeType); default: return(null); } }