'convert enums in Protobuf to enums in c#
I have this proto file
syntax = "proto3";
message AdminIpoChange
{
string Id =1;
string SymbolName =2;
string SymbolIsin =3;
string Date =4;
string Time=5;
double MinPrice =6;
double MaxPrice =7;
int32 Share =8;
bool Show =9;
AdminIpoOperation Operation =10;
string CreateDateTime=11;
enum AdminIpoOperation
{
Add = 0;
Edit = 1;
Delete = 2;
}
}
And here I have this class
public class AdminIpoChangeEntity : BaseEntity
{
public AdminIpoChangeEntity()
{
}
public string SymbolName { get; set; }
public string SymbolIsin { get; set; }
public string Date { get; set; }
public string Time { get; set; }
public double MinPrice { get; set; }
public double MaxPrice { get; set; }
public int Share { get; set; }
public bool Show { get; set; }
public AdminIpoOperation Operation { get; set; }
public DateTime CreateDateTime { get; set; }
public enum AdminIpoOperation
{
Add = 0,
Edit = 1,
Delete = 2
}
}
So I want to convert the operation enum in proto to enum in c# as you can see :
public static AdminIpoChangeEntity Map(AdminIpoChange adminIpoChange)
=> new()
{
CreateDateTime=DateTime.Parse(adminIpoChange.CreateDateTime),Date=adminIpoChange.Date,MaxPrice=adminIpoChange.MaxPrice,
MinPrice=adminIpoChange.MinPrice,Operation=adminIpoChange.Operation,Share=adminIpoChange.Share,Show=adminIpoChange.Show,
SymbolIsin=adminIpoChange.SymbolIsin,SymbolName=adminIpoChange.SymbolName,Time=adminIpoChange.Time,
};
But in this part Operation=adminIpoChange.OperationI get this error :
Severity Code Description Project File Line Suppression State
Error CS0266 Cannot implicitly convert type 'AdminIpoChange.Types.AdminIpoOperation' to 'domain.Entities.AdminIpoChangeEntity.AdminIpoOperation'. An explicit conversion exists (are you missing a cast?) domain D:\****\domain\Entities\AdminIpoChangeEntity.cs 43 Active
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
