有没有一种方法可以通过将某个类/接口/...括在其名称空间中而不是使用 using 指令“using namespace_name”来引用它?

发布于 2024-10-12 06:21:09 字数 844 浏览 1 评论 0原文

有没有一种方法可以通过将某个类/接口/...括在其名称空间中而不是使用 using 指令“using namespace_name”来引用它?

因为,我正在开发一个使用 SAP .NET 连接器的网站。我已经添加了对连接器 ddl 的引用,并且在引用其命名空间“使用命名空间_名称”时,或者将类命名空间设置为另一个命名空间而不是连接器命名空间时,

我收到了有关连接器类的错误,并显示错误消息“类型或命名空间无法找到了,您是否缺少 using 指令或程序集引用?”。

但是,当将命名空间名称更改为连接器命名空间时,一切都进展顺利?!

// Set namespace to be IDestinationConfiguration interface namespace.
// Using this, everything is going well.
namespace SAP.Middleware.Connector
{
    public class ConnectorConfiguration : IDestinationConfiguration
    {
    }
}

// Using that way; it's not working, and got an error regarding IDestinationConfiguration even it belongs to refernced namespace.
using SAP.Middleware.Connector;

public class ConnectorConfiguration : IDestinationConfiguration
{
}

因此,连接器类型迫使我将类的名称空间设置为其名称空间!

这可能吗?如果是这样,怎么办?

Is there a way to reference a certain class/interface/... by enclosing it with its namespace rather than a using directive "using namespace_name" ?!

As, I'm working on a website, which uses SAP .NET connector. I already added a reference for connector ddl, and while referencing its namespace "using namespace_name", or set class namespace to another one rather than connector namespace,

I got error regarding connector classes with that error message "The type or namespace couldn't be found, are you missing a using directive or an assembly reference?".

But while changing namespace name to connector namespace, everything is going well?!

// Set namespace to be IDestinationConfiguration interface namespace.
// Using this, everything is going well.
namespace SAP.Middleware.Connector
{
    public class ConnectorConfiguration : IDestinationConfiguration
    {
    }
}

// Using that way; it's not working, and got an error regarding IDestinationConfiguration even it belongs to refernced namespace.
using SAP.Middleware.Connector;

public class ConnectorConfiguration : IDestinationConfiguration
{
}

So, connector types forced me to set namespace of class to their namespace!

Is this possible? If so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫性小仙女 2024-10-19 06:21:09

我也遇到了这个问题,直到我最终在 http://forums.sdn.sap.com/thread.jspa?threadID=1876430,最后一行说:

“此外,请确保您的目标框架不是“.NET v4.0” “.NET v4.0 Client”——这样您就可以获得所需的 System.Web 命名空间。”

我的项目针对 4.0 客户端目标框架。当我将其更改为 .NET Freamework 4.0 后,所有引用都按预期工作。

I ran into this too and couldn't figure it out until I finally found the answer on a post at http://forums.sdn.sap.com/thread.jspa?threadID=1876430, the last line which said:

"Also, make sure your target framework is ".NET v4.0" NOT ".NET v4.0 Client" -- that way you get the System.Web namespace that is required."

My project was targeting 4.0 client target framework. Once I changed it to just .NET Freamework 4.0, all the references worked as expected.

初心未许 2024-10-19 06:21:09

这就是你所追求的吗?

public class ConnectorConfiguration: SAP.Middleware.Connection.IDestinationConfiguration
{

}

如果您愿意,您可以在不使用 using 的情况下编写所有代码,只需为不使用 using 的每个类/接口使用完全限定的命名空间名称即可。

如果您尝试这样做:

using SAPTEST = SAP.Middleware.Connection;
namespace TestNamespace 
{
   public class ConnectorConfiguration: SAPTEST.IDestinationConfiguration
   {
   }
}

如果这有效,但如果删除 SAPTEST 则不起作用,则 IDestinationConfiguration 也必须在另一个命名空间中声明。

Is this what you are after?

public class ConnectorConfiguration: SAP.Middleware.Connection.IDestinationConfiguration
{

}

You can write all your code without usings if you like, you just need to use the fully qualified namespace name for every class/interface where the using isn't used.

If you try this:

using SAPTEST = SAP.Middleware.Connection;
namespace TestNamespace 
{
   public class ConnectorConfiguration: SAPTEST.IDestinationConfiguration
   {
   }
}

If that works, but it doesn't work if you remove SAPTEST, then IDestinationConfiguration must be declared in another namespace too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文