我想了解如何創建自定義控件,工具欄。使用.NET Reflector,我試圖「重寫」ToolStripDesigner類(現在,這意味着只將代碼從反射器複製到Visual Studio)。因爲它使用System.Design.dll內部的許多類,所以我不得不用Reflector複製更多的類。在System.Windows.Forms.Design.OleDragDropHandler
類,我發現這個代碼:標誌枚舉的二進制操作
DragDropEffects allowedEffects = DragDropEffects.Move | DragDropEffects.Copy;
for (int i = 0; i < components.Length; i++)
{
InheritanceAttribute attribute = (InheritanceAttribute) TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)];
if (!attribute.Equals(InheritanceAttribute.NotInherited) && !attribute.Equals(InheritanceAttribute.InheritedReadOnly))
{
allowedEffects &= ~DragDropEffects.Move;
allowedEffects |= 0x4000000; // this causes error
}
}
DragDropEffects枚舉是公共的,與這些領域:
[Flags]
public enum DragDropEffects {
Scroll = -2147483648, // 0x80000000
All = -2147483645, // 0x80000003
None = 0,
Copy = 1,
Move = 2,
Link = 4,
}
你可以看到,有一個與價值的第一塊顯示任何領域的代碼(0x4000000)。 另外,這段代碼在VS中拋出錯誤:operator |= cannot be applied to operands of type System.Windows.Forms.DragDropEffects and int
所以我的問題是 - 這是怎麼編譯的?或者也許.NET Reflector在反編譯過程中犯了一個錯誤?有沒有什麼辦法可以繞過它(在allowedEffects
變量中沒有丟失這個奇怪的,未命名的信息)?
感謝提到ILSpy,有時間學習使用另一種工具;) – 2012-03-28 11:58:50