I’m trying to learn how to create custom controls, toolbars. Using .NET Reflector, I’ve tried to “rewrite” ToolStripDesigner class (for now, this means only copying code from reflector into visual studio). Because it uses many classes internal to System.Design.dll, I’ve had to copy some more classes with Reflector. In System.Windows.Forms.Design.OleDragDropHandler class, I’ve found this code:
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 enumeration is public, with these fields:
[Flags]
public enum DragDropEffects {
Scroll = -2147483648, // 0x80000000
All = -2147483645, // 0x80000003
None = 0,
Copy = 1,
Move = 2,
Link = 4,
}
as you can see, there is no field with value shown in the first piece of code (0x4000000).
Also, this code throws error in VS: operator |= cannot be applied to operands of type System.Windows.Forms.DragDropEffects and int
So my question is – how did this compile ? Or maybe .NET Reflector made a mistake in decompilation process ? Is there any way to hmm bypass it (without loosing this strange, unnamed information in allowedEffects variable) ?
The integer is being cast to a DragDropEffects object, as seen here in ILSpy: