简体   繁体   English

每个文件输出一个带有原语的C#类?

[英]Output one C# class per file with protogen?

Is it possible to have protogen output multiple files (one per class) based on a single .proto file? 是否可以让progengen根据单个.proto文件输出多个文件(每个类一个)?

I'm working with a very large .proto file that outputs approx 200 classes, currently all in a single file. 我正在处理一个非常大的.proto文件,该文件输出大约200个类,当前全部在一个文件中。 One of the places where I need to use the generated classes is in a highly memory constrained environment (a Windows Phone background agent). 我需要使用生成的类的地方之一是在高度内存受限的环境中(Windows Phone后台代理)。

I'd like to be able to only include the necessary classes in the assembly loaded in the constrained environment but can't easily do this when the generated classes are all in a single file. 我希望只能在受约束的环境中加载的程序集中包括必要的类,但是当生成的类都在单个文件中时,不能轻易做到这一点。 If I could have them outputted to multiple files I could only link in the ones I need in the assembly for the constrained environment. 如果我可以将它们输出到多个文件中,那么我只能链接受约束的环境中我所需的文件。

Is there a way to have protogen output the classes in separate files? 有没有办法让原语将类输出到单独的文件中? I can't see an option for this and am currently only using the umbrella-classname option. 我看不到此选项,目前仅使用umbrella-classname选项。

Manually editing the generated file is not an option so if protogen can't do it, is there another commandline tool available which can split up a file containing multiple classes? 手动编辑生成的文件不是一种选择,因此,如果protogen无法做到这一点,是否有另一个命令行工具可以拆分包含多个类的文件? (To save reinventing the wheel.) (以免浪费时间。)

Update 更新资料
I'm using Google.ProtocolBuffers.dll an inherited decision and not easily changable. 我使用的是Google.ProtocolBuffers.dll继承的决定,不容易更改。
Editing/splitting the .proto file is also not a posibility. 编辑/拆分.proto文件也不是可行的。 (Unless as a custom step.) (除非作为自定义步骤。)

We have an option for this in csharp_options, but it's not implemented: 我们在csharp_options中有一个选项,但尚未实现:

// Whether to generate a single file for everything within the
// .proto file (false), or one file per message (true).
// This option is not currently honored; please log a feature
// request if you really want it.
optional bool multiple_files = 4;

Given that you'd have to remove relevant files and make sure you got all the dependencies right it sounds like it wouldn't actually save you much work over the solution I'd suggest, which is to split your proto file into separate ones You say this is "also not a possibility" but basically that's all I can suggest at the moment - why is it not a possibility? 鉴于您必须删除相关文件并确保正确安装了所有依赖项,这听起来似乎并没有为我建议的解决方案节省很多工作,该解决方案是将原始文件拆分为单独的文件,说这“也不是不可能”,但基本上这就是我目前所能建议的- 为什么没有可能性?

EDIT: I've just had another idea. 编辑:我刚刚有另一个想法。 You could potentially run the protoc step of protogen (which is now done automatically if you don't specify otherwise) to parse the .proto file into its descriptor. 你可能运行protoc步骤protogen (它如果没有另行指定,现已自动完成)的解析.proto文件到其描述。 Then load the descriptor in another program, mutate it as you would any other protobuf message (create a builder from it, edit the message, build) and then save the descriptor. 然后将描述符加载到另一个程序中,就像处理其他protobuf消息一样对其进行突变(从中创建一个构建器,编辑该消息,然后构建),然后保存该描述符。 You can then use protogen on the remaining descriptor, and generate only the classes you want... 然后,您可以在剩余的描述符上使用protogen,并仅生成所需的类。

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

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