C#的Downcast检测工具

cap*_*one 2 c# downcast

使用传统的中等规模项目.我已经使用Decorator模式实现了一个功能,除了它打破使用从接口到实现的向下转换的糟糕代码之外,它工作得很好.问题是:是否有任何工具或编译器标志或其他东西,可以帮助我找到使用向下转换的所有情况.我可以找到所有类型的所有案例.

我有一些代码来阐述我的问题:

曾经有

interface IComponent {}
class Concrete : IComponent {}
...
IComponent obj = new Concrete()
Run Code Online (Sandbox Code Playgroud)

现在

interface IComponent {}
class Concrete : IComponent {}
class Decorator : IComponent
{
   private IComponent _imp = new Concrete()
}
...
IComponent obj = new Decorator()
Run Code Online (Sandbox Code Playgroud)

将obj转换为Concrete时出现错误代码,如(Concrete)obj.

Bra*_*ner 5

暂时标记ConcreteObsoleteAttribute.然后检查Visual Studio中的错误列表,以获取有关使用过时代码的警告.双击这些将转到正在使用的代码Concrete.