Stiamo utilizzando Andrew Davey'sBindingListView<T>
classe tramite sourceforge per legare le collezioni ad un DataGridView
e consentire l'ordinamento e filtraggio.errore "tipo proprietario non valido per DynamicMethod" durante l'ordinamento un'interfaccia
Questo funziona bene per le collezioni normali. In un caso però la collezione stiamo legame è un tipo di interfaccia e si ottiene questo errore se si cerca di ordinare su di esso:
Invalid type owner for DynamicMethod
L'errore è nel profondo del codice di Andrew Davies', quindi è difficile per noi per sapere da dove cominciare.
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>));
}
Ho appena scaricato la biblioteca, e modificato l'applicazione di esempio in modo che sia vincolante per un'interfaccia piuttosto che un tipo concreto e funziona benissimo; quindi non può essere solo il fatto che tu sia vincolante per un'interfaccia. Puoi pubblicare un'interfaccia minima e implementare una classe che mostri questo comportamento perché questo è sicuramente specifico per l'implementazione? – briantyler
OK. Riporto, si sta utilizzando 'AggregateBindingListView' e si lancia. – briantyler