简体   繁体   English

C# 具有自定义属性的 protobuf

[英]C# protobuf with customize attributes

I wanna generate C# protobuf code with customize attributes.我想生成具有自定义属性的 C# protobuf 代码。 such as:如:

public sealed partial class LoginIn : pb::IMessage<LoginIn>
  #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
      , pb::IBufferMessage
  #endif
  {
    [mycall] // customize attributes
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute] // original
    public LoginIn() {
      OnConstruction();
    }
   ... // rest code

With partial class , you can add attributes (and members) to the type , but you can't add attributes to individual members, so: you can't do anything simple here.使用partial class ,您可以向类型添加属性(和成员),但不能向单个成员添加属性,因此:您不能在这里做任何简单的事情。 Effectively, you'd need to tweak the code-gen itself (meaning: create your own version of the protoc addin), which is far from ideal.实际上,您需要调整代码生成本身(意思是:创建您自己的protoc插件版本),这远非理想。

The other option is manually editing the generated code - again: far from ideal.另一种选择是手动编辑生成的代码——同样:远非理想。

Before doing either of those, I'd have to ask myself some serious questions about [mycall] and how important it is, what it does, and whether adding it to the serialization model is necessary, vs creating my own domain model that can have any attributes you want , and mapping between the domain model and the serialization model.在做任何一个之前,我必须问自己一些关于[mycall]的严肃问题,它有多重要,它做什么,以及是否有必要将它添加到序列化 model与创建我自己的域 model 相比您想要的任何属性,以及域 model 和序列化 model 之间的映射。

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

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