部分类方法/属性在另一个项目中不可见

时间:2013-10-01 05:11:05

标签: c# .net partial-classes

我有一个Entity类(自动生成),如下所示:

namespace FicServerData
{
    using System;
    using System.Collections.Generic;

    public partial class Snapshot
    {
        public Snapshot()
        {
            this.ComponentQuotes = new HashSet<SnapshotPart>();
        }

        public int Id { get; set; }
        public System.DateTime Time { get; set; }
        public string Machine { get; set; }
        public string AppName { get; set; }

        public virtual ICollection<SnapshotPart> ComponentQuotes { get; set; }
    }
}

然后我写了一个实用程序部分类看起来像这样:

namespace FicServerData
{
    public partial class Snapshot
    {
        public IEnumerable<Quote> DerivedQuotes
        {
            get
            {
                ...
            }
        }
    }
}

因此,这些都是同一项目中的文件,您可以在同一名称空间中看到。现在在这个项目内我可以访问该属性,我添加没有问题。我无法从引用它的项目中访问它:我只能访问VS为我创建的Entity类。 我在这里缺少什么?

3 个答案:

答案 0 :(得分:2)

您无法跨项目访问部分类。部分类的“部分”被编译为单个程序集中的单个类。

答案 1 :(得分:1)

我的修复是重启Visual Studio。我是2017版专业版。

答案 2 :(得分:1)

我遇到了这个问题。我发现我的消费项目是通过程序集引用而不是项目引用来引用源项目。此外,被引用的程序集存储在驱动器文件夹中,并且该驱动器文件夹被添加为使用项目中的引用路径。正如您所料,我在源项目中的更新正在编译,但我引用的程序集没有编译。我删除了我消费项目中的引用,并将其重新添加为项目引用,等等!问题解决了!

不要问我为什么我的消费项目使用引用路径从同一解决方案中的另一个项目访问已编译的程序集。请不要。

相关问题