简体   繁体   English

Visual Studio中多个名称空间中的相同类名

[英]Same class name in multiple namespaces in Visual Studio

How to know if there is a class name repeated in different namespaces in Visual Studio? 如何知道Visual Studio中不同名称空间中是否重复了类名? Obviously I'm not looking to test every class name manually. 显然,我不是要手动测试每个类名。

I'd just write a unit test that uses reflection. 我只是写一个使用反射的单元测试。 Something like: 就像是:

var duplicateGroups = typeof(SomeTypeInAssembly).GetTypes()
    .GroupBy(t => t.Name)
    .Where(g => g.Count() != 1);
// Assert that duplicateGroups is empty

Exactly how you assert that the collection is empty will depend on your test framework - you'll also want to make sure that when the test does fail, it gives you a useful failure message, ideally a list of the types in each group. 确切地说,您如何断定集合为空将取决于您的测试框架-您还将要确保,当测试确实失败时,它会为您提供有用的失败消息,最好是每个组中的类型列表。

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

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