我很可能没有正确描述我的标题,并且完全缺乏我想要做的事情的术语......所以如果你正在阅读这篇文章并且知道我应该要求什么......请分享。
所以这是我的问题。我正在创建一个 DLL。这个 DLL 里面当然会有几个类。调用解决方案将需要访问这些类及其各种方法。
但是,我想强制调用程序仅创建“Parent\Root”类的一个实例,因为我需要某些信息,只要他们将使用属于此类的任何内容(想想有点像许可证密钥,但不是真的)。
所以从客户的角度来看..我希望它像这样工作..
FooDll.Client myFooClient = new FooDLL.Client(myLicensesKey)
myFooClient.Store.PlaceOrder()
myFooClient.Shop.FixWidget()
现在从我的DLL方面,我在想这样的事情......
public class Client
{
public StoreLogic Store {get;} //This is a internal Class that contains the method PlaceHolder
public ShopLogic Shop {get;} //This is an internal Class that contains the method FixWidget
public Client(string LicenseKey)
{
set some internal global flags for the entire library
}
}
现在,只要我将 StoreLogic 和 ShopLogic 类声明为“Public”,我就可以做到这一点。但如果我这样做,客户现在可以这样做......
FooDll.StoreLogic myStore = new FooDLL.StoreLogic()
这是我不想要的。