我可以使用 Protobuf-net 控制生成的类的可见性吗?
我正在使用 protobuf-net (感谢 Marc :) )来序列化我的对象模型,但我希望对象模型在程序集外部不可见(具体来说,我希望它在内部)。
默认情况下,protobuf-net 似乎生成公共部分类。我可以告诉它标记类内部
吗?
这是我的 .proto
文件的精简版本:
package MyProject.Core.Persistence;
option optimize_for = SPEED;
message DataObject {
required string name = 1;
required int32 id = 2;
}
它生成以下类定义:
[global::System.Serializable,
global::ProtoBuf.ProtoContract(Name=@"DataObject")]
public partial class DataObject : global::ProtoBuf.IExtensible
{
public DataObject () {}
...
}
I'm using protobuf-net (thanks Marc :) ) to serialize my object model, but I want the object model not to be visible outside my assembly (specifically, I want it to be internal).
By default protobuf-net seems to generate public partial classes. Can I tell it to mark the class internal
?
Here's a cut down version of my .proto
file:
package MyProject.Core.Persistence;
option optimize_for = SPEED;
message DataObject {
required string name = 1;
required int32 id = 2;
}
Which generates the following class definition:
[global::System.Serializable,
global::ProtoBuf.ProtoContract(Name=@"DataObject")]
public partial class DataObject : global::ProtoBuf.IExtensible
{
public DataObject () {}
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
目前还没有;不过,您可以编辑
csharp.xslt
以满足您自己的需要。这似乎并不常见,但可以很容易地将其添加为选项。
Not at the moment; however you can edit
csharp.xslt
to suit your own needs.This doesn't seem a common case, but it could be added as an option easily enough.
解决方案:
您可以在消息定义之前添加以下两行。
完整示例代码:
参考:
mgravell 的 protogen.proto
Solution:
you can add the following two lines before your message definition.
Full Sample Code:
Reference:
The definition of message access in mgravell's protogen.proto