Andrew Davey'sBindingListView<T>
クラスを使用してsourceforgeを使用してコレクションをDataGridView
にバインドし、並べ替えとフィルタリングが可能です。「DynamicMethodのタイプ所有者が無効です」というエラーが発生しました。
通常のコレクションでは問題ありません。あるケースではしかし、我々はに結合しているコレクションは、インターフェイスのタイプであり、我々はそれをソートしようとした場合、私たちは、このエラーを取得:
Invalid type owner for DynamicMethod
それがために難しいので、エラーがアンドリュー・デイビスコードに深いです私たちはどこから始めるべきかを知っています。
private static Comparison<T> BuildValueTypeComparison(PropertyInfo pi, ListSortDirection direction)
{
MethodInfo getMethod = pi.GetGetMethod();
Debug.Assert(getMethod != null);
DynamicMethod dm = new DynamicMethod("Get" + pi.Name, typeof(int), new Type[] { typeof(T), typeof(T) }, typeof(T), true);
//^^^ ======== Here's the line reporting the error=========== ^^^
ILGenerator il = dm.GetILGenerator();
// Get the value of the first object's property.
il.Emit(OpCodes.Ldarg_0);
il.EmitCall(OpCodes.Call, getMethod, null);
// Box the value type
il.Emit(OpCodes.Box, pi.PropertyType);
// Get the value of the second object's property.
il.Emit(OpCodes.Ldarg_1);
il.EmitCall(OpCodes.Call, getMethod, null);
// Box the value type
il.Emit(OpCodes.Box, pi.PropertyType);
// Cast the first value to IComparable and call CompareTo,
// passing the second value as the argument.
il.Emit(OpCodes.Castclass, typeof(IComparable));
il.EmitCall(OpCodes.Call, typeof(IComparable).GetMethod("CompareTo"), null);
// If descending then multiply comparison result by -1
// to reverse the ordering.
if (direction == ListSortDirection.Descending)
{
il.Emit(OpCodes.Ldc_I4_M1);
il.Emit(OpCodes.Mul);
}
// Return the result of the comparison.
il.Emit(OpCodes.Ret);
// Create the delegate pointing at the dynamic method.
return (Comparison<T>)dm.CreateDelegate(typeof(Comparison<T>));
}
を私はライブラリをダウンロードし、それはインターフェースではなく、具体的な形に結合され、それが正常に動作するように、サンプル・アプリケーションを変更しました。インターフェイスにバインドしているだけではありません。これは実装固有のものなので、最小限のインターフェイスを実装し、この動作を示すクラスを実装できますか? – briantyler
私はそれを取り戻し、あなたは 'AggregateBindingListView'を使用しています。 – briantyler