Skip to content

Instantly share code, notes, and snippets.

Last active October 16, 2019 23:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Provide c# decimal datatype for gRPC (based on
using System.Linq;
public partial class DecimalValue
public DecimalValue(int[] bits) => Bits.AddRange(bits);
public static implicit operator decimal(DecimalValue decimalValue) => decimalValue.ToDecimal();
public static implicit operator DecimalValue(decimal value) => FromDecimal(value);
public decimal ToDecimal() => new decimal(Bits.ToArray());
public static DecimalValue FromDecimal(decimal value) => new DecimalValue(decimal.GetBits(value));
// Name "DecimalValue" prevents conflict with C# Decimal type
message DecimalValue {
repeated int32 bits = 1;
Copy link

See for good reason NOT to use this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment