相关疑难解决方法(0)

没有注释的Protobuf-net序列化

我看了这个答案,我的情况是我不需要保持向后兼容性,我必须有一个解决方案,无需用protobuf-net所需的属性装饰数十个类.所以我尝试使用RuntimeTypeModel.Default.InferTagFromNameDefault = true;但我可能没有正确使用它,因为Serializer.Serialize调用仍然会引发异常请求合同.这是我的快速测试,我做错了什么?

public enum CompanyTypes
{
    None, Small, Big, Enterprise, Startup
}

public class BaseUser
{
    public string SSN { get; set; }    
}

public class User : BaseUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
    public DateTime BirthDate { get; set; }
    public List<string> Friends { get; set; }
    public Company Company { get; set; }
}

public class …
Run Code Online (Sandbox Code Playgroud)

c# serialization annotations protobuf-net

18
推荐指数
2
解决办法
9956
查看次数

标签 统计

annotations ×1

c# ×1

protobuf-net ×1

serialization ×1