Unsafe At Any Speed
August 10, 2010 Leave a comment
What I wrote in Visual Studio 2010:
public unsafe void waitForAttachment(int milliseconds)
{
if (this.managerPhidget)
{
throw new PhidgetException(PhidgetException.GetErrorDesc(11), 11);
}
int code = Phidget21Imports.CPhidget_waitForAttachment(this.phidgetDeviceHandle, milliseconds);
if (code != 0)
{
throw new PhidgetException(code);
}
while (!this.initialized)
{
Thread.Sleep(10);
}
}
What Reflector came up with:
public void waitForAttachment(int milliseconds)
{
if (this.managerPhidget)
{
throw new PhidgetException(PhidgetException.GetErrorDesc(11), 11);
}
int code = Phidget21Imports.CPhidget_waitForAttachment(this.phidgetDeviceHandle, milliseconds);
if (code != 0)
{
throw new PhidgetException(code);
}
while (!this.initialized)
{
}
Note how Reflector dropped the “unsafe” keyword.
Also, I learned:
· Static Methods cannot be in an interface
· Internal Methods cannot be in an interface
· I dropped Abstract b/c the code had references to its own instance