C# 将XmlSerializer类转换为protobuf网络使用
目前,我正在使用protobuf net和C#进行实验。 我有一个使用System.Xml.Serialization序列化的类C# 将XmlSerializer类转换为protobuf网络使用,c#,protobuf-net,C#,Protobuf Net,目前,我正在使用protobuf net和C#进行实验。 我有一个使用System.Xml.Serialization序列化的类 [XmlType(Namespace="http://www.test.com")] [XmlRoot(Namespace="http://www.test.com", ElementName="message", IsNullable=false)] public class TestMessage { /// <remarks/> [
[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;
}
现在我被卡住了。有人能帮我把这门课改成英语吗?那么我应该如何处理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;
}
[协议]
公共类测试消息
{
[原成员(1)]
公共字符串规范版本;
//忽略
指定的公共布尔产品代码;
[原成员(2)]
公共字符串潜文本;
[原成员(3)]
公共列表索引;
[原成员(4)]
公共布尔完成;
公共物品;
[原成员(5)]
公共信息类型信息;
}
这里有一些很好的例子。您可能希望多尝试一点,展示您遇到的确切问题,而不是只是过来请其他人帮您解决。谢谢!我要试试看。
[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;
}