छँटाई हम एक DataGridView
करने के लिए संग्रह बाँध और छंटाई और छानने अनुमति देने के लिए sourceforge के माध्यम से Andrew Davey'sBindingListView<T>
वर्ग का उपयोग कर रहे हैं।"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
ठीक है, मैं इसे वापस लेता हूं, आप 'समेकित बाइंडिंग लिस्ट व्यू' का उपयोग कर रहे हैं और यह फेंक देता है। – briantyler