Extension Methods from David Harris
-
SafeInvoke
Properly invokes an action if it is required. Best way to handle events and threaded operations on a form.
-
EnqueueWithCapacity
Sometimes you may need a Queue<T> that, once it hits a capacity, dequeues items automatically to maintain a certain maximum. While it may be best to derive a new type from Queue<T>, this will get it done much more quickly. This is very useful for maintaining a rolling average or a "history" feature.
-
ConstrainToRange
Many times you may wish to impose boundaries on what a certain variable can be. This is especially useful for validating user input. For any comparable, it simply returns the value, truncated by a minimum or maximum