protobuf 自动生成c# .cs文件 -protogen用法


usage: protogen -i:{infile2} [-i:{infile2}] [-o:{outfile}] [-t:{template}] [-p:{prop}[=value]] [-q] [-d]

-i: Input file(s); proto definitions, either as text or pre-compiled binary (via protoc)
-o: Output file; if none specified, writes to stdout
-t: Template to use; defaults to csharp
-p: Property for the template; value defaults to true; use -p:help to view available options
-q: Quiet; suppresses header
-d: Include all dependencies of the input files in the set so the set is self-contained.
-ns: Default namespace; used in code generation when no package is specified


C:\protobuf-net\ProtoGen>protogen -p:help
protobuf-net:protogen - code generator for .proto

        CSharp template for protobuf-net.
        Options:
        General:
          "help" - this page
        Additional serializer support:
          "xml" - enable explicit xml support (XmlSerializer)
          "datacontract" - enable data-contract support (DataContractSerializer; requires .NET 3.0)
          "binary" - enable binary support (BinaryFormatter; not supported on Silverlight)
        Other:
          "protoRpc" - enable proto-rpc client
          "observable" - change notification (observer pattern) support
          "preObservable" - pre-change notification (observer pattern) support (requires .NET 3.5)
          "partialMethods" - provide partial methods for changes (requires C# 3.0)
          "detectMissing" - provide *Specified properties to indicate whether fields are present
          "lightFramework" - omit additional attributes not included in CF/Silverlight
          "asynchronous" - emit asynchronous methods for use with WCF
          "clientProxy" - emit asynchronous client proxy class
          "import" - additional namespaces to import (semicolon delimited)
          "fixCase" - change type/member names (types/properties become PascalCase; fields become camelCase)

  "observable" - change notification (observer pattern)  support
属性成员会继承 global::System.ComponentModel.INotifyPropertyChanged接口,并在set 方法中实现  set { OnPropertyChanged(@"***"); _*** = value; }

  "preObservable" - pre-change notification (observer pattern) support (requires .NET 3.5)
属性成员会继承 global::System.ComponentModel.INotifyPropertyChanging,并在set方法中实现 OnProerthChanged

  "detectMissing" - provide *Specified properties to indicate whether fields are present
对于option成员,添加 *Specified() 接口,判断该成员函数是否被赋值


  注:使用detectMissing选项 和 不使用,如果有option成员为空,序列化时,字节长度会不一样

示例:
cd C:\protobuf-net\ProtoGen
protogen -i:apm\umi_msg_apm_enum.proto -o:umi_msg_apm_enum.cs  -p:detectMissing

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值