如何强制构造函数缩写? [英] How to enforce a constructor constrictor?

查看:93
本文介绍了如何强制构造函数缩写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆基本上是根据参数测试某些东西的类,并告诉我他们代表的东西是否完整。



例如,DownloadTester将传递一个文件名,大小将检查文件是否存在且是否为给定大小,EmailTester将收到一封电子邮件地址和主题,并检查是否收到了这样的电子邮件等。



我想要一个带有一系列参数的通用构造函数,所以我可以这样做以插件方式。如果接口无法指定关于类构造函数的任何内容,那么最好的方法是什么?

I have a bunch of classes that are designed to basically test something based on parameters and tell me if the thing they represent is complete or not yet.

For example the "DownloadTester" will be passed a filename and size will check if the file exists and is the given size, and the "EmailTester" will take an email address and subject and check if such an email has been received etc.

I'd like to have a generic constructor that takes an array of parameters so I can do this in a plug-in manner. What is the best way of doing this given an interface cannot specify anything about a class constructor?

推荐答案

这听起来不像构造函数的正确任务。听起来你只想要一个普通的实例方法,它可能通过 params string []参数或类似的方式得到它的参数。



他们可以在界面中指定。



That doesn't sound like the proper task for a constructor. It sounds like you just want an ordinary instance method that perhaps gets its parameters via params string[] parameters or similar.

They can specified in an Interface.

public interface ITest
{
  bool Test ( params string[] parameters ) ;
}


这篇关于如何强制构造函数缩写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆