我通过继承Type来获得一个固定点类型(参考this post)。我可以将这个项目命名为a.dll。
namespace System
{
public class FixedPointDataType : Type
{
public Boolean Signed { get; set; }
public int Width { get; set; }
public int IntegerWidth { get; set; }
public FixedPointDataType(Boolean signed = false, int width = 16, int integerWidth = 8)
{
Signed = signed;
Width = width;
IntegerWidth = integerWidth;
}
...
我有另一个项目b.dll,它使用a.dll中的System.FixedPointDataType
。
在项目b中引用a.dll后,当我尝试编译项目b中的文件abc.cs时,我收到此错误。
Error 2 'System.FixedPointDataType' is inaccessible due to its protection level
abc.cs
可能有什么问题?
我需要添加public
并为名称空间提供全名 - System.FixedPointDataType
。修改后我得到了错误,但是当我重建整个解决方案时,错误被删除了。感谢您的评论和解答。
答案 0 :(得分:2)
您的课程未被宣布为public
;或者是在您更改帖子并重建项目之前。
但我支持先前的评论,你应该不子类Type
或将成员添加到命名空间System
。
如果两个项目在同一个解决方案中,请确保添加对项目的引用,而不仅仅是作为项目输出的DLL。如果您不添加对项目的引用,VS将不知道构建您的解决方案的顺序,并且您可能引用了过时的版本。
答案 1 :(得分:1)
您的其他帖子没有告诉我们您用于FixedPoint类的命名空间。
我建议你需要一个Using语句或者完全限定类型名称。
编辑:噢,我的时机不好!如果您上面描述的代码是准确的(确定您没有从类中错过'public'),也许这是因为您正在使用System命名空间,而我有没有证据,可能是一个特例。
看看如果更改命名空间会发生什么。