如何限制用户对检查singelton例如空在C#,. NET? [英] How to restrict user for checking null for singelton instance in C#, .NET?

查看:117
本文介绍了如何限制用户对检查singelton例如空在C#,. NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想为此程序员可以将用户==或!=反对我的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.

这篇关于如何限制用户对检查singelton例如空在C#,. NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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