简体   繁体   中英

C# protobuf with customize attributes

I wanna generate C# protobuf code with customize attributes. 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. Effectively, you'd need to tweak the code-gen itself (meaning: create your own version of the protoc addin), which is far from ideal.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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