Модели C# для сообщений protobuf (проект gRPC)C#

Место общения программистов C#
Ответить
Anonymous
 Модели C# для сообщений protobuf (проект gRPC)

Сообщение Anonymous »

Я могу найти довольно много ресурсов о том, как генерировать модели C# из сообщений protobuf (он даже встроен в пакет Grpc.AspNetCore), но не наоборот.
Я' Я создал клиент/серверный проект blazor webassembly, похожий на этот: https://github.com/stevejgordon/gRPCBasicSample/
У меня есть слой домена с множеством Модели C#, которые я использую для приложения. Я хотел бы преобразовать эти модели в «модели просмотра» ответа на сообщение, вместо того, чтобы писать их все вручную (к тому же я даже не уверен в правильном преобразовании между C# и protobuf)
Пример:
Модель C#:

Код: Выделить всё

    /// 
/// The area.
/// 
public class Area
{
/// 
/// Initializes a new instance of the  class.
/// 
/// Name of the region.
/// What type of area is the region.
/// number of supplies the region has.
/// number of crowns the region has.
public Area(string name, AreaType areaType, int numberOfSupplies, int numberOfMusterCrows)
{
this.Name = name;
this.AreaType = areaType;
this.NumberOfSupplies = numberOfSupplies;
this.NumberOfMusterCrowns = numberOfMusterCrows;
this.CurrentArmy = new Collection();
this.AdjacentAreas = new Collection();
}

/// 
/// Gets the name of the region.
/// 
public string Name { get; }

/// 
/// Gets or sets which house the area is controlled by.
/// 
public House ControlledBy { get; set; }

/// 
/// Gets the type of area the region is.
/// 
public AreaType AreaType { get; }

/// 
/// Gets the adjacent regions the region has.
/// 
public IEnumerable AdjacentAreas { get; internal set; }

/// 
/// Gets the number of supplies (barrels) the region has.
/// 
public int NumberOfSupplies { get; }

/// 
/// Gets the number of crowns the region has.
/// 
public int NumberOfMusterCrowns { get; }

/// 
/// Gets or sets a value indicating whether the region is occupied by troops.
/// 
public bool IsOccupied { get; set; }

/// 
/// Gets a value indicating whether the region has a stronghold.
/// 
public bool HasStronghold { get; }

/// 
/// Gets a value indicating whether the region has a castle.
/// 
public bool HasCastle { get; }

/// 
/// Gets or sets the current armies occupying the region.
/// 
public ICollection CurrentArmy { get; set; }

/// 
/// Gets or sets the current order token placed.
/// 
public OrderToken? PlacedOrderToken { get; set; }
}
Должно получиться примерно так (упрощенно):

Код: Выделить всё

message AreaReply {
string name = 1;
enum AreaType {
Land = 0;
Water = 1;
}
AreaType areaType = 4;
House controlledBy = 5;
}
message House {
google.protobuf.StringValue name = 1;
}
Неужели такого генератора нет? :)
Спасибо

Подробнее здесь: https://stackoverflow.com/questions/709 ... pc-project
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»