Thx!
Am Dienstag, 19. März 2019 15:20:57 UTC+1 schrieb Benjamin Krämer:
>
> You have to create a message that reflects the information from 
> System.Version that interests you. There is no direct mapping, you can 
> achieve something close by writing an implicit cast operator or an 
> extension method if you don't want to do it manually and have it in many 
> places.
>
>
> https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/implicit
>
> https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods
>
> Keep in mind that your protos are cross platform compatible. So string is 
> a reference type in C# (up until 7.3) but not in ProtocolBuffers or a lot 
> of other languages. So if you plan to do more mapping, keep in mind to use 
> google.protobuf.StringValue instead of string, otherwise you will definetly 
> run into NullReferenceExceptions at runtime.
>
> server_info.proto
> message FileVersion {
>     int32 major = 1;
>     int32 minor = 2;
>     int32 build = 3;
>     int32 revision = 4;
> }
>
> message ServerInfo {
>     FileVersion file_version = 1;
> }
>
> ServerInfo.cs (just make sure to use the correct namespace maching your 
> package from ServerInfo.proto)
>
> partial class FileVersion
> {
>     public static implicit operator System.Version(FileVersion v)
>     {
>         return new System.Version(v.Major, v.Minor, v.Build, v.Revision);
>     }
>
>     public static implicit operator FileVersion(System.Version v)
>     {
>         return new FileVersion {
>
>              Major = v.Major,
>
>              Minor = v.Minor,
>
>              Build = v.Build,
>
>              Revision = v.Revision
>
>         };
>
> } }
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/ca08980b-34fd-4fad-97ed-d3b4ba2f29c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to