如何限制用户对检查singelton例如空在C#,. NET?用户、singelton、NET

2023-09-03 22:56:23 作者:回忆都淡了

我不想为此程序员可以将用户==或!=反对我的singelton一流运营商。

I don't want that end programmer can user == or != operator against my singelton class.

最终用户不能做

如果(SingleInstace == NULL)

if( SingleInstace == null)

我重载!=和==操作符,但它并不能帮助。

I have overloaded != and == operator but it doesn't help.

我有,我要处理的一个实例,并用不同的参数初始化一个场景。例如我singelton实例DBACCESS,我想不同的服务器名称intialize它。因此,在配置单例实例,并与不同的服务器名称intialize它的调用之间;有可能是空检查呼叫。在这种情况下,我singelton实例将初始化与旧的服务器名称。

I have a scenario in which I want to dispose of the singleton instance and initialize it with different parameter. For example my singelton instance is DBAccess and I want to intialize it with different server name. Therefore in between the calls of disposing of the singleton instance and intialize it with different server name ; there may be call of null check. In that case my singelton instance will be initialize with old server name.

请帮助!

推荐答案

这是毫无意义的prevent这一点。客户端code可以随时将它转换为对象。

It is pointless to prevent this. The client code can always cast it to object.