-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[c# grpc] Skip compilation for --structs=false
* The MSBuild codegen targets now detect --structs=false and skip automatic compilation of the non-existent `_types.cs` files. * Added a gRPC example that show how to use a shared type assembly between a client and service.
- Loading branch information
Showing
14 changed files
with
463 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Using a shared types assembly | ||
|
||
Sometimes you want to compile the types from a .bond file separately from | ||
the gRPC services and clients. This example shows how to split the types | ||
into their own assembly. | ||
|
||
The [`gbc`](https://microsoft.github.io/bond/manual/compiler.html) options | ||
`--structs` and `--grpc` can be used to control whether codegen is performed | ||
for structs and services. | ||
|
||
In the `types` directory, codegen is performed without the `--grpc` switch, | ||
so just types are generated and compiled. | ||
|
||
In the `client` and `server` directories, however, codegen is performed with | ||
the `--grpc` switch. Also, `--structs=false` is passed to disable the | ||
default behavior of generating C# code for the types. If `--structs=false` | ||
were not specified, there would be duplicate types in different assemblies, | ||
resulting in a conflict that would need to be resolved via | ||
[`extern alias`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias). | ||
|
||
The `client` directory shows how to pass `--gprc` via per-item metadata with | ||
`%(BondCodegen.Options)`, while the `server` directory shows how to do this | ||
via the global `$(BondOptions)` property. |
32 changes: 32 additions & 0 deletions
32
examples/cs/grpc/shared-types-assembly/client/StaClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Examples.SharedTypes | ||
{ | ||
using System; | ||
using Grpc.Core; | ||
|
||
public static class Client | ||
{ | ||
const string Address = "127.0.0.1"; | ||
const int Port = 50051; | ||
|
||
public static void Main() | ||
{ | ||
var channel = new Channel(Address, Port, ChannelCredentials.Insecure); | ||
var client = new Calc.CalcClient(channel); | ||
|
||
var request = new Request | ||
{ | ||
Num1 = 40, | ||
Num2 = 2 | ||
}; | ||
|
||
var response = client.AddAsync(request).GetAwaiter().GetResult(); | ||
|
||
Console.WriteLine($"Addition result: {response.Payload.Deserialize().Result}"); | ||
|
||
channel.ShutdownAsync().GetAwaiter().GetResult(); | ||
} | ||
} | ||
} |
Oops, something went wrong.