2
嗨,我看了看,只看到數組中的例子列出\集合,但沒有其他方式。從一個集合到一個數組的映射
我有一個屬性爲AccIndex
的集合,我想映射到 數組,其名稱爲AccIndex
。
我試過如下:
Mapper.CreateMap<AccountCollection, AcctArray[]>().
ForMember(d=> d.AccIndex,
o=>MapFrom(s => s.AcctList.Select(c => c.AccIndex).ToArray()));
這讓我空,並與toArray
我覺得這隻會讓一切慢(指定者比再次打破它)。
是不是有一個簡單的方法來映射兩者?唯一的區別是一個是集合和另一個數組,但不知何故,我在谷歌上找不到任何東西。
一些更多的東西,我想,總是導致許多空值:
Mapper.CreateMap<AccountCollection,
AcctArray>();
Mapper.Map(AcctIndexesList, newIndexesArray);
Mapper.CreateMap<AccountCollection,
AcctArray[]>();
Mapper.Map(AcctIndexesList, newIndexesArray2);
我被要求出示收集和陣列怎麼看起來像這樣:
public class AccountCollection: IList, ICollection, IList<AcctIndexes>,
ICollection<AcctIndexes>, IEnumerable<AcctIndexes>, IEnumerable {
public AcctIndexesCollection();
public virtual int Count { get; }
public int Rows { get; set; }
public virtual AcctIndexes this[int index] { get; set; }
public virtual int Add(AcctIndexes value);
...
}
public class AcctIndexes : IFormattable
{
public bool AccIndexSpecified;
public AcctIndexes();
public int AccIndex { get; set; }
}
和這些數組:
public partial class AcctArray {
private int accIndexField;
public int AccIndex
{
get {
return this.accIndexField;
}
set {
this.accIndexField = value;
}
}
}
感謝
請使用正確的格式。 –
** System.LINQ **命名空間包含一個擴展方法'List ToList(此IEnumerable 源)',它可用於* ICollection *的所有實現,因爲它擴展了* IEnumerable *。這有幫助: –
顯示你的'AccountCollection'和'AcctArray'類。 –