用于枚举源文件的插件

发布于 2024-11-19 05:18:40 字数 160 浏览 3 评论 0原文

我被要求开发一个插件,它通过 C# 解决方案并从源文件中提取所有文档并将它们导出到 HTML 文件。我们不能使用普通的文档生成器,因为导出需要采用特定的格式。

我知道如何创建基本插件,但不知道如何枚举源文件。

关于如何开始这个项目有什么想法/资源吗?

谢谢。

I've been asked to develop an addin that goes through a C# solution and extracts all the documentation from the source files and export them to an HTML file. We can't use normal document generators since the export needs to be in a specific format.

I know how to create a basic addin but have no clue as to how to go about enumerating through the source files.

Any ideas/resources on how to go about starting this project?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林迷了鹿 2024-11-26 05:18:40

这是我用来搜索以给定字符串结尾的文件的一些代码。

该结构类似于 Visual Studio 中的解决方案资源管理器:

Solution -> ProjectItems -> (Nested ProjectItems) -> FileNames

无论您的代码在何处执行,您都可以提取解决方案中的项目,然后提取这些项目中的项目项。

var typeFileName = @"\MyClassName.cs";

// Search each Project in the Solution, exclude Unit Test Projects
foreach (Project item in _applicationObject.Solution.Projects.OfType<Project>().Where(p => !p.Name.EndsWith(".Tests")))
{
    // Search each ProjectItem recursively
    foreach (ProjectItem projectItem in item.ProjectItems)
    {
        RecursiveProjectItemSearch(projectItem, typeFileName);
    }
}

asdasd

private void RecursiveProjectItemSearch(ProjectItem projectItem, string typeFileName)
{
    for (short i = 0; i < projectItem.FileCount; i++)
    {
        var fileName = projectItem.FileNames[i];

        if (fileName.EndsWith(typeFileName))
        {
            // In my case, I want to open the file that I'm searching for
            _applicationObject.ItemOperations.OpenFile(fileName);
        }

        foreach(ProjectItem childProjectItem in projectItem.ProjectItems)
        {
            RecursiveProjectItemSearch(childProjectItem, typeFileName);
        }
    }
}

我不知道这是否是执行此操作的最佳方法,但它应该有效。鉴于上面的代码,您可以将其更改为执行 File.Open() 并读取内容或类似的内容。

Here is some code I'm using to search for a file that ends with a given string.

The structure is like the Solution Explorer in Visual Studio:

Solution -> ProjectItems -> (Nested ProjectItems) -> FileNames

Wherever your code is executing, you can pull up the Projects in the Solution, and then the ProjectItems in those Projects.

var typeFileName = @"\MyClassName.cs";

// Search each Project in the Solution, exclude Unit Test Projects
foreach (Project item in _applicationObject.Solution.Projects.OfType<Project>().Where(p => !p.Name.EndsWith(".Tests")))
{
    // Search each ProjectItem recursively
    foreach (ProjectItem projectItem in item.ProjectItems)
    {
        RecursiveProjectItemSearch(projectItem, typeFileName);
    }
}

asdasd

private void RecursiveProjectItemSearch(ProjectItem projectItem, string typeFileName)
{
    for (short i = 0; i < projectItem.FileCount; i++)
    {
        var fileName = projectItem.FileNames[i];

        if (fileName.EndsWith(typeFileName))
        {
            // In my case, I want to open the file that I'm searching for
            _applicationObject.ItemOperations.OpenFile(fileName);
        }

        foreach(ProjectItem childProjectItem in projectItem.ProjectItems)
        {
            RecursiveProjectItemSearch(childProjectItem, typeFileName);
        }
    }
}

I don't know if this is the most optimal way to do this, but it should work. Given the code above you can change it to do a File.Open() and read the contents or something similar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文