Add BindServiceAttribute

pull/18484/head
James Newton-King 6 years ago
parent a3366c1b7f
commit f00508e9ce
No known key found for this signature in database
GPG Key ID: A66B2F456BF5526
  1. 3
      src/compiler/csharp_generator.cc
  2. 48
      src/csharp/Grpc.Core.Api/BindServiceAttribute.cs

@ -382,6 +382,9 @@ void GenerateServerClass(Printer* out, const ServiceDescriptor* service) {
"/// <summary>Base class for server-side implementations of "
"$servicename$</summary>\n",
"servicename", GetServiceClassName(service));
out->Print(
"[grpc::BindService(typeof($classname$), nameof($classname$.BindService))]\n",
"classname", GetServiceClassName(service));
out->Print("public abstract partial class $name$\n", "name",
GetServerClassName(service));
out->Print("{\n");

@ -0,0 +1,48 @@
#region Copyright notice and license
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;
namespace Grpc.Core
{
/// <summary>
/// Defines the location of the service bind method for a gRPC service.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class BindServiceAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="BindServiceAttribute"/> class.
/// </summary>
/// <param name="bindType">The type the service bind method is defined on.</param>
/// <param name="bindMethodName">The name of the service bind method.</param>
public BindServiceAttribute(Type bindType, string bindMethodName)
{
BindType = bindType;
BindMethodName = bindMethodName;
}
/// <summary>
/// Gets the type the service bind method is defined on.
/// </summary>
public Type BindType { get; }
/// <summary>
/// Gets the name of the service bind method.
/// </summary>
public string BindMethodName { get; }
}
}
Loading…
Cancel
Save