如何在另一个项目中重用“类型别名”?

How can I reuse "type alias" in another project?

提问人:sorosh_sabz 提问时间:6/5/2023 最后编辑:Peter Mortensensorosh_sabz 更新时间:8/9/2023 访问量:130

问:

我有一个项目,其中包含一些接口,其中包含某种类型别名,如下所示:

namespace UsingTest
{
    using MyType = System.Collections.Generic.List<int>;

    public interface IUsingTest
    {
        MyType GetList();
    }
}

我怎样才能在另一个项目中使用,如下所示?(无需重新定义MyTypetype alias)

namespace UsingTest
{
    public class UsingClass : IUsingTest
    {
        public MyType GetList()
        {
            throw new NotImplementedException();
        }
    }
}

注意:如果我想在同一个项目中编写上述代码,正如您在如何在 C# 中为类名添加别名中看到的那样,而不必向使用该类的每个文件添加一行代码?,我只需要在接口文件中声明。但是这种技术在多个项目之间不起作用。MyTypeglobal using

C 类型别名 使用指令 C#-10.0

评论


答: 暂无答案