数据契约序列化器。将元数据导出到一个命名空间

发布于 2024-12-29 07:03:30 字数 1106 浏览 2 评论 0原文

我想要 svcutil 将元数据从我的库导出到一个 xsd 文件中。由于它将元数据按命名空间划分为不同的文件,因此我想将所有类重新定义为唯一的命名空间。 我可以“尝试”通过两种方式做到这一点: 1)为 DataContract 属性中的每个类重新定义它,如下所示 [DataContract(命名空间=“http://mynamspace.com”)] 但我遇到了下一个障碍 - 我无法在从标准类派生的类上设置属性

2)为程序集中的每个命名空间重新定义命名空间,其中包括导出类。 [程序集:ContractNamespaceAttribute(SerializationConstants.DefaultNamespace,ClrNamespace =“UBP.AddInfo”)] 但在这里,我挑战另一个问题 - 该指令不反映枚举。它们仍然被导出到程序集中定义的命名空间中。所以它迫使我直接将属性 DataContract 设置为这些枚举。但!!!!在这种情况下,枚举导出不正确。而不是

  <xs:simpleType name="AddInfoValueType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="String" />
      <xs:enumeration value="DateTime" />
      <xs:enumeration value="Number" />
      <xs:enumeration value="BynaryData" />
    </xs:restriction>
  </xs:simpleType>

我得到

  <xs:simpleType name="AddInfoValueType">
    <xs:restriction base="xs:string" />
  </xs:simpleType>

有没有人挑战过这样的问题?

I want to svcutil to export metadata from my libraries into one xsd file. As it divides metadata into different files by namespace, I want to redefine it for all classes to sole namespace.
I can "try" do it by two ways:
1) Redefine it for each class in DataContract attribute like this
[DataContract(Namespace="http://mynamspace.com")]
but i get the next obstacle - I can't set atribute on class that is derived from standard class

2)Redefine namespace for each namespace in assembly, which includes exporting classes.
[assembly: ContractNamespaceAttribute(SerializationConstants.DefaultNamespace, ClrNamespace = "UBP.AddInfo")]
But here, I challenge another problem - this directive doesn't reflect on enumeratons. They remain being exported into namespace as it defined in assembly. So it forced me to set attribute DataContract to these enums directly. BUT!!!! in this case enumeration is exported incorrectly. Instead of

  <xs:simpleType name="AddInfoValueType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="String" />
      <xs:enumeration value="DateTime" />
      <xs:enumeration value="Number" />
      <xs:enumeration value="BynaryData" />
    </xs:restriction>
  </xs:simpleType>

I get

  <xs:simpleType name="AddInfoValueType">
    <xs:restriction base="xs:string" />
  </xs:simpleType>

Has anyone challenged such problems?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掀纱窥君容 2025-01-05 07:03:30
  1. 这通常是我会走的路线 - 给你精确的控制。以及从系统类型派生的问题。有一个老笑话男人:“医生医生,当我这样做时会很痛”医生:“那就不要这样做”。我会避免从服务边界上的系统类型派生,而只定义要传输的数据。显然我不知道你的确切情况,但这是我会采取的一般方法

  2. 你可以混合和匹配这两种方法 - 你应该能够使用[DataContract]来注释枚举并且每个枚举成员都带有 [EnumMember] ,这应该可以满足您的需求

  1. This is generally the route I'd go - gives you precise control. And the issue with deriving from a system type. There is an old joke Man: "doctor doctor it hurts when I do this" Doctor: "Then don't do it". I'd avoid deriving from system types on my service boundaries and just define the data you want to transport. Obviously I don't know your exact situation but that's the general approach I'd take

  2. You can mix and match the two approaches - You should be able to annotate the enums with [DataContract] and each enum member with [EnumMember] and that should give you what you need

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文