C#: Generate proper code for services that inherit from other services.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665632 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc
index cfb1ff1..f4fd543 100644
--- a/compiler/cpp/src/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/generate/t_csharp_generator.cc
@@ -781,17 +781,18 @@
f_service_ << endl;
indent(f_service_) <<
- "public Client(TProtocol iprot, TProtocol oprot)" << endl;
+ "public Client(TProtocol iprot, TProtocol oprot)";
+ if (!extends.empty()) {
+ f_service_ << " : base(iprot, oprot)";
+ }
+ f_service_ << endl;
+
scope_up(f_service_);
if (extends.empty()) {
f_service_ <<
indent() << "iprot_ = iprot;" << endl <<
indent() << "oprot_ = oprot;" << endl;
- } else {
- f_service_ <<
- indent() << "base(iprot, oprot);" << endl;
}
-
scope_down(f_service_);
f_service_ << endl;
@@ -957,18 +958,18 @@
indent_up();
indent(f_service_) <<
- "public Processor(Iface iface)" << endl;
- scope_up(f_service_);
+ "public Processor(Iface iface)" ;
if (!extends.empty()) {
- f_service_ <<
- indent() << "base(iface);" << endl;
+ f_service_ << " : base(iface)";
}
+ f_service_ << endl;
+ scope_up(f_service_);
f_service_ <<
indent() << "iface_ = iface;" << endl;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
f_service_ <<
- indent() << "processMap_[\"" << (*f_iter)->get_name() << "\"] = new " << (*f_iter)->get_name() << "();" << endl;
+ indent() << "processMap_[\"" << (*f_iter)->get_name() << "\"] = " << (*f_iter)->get_name() << "_Process;" << endl;
}
scope_down(f_service_);
@@ -976,9 +977,7 @@
if (extends.empty()) {
f_service_ <<
- indent() << "protected interface ProcessFunction {" << endl <<
- indent() << " void Process(int seqid, Iface iface, TProtocol iprot, TProtocol oprot);" << endl <<
- indent() << "}" << endl << endl;
+ indent() << "protected delegate void ProcessFunction(int seqid, TProtocol iprot, TProtocol oprot);" << endl;
}
f_service_ <<
@@ -991,8 +990,15 @@
f_service_ << endl;
- indent(f_service_) <<
- "public bool Process(TProtocol iprot, TProtocol oprot)" << endl;
+ if (extends.empty()) {
+ indent(f_service_) <<
+ "public bool Process(TProtocol iprot, TProtocol oprot)" << endl;
+ }
+ else
+ {
+ indent(f_service_) <<
+ "public new bool Process(TProtocol iprot, TProtocol oprot)" << endl;
+ }
scope_up(f_service_);
f_service_ <<
@@ -1010,7 +1016,7 @@
indent() << " oprot.Transport.Flush();" << endl <<
indent() << " return true;" << endl <<
indent() << "}" << endl <<
- indent() << "fn.Process(msg.SeqID, iface_, iprot, oprot);" << endl;
+ indent() << "fn(msg.SeqID, iprot, oprot);" << endl;
f_service_ <<
indent() << "return true;" << endl;
@@ -1051,11 +1057,7 @@
void t_csharp_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
indent(f_service_) <<
- "private class " << tfunction->get_name() << " : ProcessFunction {" << endl;
- indent_up();
-
- indent(f_service_) <<
- "public void Process(int seqid, Iface iface, TProtocol iprot, TProtocol oprot)" << endl;
+ "public void " << tfunction->get_name() << "_Process(int seqid, TProtocol iprot, TProtocol oprot)" << endl;
scope_up(f_service_);
string argsname = tfunction->get_name() + "_args";
@@ -1090,7 +1092,7 @@
f_service_ << "result.success = ";
}
f_service_ <<
- "iface." << tfunction->get_name() << "(";
+ "iface_." << tfunction->get_name() << "(";
bool first = true;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if (first) {
@@ -1131,9 +1133,6 @@
indent() << "return;" << endl;
scope_down(f_service_);
- indent_down();
- f_service_ <<
- indent() << "}" << endl << endl;
return;
}
@@ -1146,11 +1145,6 @@
scope_down(f_service_);
f_service_ << endl;
-
- indent_down();
-
- f_service_ <<
- indent() << "}" << endl << endl;
}
void t_csharp_generator::generate_deserialize_field(ofstream& out, t_field* tfield, string prefix) {