简体   繁体   English

在ASP.Net网站中的反思

[英]Reflection in ASP.Net website

I have been working with a Visual Studio Addin project for a while. 我已经使用Visual Studio Addin项目已有一段时间了。 The purpose of this addin is to tell me which Store Procedures are used where in my many projects. 此插件的目的是告诉我在许多项目中的哪个位置使用了哪些存储过程。

I achive this by loading all my projects including The Business and DataAccess projects into one solution and then using EnvDTE to traverse the projects of the solution to get the specific codeitems. 通过将我的所有项目(包括业务和DataAccess项目)加载到一个解决方案中,然后使用EnvDTE遍历解决方案的项目以获得特定的代码项,可以达到这一目的。

This way I can Identify the methods calling the various Stored Procedures, and it works just great. 这样,我可以识别调用各种存储过程的方法,并且效果很好。

Then to identify which methods are calling the various methods in my DataAccess project, I use reflection to load the Assembly for each project : 然后要确定哪些方法正在调用DataAccess项目中的各种方法,我使用反射为每个项目加载Assembly:

foreach (EnvDTE.Project proj in this._solution.Projects) {
    assembly = System.Reflection.Assembly.LoadFrom(GetAssemblyPath(proj));
}

private string GetAssemblyPath(EnvDTE.Project vsProject)
{
    string assemblyPath = "";
    string fullPath = vsProject.Properties.Item("FullPath").Value.ToString();
    string outputPath = vsProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
    string outputDir = System.IO.Path.Combine(fullPath, outputPath);
    string outputFileName = vsProject.Properties.Item("OutputFileName").Value.ToString();
    assemblyPath = System.IO.Path.Combine(outputDir, outputFileName);

    return assemblyPath;
}

This system works just great for most projects, but now I have ran into a problem, and I can't get around it .... 该系统仅适用于大多数项目,但是现在遇到了一个问题,我无法解决....

Is it possible to use this sort of reflection assembly loading for a WebSite project. 是否可以对WebSite项目使用这种类型的反射程序集加载。 It fails on: 它失败于:

vsProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath")

Since the WebSite does not have an output path the same way as dll og WinForms projects has... 由于WebSite没有与dll和WinForms项目相同的输出路径,因此...

I need to use reflection since it is not possible to identify calls to overloaded methods using EvnDTE on its own. 我需要使用反射,因为无法单独使用EvnDTE识别对重载方法的调用。 With reflection I can get the instructions of a method body thereby identifying which overloaded method is being called. 通过反射,我可以获得方法主体的指令,从而确定正在调用的重载方法。

EnvDTE works fine in WebSite projects, but reflection unfortunaltely does not. EnvDTE在WebSite项目中工作正常,但不幸的是,反射却不能。 :( :(

By using EnvDTE I am only able to get the text content of a method. 通过使用EnvDTE,我只能获取方法的文本内容。

Does anyone know what to do to get this working? 有谁知道该怎么做才能工作?

It was failing because a WebSite project does not create an output assembly dll that is accessible and contains all info. 失败是因为WebSite项目未创建可访问并包含所有信息的输出程序集dll。 This is instead created on the fly by the webserver. 而是由Web服务器动态创建的。

I could not get around it and my solution was to simply convert my WebSite projects to WebApplication projects. 我无法解决它,而我的解决方案是将WebSite项目简单地转换为WebApplication项目。

These are actual normal projects and have a precompiled Assembly dll that I can access. 这些是实际的普通项目,并且具有我可以访问的预编译的Assembly dll。

Thanks for your comments... 感谢您的意见...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM