0
protogen.exe
が.proto
ファイルに適用された場合、各プロパティにゲッター(セッターではない)があるクラスC#
を生成できますか?protobuf-net:なぜ生成されたクラスにセッターがないのですか?
package MyLibrary.MyProto
import "MyExternalType.proto";
option optimize_for = SPEED;
message MyProto {
repeated MyExternalType MyProperty = 1;
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// Generated from: MyLibrary.MyProto
// Note: requires additional types generated from: MyExternalType.proto
namespace MyLibrary
{
[global::System.Serializable, global::ProtoBuf.ProtoContract([email protected]"MyProto")]
public partial class MyProto : global::ProtoBuf.IExtensible
{
public MyProto() {}
private readonly global::System.Collections.Generic.List<MyExternalType> _MyProperty = new global::System.Collections.Generic.List<MyExternalType>();
[global::ProtoBuf.ProtoMember(1, [email protected]"MyProperty", DataFormat = global::ProtoBuf.DataFormat.Default)]
public global::System.Collections.Generic.List<MyExternalType> MyProperty
{
get { return _MyProperty; }
}
private global::ProtoBuf.IExtension extensionObject;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
{ return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }
}
}
私は 'proto2'' protobuf-net'では 'proto3'ではないことに気づいたはずですので、' protogen.exe'ではなく 'protoc.exe'を使っています。とにかく、完全なコンストラクタが存在しないビルダーでは、init用のセッターを持つプロパティが必要です。 – BaltoStar
"完全なコンストラクタが存在しないビルダーでは、initのためにsetterを持つプロパティが必要です。 [反映を参照してください](http://stackoverflow.com/questions/934930/can-i-change-a-private-readonly-field-in-c-sharp-using-reflection)。また、クラスMyProtoが 'partial'であることに注意してください。他にもセッターや別のコンストラクタがありますか? – asynchronos