add service descriptor property to generated code

pull/2863/head
Jan Tattermusch 10 years ago
parent 9ee27e10ba
commit e6af5d10ec
  1. 12
      src/compiler/csharp_generator.cc
  2. 1
      src/compiler/csharp_generator.h
  3. 2
      src/csharp/Grpc.Examples/MathGrpc.cs
  4. 6
      src/csharp/Grpc.HealthCheck/HealthGrpc.cs
  5. 6
      src/csharp/Grpc.IntegrationTesting/TestGrpc.cs

@ -44,6 +44,7 @@
using google::protobuf::compiler::csharp::GetFileNamespace;
using google::protobuf::compiler::csharp::GetClassName;
using google::protobuf::compiler::csharp::GetUmbrellaClassName;
using google::protobuf::SimpleItoa;
using grpc::protobuf::FileDescriptor;
using grpc::protobuf::Descriptor;
using grpc::protobuf::ServiceDescriptor;
@ -226,6 +227,16 @@ void GenerateStaticMethodField(Printer* out, const MethodDescriptor *method) {
out->Outdent();
}
void GenerateServiceDescriptorProperty(Printer* out, const ServiceDescriptor *service) {
out->Print("// service descriptor\n");
out->Print("public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor\n");
out->Print("{\n");
out->Print(" get { return $umbrella$.Descriptor.Services[$index$]; }\n",
"umbrella", GetUmbrellaClassName(service->file()), "index", SimpleItoa(service->index()));
out->Print("}\n");
out->Print("\n");
}
void GenerateClientInterface(Printer* out, const ServiceDescriptor *service) {
out->Print("// client interface\n");
out->Print("public interface $name$\n", "name",
@ -472,6 +483,7 @@ void GenerateService(Printer* out, const ServiceDescriptor *service) {
for (int i = 0; i < service->method_count(); i++) {
GenerateStaticMethodField(out, service->method(i));
}
GenerateServiceDescriptorProperty(out, service);
GenerateClientInterface(out, service);
GenerateServerInterface(out, service);
GenerateClientStub(out, service);

@ -39,6 +39,7 @@
using namespace std;
#include <google/protobuf/compiler/csharp/csharp_names.h>
#include <google/protobuf/stubs/strutil.h>
namespace grpc_csharp_generator {

@ -48,7 +48,7 @@ namespace Math {
// service descriptor
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
get { return global::Math.Proto.Math.Descriptor.Services[0]; }
get { return global::Math.Proto.Math.Descriptor.Services[0]; }
}
// client interface

@ -22,6 +22,12 @@ namespace Grpc.Health.V1Alpha {
__Marshaller_HealthCheckRequest,
__Marshaller_HealthCheckResponse);
// service descriptor
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
get { return global::Grpc.Health.V1Alpha.Proto.Health.Descriptor.Services[0]; }
}
// client interface
public interface IHealthClient
{

@ -62,6 +62,12 @@ namespace Grpc.Testing {
__Marshaller_StreamingOutputCallRequest,
__Marshaller_StreamingOutputCallResponse);
// service descriptor
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
get { return global::Grpc.Testing.Test.Descriptor.Services[0]; }
}
// client interface
public interface ITestServiceClient
{

Loading…
Cancel
Save