Visual studio 是否可以使用coderush API获取源代码所在类的完整文件路径?
当VisualStudio中的插入符号处于对象创建或引用其他类的方法时,我希望获得完整的文件路径 差不多Visual studio 是否可以使用coderush API获取源代码所在类的完整文件路径?,visual-studio,coderush,dxcore,Visual Studio,Coderush,Dxcore,当VisualStudio中的插入符号处于对象创建或引用其他类的方法时,我希望获得完整的文件路径 差不多 Class CurrentClass { Class2 object1=new Class2(); object1.method1(); } 我可以获得完整的文件路径,如c:\ProjectLocation\Class2.cs 当我在VisualStudio中得到这一行时 Class2 object1=new Class2(); 您可以解析活动表达式(对象创建表达式、类型
Class CurrentClass
{
Class2 object1=new Class2();
object1.method1();
}
我可以获得完整的文件路径,如c:\ProjectLocation\Class2.cs
当我在VisualStudio中得到这一行时
Class2 object1=new Class2();
您可以解析活动表达式(对象创建表达式、类型引用表达式、方法引用表达式),并使用以下代码获取带有已解析声明的文件名:
Expression activeExpression = CodeRush.Source.Active as Expression;
if (activeExpression!= null)
{
IElement declaration = activeExpression.Resolve(new SourceTreeResolver());
if (declaration != null)
{
string fileName = declaration.FirstFile.Name;
// use the fileName...
}
}
我只是尝试用coderush做一些基本的事情,比如获取父类中的所有方法……我尝试将类parent=declaraton.GetDeclaration()作为类,并尝试使用parent.AllMethods,这并没有授予对该类中所有方法的访问权…我正在尝试使用TypeReferenceExpression是否还有其他类或函数需要查看???代码中的“声明”应该是ITypeElement类型的实例,因此尝试使用如下代码:ITypeElement typeInstance=声明为ITypeElement;if(typeInstance!=null)foreach(typeInstance.Members中的IMemberElement成员){IMethodElement method=memberas-IMethodElement;if(method!=null){//对方法执行操作…}