确定 ITypeSymbol 在编译器中是否可序列化 API

Determining if ITypeSymbol is Serializable in the Compiler API

我需要检查 ITypeSymbol 看它是否可序列化。 ITypeSymbol 上没有 IsSerializable 属性 或我在编译器 API 中知道的扩展方法可以做到这一点,所以这是我能想到的最佳猜测:

我是否遗漏了任何其他可能性?

如果您想复制 Type.IsSerializable 的功能,可以查看 its reference source。它的作用是:

  • return true 如果类型具有 [Serializable] 属性
  • return true 如果类型是 DelegateEnum 或从它们继承,即如果类型是 delegateenum
  • 否则returnfalse

这意味着您的值类型和 ISerializable 实现的特殊大小写不正确。