[英]how to not expose a class to any other class but one? (C#)
我有一个命名空间 ABC,它有一种形式 class、F 和一个普通的 class C。 现在我有了另一个名称空间 XYZ,其中包含许多不同的类。 现在,F 仅在 C 中使用,在程序中没有其他地方使用。 其他所有类都使用 C,而不是 F。
在 Visual Studio (2010) 中,从 XYZ 命名空间中的类中,我可以看到智能感知下拉列表中列出的 F(因为我已经引用 ABC 来使用 C)。 我该如何防止呢?我只想要 C 那里。 只要我可以使用来自 XYZ 的 C,任何方法都足够了。
谢谢。
你能在你的 C class 内部制作一个嵌套的 class 吗?
public class C
{
public C()
{ }
class F : Form
{
...
}
}
我不确定这是否适用于您的场景,但它可以解决 Intellisense 问题,同时满足上面列出的要求。
有什么理由不能将它放在另一个命名空间中以对其他类隐藏它,例如命名空间 ABC.Forms?
If it were anything other than a form class (therefore is a partial class if you are using a recent version of .net) - I would say, why not make it an inner class to C - but I doubt that would be neat with a形成 class。
我会 go 更改命名空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.