c# - 如何将字符串列表视为模型中的枚举 - ASP.net Core Web API
问题描述
我有一个 ASP.net Core Web API (v3.1),它接受一个具有枚举属性的模型。示例类和枚举:
public class OrderModel
{
public int OrderNumber { get; set; }
public OrderType OrderType { get;set; }
...
}
public enum OrderType
{
Offline = 0,
Checkout = 1
}
然后在大摇大摆中显示如下:
我想定义一个字符串列表,例如:
public class OrderTypes
{
public List<string> GetOrderTypes()
{
return new List<string> { "Offline", "Checkout" };
// in reality this will be dynamically built at startup.
}
}
我想做的是将我的模型更改为与此类似:
public class OrderModel
{
public int OrderNumber { get; set; }
public string OrderType { get;set; }
...
}
但是以与枚举类似的方式显示 OrderType 的选项。
这可能吗?
注意:我的实际用例是反映(在运行时)特定接口的所有实现。这将是一个不断增长的列表,并且会随着时间的推移而增长——我不想在这些提供商增长时维护它们的枚举列表。
解决方案
推荐阅读
- java - 如何遍历 .txt 文件并将结果存储在 2d arrayList 中
- ios - 在 ios Flutter 上实现 Firebase 匿名身份验证
- c# - 如何向上导航几个文件夹
- android - 如何使android studio按创建日期显示项目目录中的文件
- reactjs - 依赖数组中的对象属性时不触发useEffect
- r - R Markdown 如何自动将打印效果格式化为数据帧?或者我怎样才能使用特殊的打印方法?
- python - 在一个盒子里裁剪分割的水果以获得他的直径(以像素为单位)
- c# - 在具有特定属性的 ObservableCollection 中搜索多个对象
- node.js - 订购 app.use() 函数的最安全和最有效的方法是什么?
- json - 使用来自 mediainfo AWS Lambda 的请求发送 json 时出现属性错误