@ -104,9 +104,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
vars [ " access_level " ] = class_access_level ( ) ;
vars [ " access_level " ] = class_access_level ( ) ;
WriteMessageDocComment ( printer , descriptor_ ) ;
WriteMessageDocComment ( printer , descriptor_ ) ;
printer - > Print (
WriteGeneratedTypeAttributes ( printer ) ;
" [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
printer - > Print (
vars ,
vars ,
" $access_level$ sealed partial class $class_name$ : pb::IMessage<$class_name$> { \n " ) ;
" $access_level$ sealed partial class $class_name$ : pb::IMessage<$class_name$> { \n " ) ;
@ -114,9 +112,13 @@ void MessageGenerator::Generate(io::Printer* printer) {
// All static fields and properties
// All static fields and properties
printer - > Print (
printer - > Print (
vars ,
vars ,
" private static readonly pb::MessageParser<$class_name$> _parser = new pb::MessageParser<$class_name$>(() => new $class_name$()); \n "
" private static readonly pb::MessageParser<$class_name$> _parser = new pb::MessageParser<$class_name$>(() => new $class_name$()); \n " ) ;
" public static pb::MessageParser<$class_name$> Parser { get { return _parser; } } \n \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
vars ,
" public static pb::MessageParser<$class_name$> Parser { get { return _parser; } } \n \n " ) ;
// Access the message descriptor via the relevant file descriptor or containing message descriptor.
// Access the message descriptor via the relevant file descriptor or containing message descriptor.
if ( ! descriptor_ - > containing_type ( ) ) {
if ( ! descriptor_ - > containing_type ( ) ) {
@ -127,18 +129,23 @@ void MessageGenerator::Generate(io::Printer* printer) {
+ " .Descriptor.NestedTypes[ " + SimpleItoa ( descriptor_ - > index ( ) ) + " ] " ;
+ " .Descriptor.NestedTypes[ " + SimpleItoa ( descriptor_ - > index ( ) ) + " ] " ;
}
}
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
printer - > Print (
vars ,
vars ,
" public static pbr::MessageDescriptor Descriptor { \n "
" public static pbr::MessageDescriptor Descriptor { \n "
" get { return $descriptor_accessor$; } \n "
" get { return $descriptor_accessor$; } \n "
" } \n "
" } \n "
" \n "
" \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
vars ,
" pbr::MessageDescriptor pb::IMessage.Descriptor { \n "
" pbr::MessageDescriptor pb::IMessage.Descriptor { \n "
" get { return Descriptor; } \n "
" get { return Descriptor; } \n "
" } \n "
" } \n "
" \n " ) ;
" \n " ) ;
// Parameterless constructor and partial OnConstruction method.
// Parameterless constructor and partial OnConstruction method.
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
printer - > Print (
vars ,
vars ,
" public $class_name$() { \n "
" public $class_name$() { \n "
@ -188,12 +195,18 @@ void MessageGenerator::Generate(io::Printer* printer) {
printer - > Print ( " } \n " ) ;
printer - > Print ( " } \n " ) ;
// TODO: Should we put the oneof .proto comments here?
// TODO: Should we put the oneof .proto comments here?
// It's unclear exactly where they should go.
// It's unclear exactly where they should go.
printer - > Print (
printer - > Print (
vars ,
vars ,
" private $property_name$OneofCase $name$Case_ = $property_name$OneofCase.None; \n "
" private $property_name$OneofCase $name$Case_ = $property_name$OneofCase.None; \n " ) ;
" public $property_name$OneofCase $property_name$Case { \n "
WriteGeneratedCodeAttributes ( printer ) ;
" get { return $name$Case_; } \n "
printer - > Print (
" } \n \n "
vars ,
" public $property_name$OneofCase $property_name$Case { \n "
" get { return $name$Case_; } \n "
" } \n \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
vars ,
" public void Clear$property_name$() { \n "
" public void Clear$property_name$() { \n "
" $name$Case_ = $property_name$OneofCase.None; \n "
" $name$Case_ = $property_name$OneofCase.None; \n "
" $name$_ = null; \n "
" $name$_ = null; \n "
@ -210,8 +223,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
printer - > Print (
printer - > Print (
vars ,
vars ,
" #region Nested types \n "
" #region Nested types \n "
" /// <summary>Container for nested types declared in the $class_name$ message type.</summary> \n "
" /// <summary>Container for nested types declared in the $class_name$ message type.</summary> \n " ) ;
" [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print ( " public static partial class Types { \n " ) ;
printer - > Print ( " public static partial class Types { \n " ) ;
printer - > Indent ( ) ;
printer - > Indent ( ) ;
@ -255,6 +267,7 @@ bool MessageGenerator::HasNestedGeneratedTypes()
void MessageGenerator : : GenerateCloningCode ( io : : Printer * printer ) {
void MessageGenerator : : GenerateCloningCode ( io : : Printer * printer ) {
map < string , string > vars ;
map < string , string > vars ;
WriteGeneratedCodeAttributes ( printer ) ;
vars [ " class_name " ] = class_name ( ) ;
vars [ " class_name " ] = class_name ( ) ;
printer - > Print (
printer - > Print (
vars ,
vars ,
@ -294,6 +307,7 @@ void MessageGenerator::GenerateCloningCode(io::Printer* printer) {
printer - > Outdent ( ) ;
printer - > Outdent ( ) ;
printer - > Print ( " } \n \n " ) ;
printer - > Print ( " } \n \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
printer - > Print (
vars ,
vars ,
" public $class_name$ Clone() { \n "
" public $class_name$ Clone() { \n "
@ -309,11 +323,15 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
vars [ " class_name " ] = class_name ( ) ;
vars [ " class_name " ] = class_name ( ) ;
// Equality
// Equality
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
printer - > Print (
vars ,
vars ,
" public override bool Equals(object other) { \n "
" public override bool Equals(object other) { \n "
" return Equals(other as $class_name$); \n "
" return Equals(other as $class_name$); \n "
" } \n \n "
" } \n \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
vars ,
" public bool Equals($class_name$ other) { \n "
" public bool Equals($class_name$ other) { \n "
" if (ReferenceEquals(other, null)) { \n "
" if (ReferenceEquals(other, null)) { \n "
" return false; \n "
" return false; \n "
@ -338,7 +356,8 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
// GetHashCode
// GetHashCode
// Start with a non-zero value to easily distinguish between null and "empty" messages.
// Start with a non-zero value to easily distinguish between null and "empty" messages.
printer - > Print (
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
" public override int GetHashCode() { \n "
" public override int GetHashCode() { \n "
" int hash = 1; \n " ) ;
" int hash = 1; \n " ) ;
printer - > Indent ( ) ;
printer - > Indent ( ) ;
@ -355,13 +374,15 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
printer - > Outdent ( ) ;
printer - > Outdent ( ) ;
printer - > Print ( " } \n \n " ) ;
printer - > Print ( " } \n \n " ) ;
printer - > Print (
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
" public override string ToString() { \n "
" public override string ToString() { \n "
" return pb::JsonFormatter.ToDiagnosticString(this); \n "
" return pb::JsonFormatter.ToDiagnosticString(this); \n "
" } \n \n " ) ;
" } \n \n " ) ;
}
}
void MessageGenerator : : GenerateMessageSerializationMethods ( io : : Printer * printer ) {
void MessageGenerator : : GenerateMessageSerializationMethods ( io : : Printer * printer ) {
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
printer - > Print (
" public void WriteTo(pb::CodedOutputStream output) { \n " ) ;
" public void WriteTo(pb::CodedOutputStream output) { \n " ) ;
printer - > Indent ( ) ;
printer - > Indent ( ) ;
@ -376,8 +397,10 @@ void MessageGenerator::GenerateMessageSerializationMethods(io::Printer* printer)
// TODO(jonskeet): Memoize size of frozen messages?
// TODO(jonskeet): Memoize size of frozen messages?
printer - > Outdent ( ) ;
printer - > Outdent ( ) ;
printer - > Print (
printer - > Print (
" } \n "
" } \n "
" \n "
" \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
" public int CalculateSize() { \n " ) ;
" public int CalculateSize() { \n " ) ;
printer - > Indent ( ) ;
printer - > Indent ( ) ;
printer - > Print ( " int size = 0; \n " ) ;
printer - > Print ( " int size = 0; \n " ) ;
@ -398,6 +421,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
map < string , string > vars ;
map < string , string > vars ;
vars [ " class_name " ] = class_name ( ) ;
vars [ " class_name " ] = class_name ( ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print (
printer - > Print (
vars ,
vars ,
" public void MergeFrom($class_name$ other) { \n " ) ;
" public void MergeFrom($class_name$ other) { \n " ) ;
@ -434,6 +458,7 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
}
}
printer - > Outdent ( ) ;
printer - > Outdent ( ) ;
printer - > Print ( " } \n \n " ) ;
printer - > Print ( " } \n \n " ) ;
WriteGeneratedCodeAttributes ( printer ) ;
printer - > Print ( " public void MergeFrom(pb::CodedInputStream input) { \n " ) ;
printer - > Print ( " public void MergeFrom(pb::CodedInputStream input) { \n " ) ;
printer - > Indent ( ) ;
printer - > Indent ( ) ;
printer - > Print (
printer - > Print (