[英]C# Visual studio needs reference to base class dll
Why do I get this problem? 为什么会出现这个问题?
Background: myClass
inherits from a class ABC
which inherits from a BaseClass
. 背景:
myClass
继承自ABC
类,而ABC
类继承自BaseClass
。 BaseClass
is a custom created class in a different namespace and contained in a different DLL assembly. BaseClass
是在不同名称空间中的自定义创建的类,并且包含在不同的DLL程序集中。
Issue: VisualStudio wants me to add a reference to the BaseClass
DLL - otherwise it won't compile myClass
. 问题: VisualStudio希望我添加对
BaseClass
DLL的引用-否则它将无法编译myClass
。
Thanks 谢谢
How could it get the metadata for the base class if you don't provide it? 如果您不提供基类的元数据,它将如何获取? It doesn't get copied from the base class to the derived class and stored in the derived class' assembly.
它不会从基类复制到派生类,也不会存储在派生类的程序集中。
Your vendor scenario is just not realistic. 您的供应商方案只是不现实的。 Nobody designs class hierarchies that are a hundred classes deep, let alone store each of them in a separate assembly.
没有人会设计一百个类的类层次结构,更不用说将它们存储在单独的程序集中了。 This tops out at six or seven, at worst.
在最坏的情况下,最高达到六到七个。 With one base assembly, sometimes two.
使用一个基座组件,有时两个。 Any deeper and nobody can understand how it works anymore.
任何更深层次的人都无法理解它是如何工作的。
Regarding your vendor
scenario - you won't be forced to reference all the libraries from vendor's library if that library doesn't expose anything from other libs and all those libs are used only internally. 关于您的
vendor
方案-如果该供应商的库未公开任何其他库中的任何库,并且所有这些库仅在内部使用,则不会被迫引用该供应商库中的所有库。
But if a library for example returns a class from another library (or it's inheritor) then of course you'll have to reference both. 但是,例如,如果一个库从另一个库(或它的继承者)返回一个类,那么您当然必须引用两者。 Just in order to get all the information about those exposed classes.
只是为了获取有关那些公开类的所有信息。
If BaseClass isn't referenced, how would your program know about it and its definition? 如果未引用BaseClass,您的程序将如何知道它及其定义? Where is it supposed to grab the meta data from if it has no reference to it?
如果没有引用元数据,应该从哪里获取?
It's like asking a web server-side related question on SO but not telling anyone what language/platform you're using - there's no frame of reference. 这就像在Web服务器端上询问有关SO的问题,但不告诉任何人您正在使用哪种语言/平台-没有参考框架。
Let's answer your questions... 让我们回答您的问题...
In order to compile the code for MyClass, it needs to know what Class did. 为了编译MyClass的代码,它需要知道Class做了什么。 In order to know what Class did, it needs to see what BaseClass did - it's like a chain.
为了知道Class做了什么,它需要查看BaseClass做了什么-就像一条链。
You need to include anything you are building against in your project. 您需要在项目中包括要构建的所有内容。 This can be done by either actually having the source for whatever in your project, or by including a reference to the project / binary where the behaviour is defined.
这可以通过在项目中实际拥有任何项目的源代码,或通过包含对定义了行为的项目/二进制文件的引用来完成。
Meta data doesn't contain any details about the actual logic in a class. 元数据不包含有关类中实际逻辑的任何详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.