0
リストのインデックスを作成しようとしています。しかし、私は次のエラーを取得しておく何らかの理由:ラムダ式がデリゲートではないため型に変換できません
Cannot convert lambda expression to type 'TEntity' because it is not a delegate
私はこの問題にかなりの検索試してみましたが、私が試したすべてが動作するようには思えません。私はキャストを作成するから、これは特にエラーを投げているラインである私が正しいUsing
文
を持って保証するすべてのものを試した、このメソッドを呼び出している
int index = items.IndexOf(x => ID(x) == id.Value);
protected Int32? ID(TEntity entity)
{
return entity.As<dynamic>().__id;
}
参考までに残りの部分はここにあります。あなたは、このように行う可能性があり、IndexOf
にアイテムを渡す必要が
[Element("<div/>"), Editor, IdProperty("__id")]
public abstract class GridEditorBase<TEntity> : EntityGrid<TEntity>, ISetEditValue, IGetEditValue
where TEntity : class, new()
{
private int nextId = 1;
public GridEditorBase(jQueryObject container)
: base(container)
{
}
protected Int32? ID(TEntity entity)
{
return entity.As<dynamic>().__id;
}
protected virtual void Save(ServiceCallOptions opt, Action<ServiceResponse> callback)
{
SaveRequest<TEntity> request = opt.Request.As<SaveRequest<TEntity>>();
TEntity row = Q.DeepClone(request.Entity);
int? id = row.As<dynamic>().__id;
if (id == null)
row.As<dynamic>().__id = nextId++;
if (!ValidateEntity(row, id))
return;
List<TEntity> items = view.GetItems().Clone();
if (id == null)
items.Add(row);
else
{
int index = items.IndexOf(x => ID(x) == id.Value);
items[index] = Q.DeepExtend<TEntity>(new TEntity(), items[index], row);
}
SetEntities(items);
callback(new ServiceResponse());
}
は、署名を見てください。 – Servy
@Servyそれは受け入れる(TEntityアイテム) – Travis
そしてそのタイプの 'TEntity'のラムダですか? – Servy