我想了解如何创建自定义控件,工具栏。使用.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