【问题标题】:How to use this class in my c# code如何在我的 C# 代码中使用这个类
【发布时间】:2023-03-30 06:31:01
【问题描述】:

我将如何使用此类中的 IAxaptaWrapper ?

 namespace Axapta
{
    internal class Axapta : IAxaptaWrapper

namespace Axapta
{
    public class AxThreadedWrapper: IAxaptaWrapper
    {

我尝试引用 dll 库,然后

像这样使用它

using (IAxaptaWrapper Ax = new AxThreadedWrapper())

        {

找不到类型或命名空间名称“AxThreadedWrapper”(您是否缺少 using 指令或程序集引用?)

【问题讨论】:

  • 您是否在项目中添加了对 Axapta 库的引用?

标签: c# namespaces


【解决方案1】:

你需要一个 using 指令而不是 using 语句。它们是不同的。

using directive 允许您在代码中省略命名空间限定符。您需要一个用于 IAxaptaWrapper 和 AxThreadedWrapper 的 using 指令。它们很可能在同一个命名空间中。

using statement 有效地包装了 try-finally 。Dispose 围绕代码块。仅当对象实现 IDisposable 时才使用它。


现在您已将internal 添加到班级。这意味着您不能在另一个程序集中使用它(以正常方式)。非嵌套类的默认access modifierinternal,因此您需要将其替换为public,因为您想从另一个程序集访问它。

【讨论】:

    【解决方案2】:

    使用 using 指令在类的顶部添加对 Axapta 的引用。

    using Axapta;
    using System; 
    

    【讨论】:

    • @UserAnonymous 您使用的是 statement,而不是使用 directive
    • 这可能有点令人困惑......您是否同时拥有我详细介绍的 using 指令和您在问题中提到的 using 语句?
    • 使用 (IAxaptaWrapper Ax = new AxThreadedWrapper()) { Ax.Logon("Auto", "", "", "Original (installed configuration)");
    • “参考”是完全不同的东西。它们不在源代码中,它们是编译器参数(通常在项目中设置。)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多