1

我有一个 XML

<Where>
    <And>
        <Eq>
            <Key>Name</Key>
            <Value>Value</Value>
        </Eq>
        <Or>
            <NEq>
                <Key>Name</Key>
                <Value>Value</Value>
            </NEq>
            <And>
                <NEq>
                    <Key>Name</Key>
                    <Value>Value</Value>
                </NEq>
                <Eq>
                    <Key>Name</Key>
                    <Value>Value</Value>
                </Eq>
            </And>
        </Or>
    </And>
</Where>

有没有办法定义一些将由 DataContractSerializer 以这种方式序列化的类?

我尝试使用 KnownTypes 和 CollectionDataContract 属性,但我无法找到正确的方法。

  <DataContract()>
  <KnownType(GetType(Eq))>
  <KnownType(GetType(NEq))>
  <KnownType(GetType(Gt))>
  <KnownType(GetType(Lt))>
  <KnownType(GetType(GEq))>
  <KnownType(GetType(LEq))>
  <KnownType(GetType(IsNull))>
  <KnownType(GetType(IsNotNull))>
  <KnownType(GetType(Contains))>
  Public MustInherit Class Operation
    <DataMember(IsRequired:=True, Order:=1)>
    Public Key As String
    <DataMember(IsRequired:=False, Order:=2)>
    Public Value As String
  End Class

  <DataContract(Name:="Eq")>
  Public Class Eq
    Inherits Operation
  End Class

  <DataContract(Name:="NEq")>
  Public Class NEq
    Inherits Operation
  End Class
...

  <KnownType(GetType([Or]))>
<KnownType(GetType([And]))>
<CollectionDataContract()>
  Public Class LogicalOperation
    Inherits ObjectModel.Collection(Of Object)
  End Class

  <CollectionDataContract(Name:="And")>
  Public Class [And]
    Inherits LogicalOperation
  End Class

  <CollectionDataContract(Name:="Or")>
  Public Class [Or]
    Inherits LogicalOperation
  End Class

而且只有

    <Where>
       <anyType i:type="And">
          <anyType i:type="IsNull">
             <Requisites>sdf</Requisites>
             <Value i:nil="true"/>
          </anyType>
          <anyType i:type="LEq">
             <Requisites>sdf</Requisites>
             <Value>sdf</Value>
          </anyType>
          <anyType i:type="LEq">
             <Requisites>123</Requisites>
             <Value>123</Value>
          </anyType>
          <anyType i:type="And">
             <anyType i:type="IsNull">
                <Requisites>sdf</Requisites>
                <Value i:nil="true"/>
             </anyType>
             <anyType i:type="LEq">
                <Requisites>sdf</Requisites>
                <Value>sdf</Value>
             </anyType>
             <anyType i:type="LEq">
                <Requisites>123</Requisites>
                <Value>123</Value>
             </anyType>
          </anyType>
       </anyType>
    </Where>

如何将 objectType 名称设置为标签名称?

4

0 回答 0