ProtobufNetPrimitives is a library to transfer basic data types with protobuf-net.Grpc.
$ dotnet add package HaemmerElectronics.SeppPenner.ProtobufNetPrimitivesProtobufNetPrimitives is a library to transfer basic data types with protobuf-net.Grpc.
| Net type | GRPC type | Remark |
|---|---|---|
bool | DtoBool | - |
byte | DtoByte | - |
char | DtoChar | - |
DateTime | DtoDateTime | The value is internally stored as long, use the property DateTime to get the correct value. |
DateTimeOffset | DtoDateTimeOffset | The value is internally stored as long, use the property DateTimeOffset to get the correct value. |
decimal | DtoDecimal | - |
double | DtoDouble | - |
float | DtoFloat | - |
Guid | DtoGuid | The value is internally stored as string, use the property Uuid to get the correct value. |
int | DtoInt | - |
long | DtoLong | - |
nint | DtoNint | - |
nuint | DtoNuint | - |
sbyte | DtoSbyte | - |
short | DtoShort | - |
string | DtoString | - |
TimeSpan | DtoTimeSpan | The value is internally stored as long, use the property TimeSpan to get the correct value. |
uint | DtoUint | - |
ulong | DtoUlong | - |
ushort | DtoUshort | - |
Non-Nullable and Nullable types are supported (Different sub-namespaces).
/// <summary>
/// The base DTO class.
/// </summary>
[ProtoContract]
[ProtoInclude(1, typeof(DtoBool))]
public class DtoBase<T> where T : new()
{
/// <summary>
/// Initializes a new instance of the <see cref="DtoBase{T}"/> class.
/// </summary>
public DtoBase()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DtoBase{T}"/> class.
/// </summary>
/// <param name="value">The value.</param>
public DtoBase(T value)
{
this.Data = value;
}
/// <summary>
/// Gets or sets the data.
/// </summary>
[ProtoMember(2)]
public T Data { get; set; } = new();
}
/// <summary>
/// The DTO class to transfer bool data.
/// </summary>
[ProtoContract]
public class DtoBool : DtoBase<bool>
{
/// <summary>
/// Initializes a new instance of the <see cref="DtoBool"/> class.
/// </summary>
public DtoBool()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DtoBool"/> class.
/// </summary>
/// <param name="value">The value.</param>
public DtoBool(bool value)
{
this.Data = value;
}
}
throws the error subscribed under https://github.com/protobuf-net/protobuf-net/issues/829 (Not resolved yet).
dotnet add package HaemmerElectronics.SeppPenner.ProtobufNetPrimitives
See the Changelog.