【发布时间】:2013-02-12 10:57:04
【问题描述】:
我们正在使用 protobuf-net 来处理 C# 应用程序中的协议缓冲区需求。由于我们与其他非托管应用程序共享我们的 .proto 文件,因此我们从 .proto 文件生成我们的代码(不使用代码优先的 protobuf-net 方法)。为了尽可能保持DRY,我们在 .proto 文件中保留了大量的接口文档。我们通过项目构建目标调用的 protogen.exe 生成 C# 代码。
现在,有什么方法可以(自动)将这些 cmets 传输到已编译的 C# 代码中?
基本上,给定一个像这样的 .proto:
// This message is used to request a resource from the server
message GetResource
{
// The identifier of the requested resource
required string resourceId = 1;
}
...我想要这样的东西(为了便于阅读,省略了 IExtensible 方法):
/// <summary>
/// This message is used to request a resource from the server
/// </summary>
[global::System.Serializable,global::ProtoBuf.ProtoContract(Name=@"GetResource")]
public partial class GetResource : global::ProtoBuf.IExtensible
{
public GetResource() {}
private string _resourceId;
/// <summary>
/// The identifier of the requested resource
/// [Required] <-- Would be nice...
/// </summary>
[global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"resourceId",
DataFormat = global::ProtoBuf.DataFormat.Default)]
public string ResourceId
{
get { return _resourceId; }
set { _resourceId = value; }
}
}
【问题讨论】:
-
据我所知,现在这适用于 proto 3.0.0 中的
protoc。 Itz 适用于 C# 和 Java,但不适用于 C++ AFAIKT -
是的,终于!像魅力一样工作。
标签: c# .net protocol-buffers protobuf-net documentation-generation