I ran into an unusual problem the other day…
I’m developing a control that under the hood uses one of three implemented fingerprint scanner API’s in c#. My code is not complicated… just use the relevant DLLs and have their dependencies in my project directory. I have a base scanner class, a single property of that type, and one of the abstract properties of derived classes (ScannerFound) tells the dialog which control it found. It’s like a poor man’s factory pattern – declare a single property of the base type and then iterate and create each derived type found in the assembly; if ScannerFound == true we are done; else try the next one.
But for some reason I cannot fathom, one of the scanners API’s expects a class that implements ISynchronizeInvoke to be passed to its constructor. (Not cool. My Scanner base class is just a plain abstract class and is completely decoupled from the form or control that contains it. I am not passing the Form – which happens to implement ISynchronizeInvoke, to the class, so this means one derived class needs to contain a reference to a class that implements the interface, or implement it itself and in the process add a bunch of unnecessary bullshit to my nice clean class structure.) It’s not an interface I would ever think to implement myself. Why they did this is beyond me because I’d really rather just use an async method or my own thread (if necessary) and don’t need to be tied to the way a Winforms control calls a delegate. In my case, this implementation is only necessary to pass to a constructor, and is used internally in their API by a method I don’t even call. I could probably have used a class that “implements” it by throwing NotImplementedException everywhere but that would just feel wrong.
Anyway, this example I found looks good and I used it as is. To be honest, I’d probably have implemented it myself just for fun if I really cared about it and my code actually used it for more than passing a dummy type, but oh well, I feel almost guilty about not writing here on this blog with the silly header image any more.