- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在一个较旧的应用程序中工作(从 1.1 天开始)并且有许多非通用集合,例如:
[Serializable]
public class MyEntityList : CollectionBase
{
private int _virtualRecordCount;
public int VirtualRecordCount
{
get { return _virtualRecordCount; }
set { _virtualRecordCount = value; }
}
public MyEntityList()
{
}
public MyEntityList(MyEntity[] arr)
{
AddRange(arr);
}
public MyEntityList this[int index]
{
get { return (MyEntity)InnerList[index]; }
}
public void Add(MyEntity item)
{
InnerList.Add(item);
}
etc...
我已经升级应用程序的一层以使用通用 Collection<T>
对于返回类型。该层是自动生成的,类名基于数据源表名。业务实体类也不必排队,但在本例中并非如此。在这种情况下,它们 1:1 完美匹配。
我试过像这样映射集合:
Collection<MyEntityResponse> responses = GetMyEntityResponses();
AutoMapper.Mapper.CreateMap<MyEntityResponse, MyEntity>();
myEntityList = AutoMapper.Mapper.Map<MyEntityList>(responses);
最奇怪的是...我认为它可能会在使用 CollectionBase
时发出尖叫声,但我还是按了 F5。令我惊讶的是,没有编译器错误,也没有异常。哇哦!
但是,稍后在应用程序中它抛出了一个异常,提示来自 MyEntityResponse
的类型转换至 MyEntity
当它试图执行 foreach()
时在 MyEntityList
这是从 Mapper.Map 返回的。
发生的是一个新的MyEntityList
收藏已退回,但里面装满了 MyEntityResponse
对象。啊??自定义集合覆盖 Add()
方法并指定类型必须是 MyEntity
类型.我希望它在尝试向集合中添加错误类型时会爆炸,但它似乎没有任何问题与 CollectionBase
一起工作。 .
所以我的问题是,如果我尝试映射的两种类型完全匹配(属性到属性),并且 AutoMapper 对 CollectionBase 没有问题,为什么它不能映射实体?为什么它不抛出异常,而是将错误的类型插入集合?
编辑:我想我知道为什么......因为非通用集合没有与之关联的已知类型,就像通用集合一样。
那么,新问题...我如何告诉它使用 MyEntity
而不是 MyEntityResponse
?
最佳答案
我想我找到了答案:http://automapper.codeplex.com/wikipage?title=Lists%20and%20Arrays
For the non-generic enumerable types, only unmapped, assignable types are supported, as AutoMapper will be unable to "guess" what types you're trying to map. As shown in the example above, it's not necessary to explicitly configure list types, only their member types.
As of release 0.2.0, no custom destination collection types are supported.
关于c# - 从通用集合到非通用集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11403949/
编辑:我似乎问错了这个问题。 我正在尝试寻找一种方法来查询一个集合是否在另一个集合中可用。例如: SELECT * FROM something WHERE (1, 3) IN (1, 2, 3, 4
这两种方法似乎 produce the same results ,但我一直很难真正说服人们第二种方法有效,因为它显然并不为人所知。 // Create some data var foo = { '
我一直在学习Kotlin,并且遇到过Collections API。在Kotlin之前,我一直在学习Java,并且我知道Java中有很多不同类型的Collections API。例如,我们使用List
为什么我会得到不同的行为: Collection col2 = new ArrayList(col); 集合 col2 = new ArrayList(); col2.addAll(col) 我正在与
所以我有一个代表专辑信息的 JSON 对象。给定“function updateRecords(id, prop, value)”我希望能够更新每个条目。正确的完成代码如下。 我得到了指示,粗体部分,
我想存储一个对象集合,这些对象根据它们所代表的值进行键控。这些键可以重复。例如: [4] => Bob [5] => Mary [5] => Sue [9] => Steve [10] =>
在检查 ArrayList API 时,我注意到一些看起来很奇怪的东西。 确实,这里是 ArrayList 构造函数实现,其中 Collection 作为参数传递: public ArrayList(
我正在为 API 编写一个 swagger 定义文件。 API 是用于 GET 请求的 /path/to/my/api: get: summary: My Custom API d
我知道scala.collection包中有两个非常有用的对象,可以帮助我们实现这个目标: JavaConverters(如果我想明确说明并准确说明我要转换的内容) JavaConversions(如
我已经阅读了无数其他帖子,但似乎无法弄清楚发生了什么,所以是时候寻求帮助了。 我正在尝试将包含集合的域实体映射到也包含集合的 dtos。 这是一个原始示例; (我提前为代码墙道歉,我尽量保持简短):
我正在创建一个具有 ArrayList 的类,因此当我调用构造函数时,它会初始化该数组: public class ElementsList { private ArrayList list;
我正在阅读事件指南和指南的开头,它说: You can also add an event listener to any element in the this.$ collection using
我是 Python 新手,想知道如何使用键在字典中存储不同数据类型的列表 例如 - {[Key1,int1,int1,String1] , [Key2,int2,int2,String2], [Key
int[] mylist = { 2, 4, 5 }; IEnumerable list1 = mylist; list1.ToList().Add(1); // why 1 does not get
我在 UI 表单中的每一行之后将以下内容添加到 HashMap 集合中 声明 Map> map = new HashMap>(); List valSetOne = new ArrayList();
我正在开发我的第一个 Java 项目,我有一个问题。问题应该很简单(虽然代码不是那么短,但没有理由被吓倒:))。我创建了一个基本的角色扮演游戏,并且有一个定义每个角色的抽象类“Character”。在
我正在开发一款应用程序,可以为用户收集推文、Facebook 状态和 Facebook 照片。目前,用户确切地设定了他们希望这种收获发生的时间和时间,并且蜘蛛会在此期间拉取数据。 when 和 to
有谁知道在 C# 中是否有与 Java 的 Set 集合等效的好方法?我知道您可以通过填充但忽略值来使用 Dictionary 或 HashTable 在某种程度上模仿集合,但这不是一种非常优雅的方式
EXISTS 该函数返回 集合中第一个元素的索引,如果集合为空,返回NULLNULLNULL Collecti
RDF集合是通过属性 rdf:parseType="Collection" 来描述仅包含指定成员的组 rdf:parseType="Collection" 属
我是一名优秀的程序员,十分优秀!