c# - .Net 中的类型转发 : Does the class forwarded need to inherit from the Type class?

标签 c# .net types forwarding

如果要使用类型转发将类引用转发到另一个程序集,该类是否需要从类型继承?

我想我真正想要的是 - Type Forwarding 的短语和概念中的“Type”一词是什么意思,或者表示什么。

最佳答案

If you want to forward a class reference to another assembly with Type Forwarding, does that class need to inherit from Type?

没有。

I guess what I am really after is - What does it mean, or what is indicated, by the word "Type" in the phrase and concept of Type Forwarding.

假设您在程序集 Alpha 中有一个类型 Foo,并且在您的下一个版本中您意识到 Foo 确实应该在程序集 Bravo 中。您不能移动类型,因为所有依赖 Foo 处于 Alpha 中的客户都将被破坏。

解决方案是将类型 Foo 移动到 Bravo 中,然后发布一个新版本的 Alpha,其中包含一个类型转发器,告诉 Alpha 用户“如果你正在寻找 Foo,它现在可以在 Bravo 中找到”。这样一来,您就不会破坏任何依赖于事物原样的人。

I think what I am missing here, is what the definition of "Type" is in the concept of Type Forwarding. What qualifies as a type?

以下是类型定义:

  • 非泛型或未构造的泛型类、结构、接口(interface)和委托(delegate)
  • 枚举

以下是类型引用(它们都引用另一种类型;这些都定义新的东西。)

  • 构造泛型类、结构、接口(interface)和委托(delegate)
  • 数组
  • 指点
  • 可空值

(并且有一种类型不属于任何一类,就是返回类型“void”。)

在所有这些类型中,只能转发类型定义。类型转发器的目的是说“过去由该程序集定义的类型现在由该程序集定义”,因此转发类型定义才有意义。您不能转发类型 MyStruct<int>[] ;那没有任何意义。可以转发MyStruct<T> .

what do you mean by "unconstructed generic classes? Does this mean only a generic's definition, and not a generic that has been instantiated with the type specified?

正确。

And can you point me to where you found the information for the "type references" and "type definitions"?

这些不是来自 C# 语言规范的概念;相反,这些是来自底层公共(public)语言基础设施类型系统的概念。如需全面了解 CLI 在定义类型和引用类型之间的区别,请阅读 ECMA 335 CLI 规范,尤其是查找有关 TypeDef 和 TypeRef 的元数据表的部分。

关于c# - .Net 中的类型转发 : Does the class forwarded need to inherit from the Type class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4635887/

相关文章:

c# - Nancy 中的应用程序管道和模块管道之间的区别?

c - 指向指针: What datatype with variable length strings?的指针

C# 相当于 perl 的 $_

c# - 单击时部分选择 DataGridView 单元格的文本

.net - 引用两个相等的程序集,只有公钥不同

c# - 是否可以使用 WCF 通过 TCP/IP 与外部系统通信?

C# - 读取并行端口状态(简单的按钮开关)

arrays - Ocaml中带有参数的类型的数组

types - 为什么要在 Haskell 中编写类型声明?

c# - 在运行时为接口(interface)创建类,在 C# 中