如何识别VScode中未使用的方法、代码、库和引用

问题描述 投票:0回答:1

团队

我需要识别并删除 VS 代码中未使用的变量(参数、局部变量、类成员变量)、库和引用。

我也试图找到一些扩展或插件或Nuget包,但没有运气,并且也进行了很多研究,但没有找到可以满足我的需求的相关链接。我认识这个社区的一个人可以帮助我解决这个问题。

请检查下面的代码示例以了解未使用的代码,我想要一些东西来识别未使用的代码并希望删除它们。

using System;
using System.Diagnostics; //unused
using Microsoft.AspNetCore.Mvc; //unused
using Microsoft.AspNetCore.Mvc.RazorPages; //unused

public class HelloWorld
{
    public string? RequestId { get; set; } //unused 
    private readonly ILogger<ErrorModel> _logger; //unused
    public static void Main(string[] args)
    {
        Console.WriteLine ("Hello Mono World");
    }
    public ErrorModel(ILogger<ErrorModel> logger) // This method is unused
    {
       //Some code here
    }

}
c# visual-studio-code code-cleanup unused-variables unused-functions
1个回答
0
投票

使用 C# Dev Kit 进行 VSCode 扩展,即使该函数仅返回一个任务,它似乎也没有突出显示任务中的一些非原始情况。

在示例中,检测到所有未使用的原始

foo
,但是
anotherTest
实例未在
ReturnTaskTest()
中检测为未使用。

© www.soinside.com 2019 - 2024. All rights reserved.