创建带有接口的类。然后在代码隐藏中迭代它

发布于 2024-11-04 06:15:33 字数 729 浏览 1 评论 0原文

我有一个关于包含接口的类的问题。我有大约 12 个类,它们的接口都相同。现在,我需要列出所有课程。该功能中可能会创建 1000 个新类别。但由于它们负责设备,有时某些类已经过时了。

好的。 列出所有类是没有问题的

dim ClassList as new List(Of MyInterface)
ClassList.Add(New MyFirstItem())
ClassList.Add(New MySecondItem())
ClassList.Add(New MyThirdItem())
ClassList.Add(New ...)

使用我现在

For each item as MyInterface in ClassList
   'Print info
next

正在做的事情

我想问是否可以告诉 Visual Studio 或我的应用程序,我有一个解决方案文件夹,其中写入了所有类,并自动将这些项目添加到列表中。或者像插件一样做。我想避免上面的行。我想避免仅仅为每个类中的某些代码行创建一个完整的新项目。

ClassList.Add(New ...) 'would like to avoid this to do manually

只是为了创建一个实例并立即再次处理它以在屏幕上写入类信息。

希望我能解释我的问题

问候

I have a question about classes with including interfaces. I have about 12 classes with all the same interface in it. Now, I need to list all classes. In the feature there could be 1000 new classed to create. But because they are responsible for devices some times some classes are obsolete.

Ok. No problem to list all classes by using

dim ClassList as new List(Of MyInterface)
ClassList.Add(New MyFirstItem())
ClassList.Add(New MySecondItem())
ClassList.Add(New MyThirdItem())
ClassList.Add(New ...)

then

For each item as MyInterface in ClassList
   'Print info
next

that what I am doing NOW.

I want to ask if it is possible tell visual studio or my application that I have one solution folder with all classes written in and to add automatically these items to the list. Or do it like plugins. I want to avoid the lines above. And I want to avoid creating a complete new project just for some lines of code in each class.

ClassList.Add(New ...) 'would like to avoid this to do manually

just to create an instance and dispose it immediately again for writing the class information on screen.

Hope I could explain my question

Regards

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

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

发布评论

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

评论(1

┾廆蒐ゝ 2024-11-11 06:15:33

假设您的所有类都位于各自的文件中,并在目录中命名为它们的类名,您可以做一个小应用程序,将您的行输出到文本文件,如下所示:

String[] Files= Directory.GetFiles("PATH", "*.cs");                
foreach (String file in Files)
{
    WriteLine("ClassList.Add(new " + file.Replace(".cs", "") + ");");
}

Assuming all of your classes are in their own files named their class name in the directory you could do a little app that would output your lines to a text file like this:

String[] Files= Directory.GetFiles("PATH", "*.cs");                
foreach (String file in Files)
{
    WriteLine("ClassList.Add(new " + file.Replace(".cs", "") + ");");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文