繁体   English   中英

将XmlSerializer类转换为protobuf-net用法

[英]Convert XmlSerializer class to protobuf-net usage

目前我正在尝试使用带有C#的protobuf-net。 我有一个使用System.Xml.Serialization序列化的类;

[XmlType(Namespace="http://www.test.com")]
[XmlRoot(Namespace="http://www.test.com", ElementName="message", IsNullable=false)]
public class TestMessage 
{
    /// <remarks/>
    [XmlAttribute(Form=XmlSchemaForm.Unqualified)]
    public string specificationversion;

    [XmlElement("errornotification", typeof(errorNotificationfType))]

    [XmlIgnore()]
    public bool ProductCodeSpecified;

    public string SubText;

    [XmlElement(DataType = "hexBinary")]
    public List<byte[]> Index;

    [XmlAttribute()]
    public bool Complete;

    public object Item;

    /// <remarks/>
    public InfoType info;
}

现在我想将此部分转换为与protobuf-net一起使用。

我看过一些例子并开始:

[ProtoContract]
public class TestMessage 
{
    [ProtoMember(1)]
    ....
    ....
}

现在我被卡住了。 有人可以帮我改变这门课吗? 我应该如何处理XmlType,XmlRoot,XmlAttribute,XmlElement和XmlIgnore部分?

我认为你可以忽略它们,因为它的外观Protobuf没有属性,元素,根或命名空间,所以所有这些都成为ProtoMember

[ProtoContract]
public class TestMessage 
{
    [ProtoMember(1)]
    public string specificationversion;

    // ignore
    public bool ProductCodeSpecified;

    [ProtoMember(2)]
    public string SubText;

    [ProtoMember(3)]
    public List<byte[]> Index;

    [ProtoMember(4)]
    public bool Complete;

    public object Item;

    [ProtoMember(5)]
    public InfoType info;
}

有一些很好的例子在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM