开发者

Namespace and Type issue

I have a solution with two projects. One namespace is MarketplaceWebServiceOrders and the other is MarketsplaceWebServiceOrders.Sample. I have public interface in the MarketplaceWebServiceOrders called MarketplaceWebServiceOrders. My main function is in MarketplaceWebServiceOrders.Sample and whenever I try to use the interface MarketplaceWebServiceOrders I get Error: MarketplaceWebServiceOrders.Samples.MarketplaceWebServiceOrde开发者_如何学Pythonrs is namespace used use like a type.

I actually have this program compiled and running but I need to make changes and this popped up.


In this case you can access your interface specifying full name with namespace:

MarketplaceWebServiceOrders.MarketplaceWebServiceOrders instance = new ...();

Anyway, your naming looks wrong. You are probably misusing namespaces - they should "categorize" types, no need to have type name the same as namespace. Moreover, interfaces are prefixed with I letter by good convention.


You may want to consider refactoring your code to make the namespace and types a little less ambiguous. One of the purposes of namespaces is to organize code, so it's a bit redundant to have the same name in both the namespace and the type.


Well, the error states that you have an additional namespace level MarketplaceWebServiceOrders in the MarketplaceWebServiceOrders.Sample namespace. Is this true? If so, you will need to fully qualify the usage of the interface from the base namespace: MarketplaceWebServiceOrders.MarketplaceWebServiceOrders is the interface you say you want. Just don't use the base MarketplaceWebServiceOrders namespace in this code file.

To avoid this confusion if at all possible I would change the namespace name or the interface. The interface would be easier; add an "I" to the front of the identifier if it is an actual C# interface type (it's recommended naming convention in most C-style languages).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜