episerver - 将自定义类属性映射到选择工厂选择项类
问题描述
我正在尝试在 Episerver 中实现 selectionFactory。选择工厂中的代码实现对于一些自定义类是通用的。
这是自定义类的 1
Public class Location ()
{
public virtual string City { get; set; }
public virtual string Name { get; set; }
public virtual string State { get; set; }
public virtual string Country { get; set; }
}
由于 selectionfactory 的返回类型是 SelectItem,我需要先将类转换为选择项类,这很容易通过类型检查和分配来实现。但是,由于这是多个类的通用代码,我需要继续添加条件。
var locations = parentList as IEnumerable<Location>;
var selectItems = locations == null ?
((IEnumerable<string>)parentList).Select(item => new SelectItem() { Value = item, Text = item.ToString() }) :
locations.Select(location => new SelectItem() { Value = location.Name, Text = location.Name });
为了消除这种情况,我包含了一个自定义属性 (SelectionFactoryParentProperty),其中提到了下面给出的类型
[Display(Name = "Locations", GroupName = SystemTabNames.Content, Order = 70)]
[SelectionFactoryParentProperty(PropertyName = "Locations",PropertyType =typeof(Location))]
[SelectOne(SelectionFactoryType = typeof(ParentListSelectionFactory))]
public virtual string Locations { get; set; }
当两者之间没有共同属性时,有没有办法实现这一点,将本例中的类(位置)转换为 SelectItem?
任何输入表示赞赏。
问候。
解决方案
推荐阅读
- python - 尝试显示模型结果时 Sparknlp Java 错误
- git - 有没有办法确保团队遵循约定的 Git 流分支策略
- node.js - Sequelize 一次处理的请求太多?
- r - 创建对 `mice::with.mids()` 的调用
- javascript - 为什么您可以手动将 IP 与字符串进行比较,但不能将其存储在 JavaScript 的数组中?
- javascript - Spotify Web API 无论如何都会给我非法范围
- c - 如何在我的应用中找到“私有 API”的来源以通过 Apple Review
- python - 从 zsh 启动 Python 脚本并留在 Python shell
- sql - SQL 日语法在 AWS Athena 上不起作用
- r - 为超过/低于阈值的值制作不同颜色的ggplot2热图