Lazy<T> with implicit cast to T can give you some pretty code

Magnus Mårtensson

Adding an implicit cast functionality to Lazy<T> can give you an option to writing null checkers in your delayed instantiation properties. The problem Today in our project a colleague was cussing over the fact that he kept writing the same block of code over and over again when null checking a property with a backing [...]

Tags: ,

Handling Lazy + Metadata instances in Managed Extensibility Framework (MEF)

Magnus Mårtensson

Have you ever wanted to dynamically choose from many potential implementations of some code? Would you like to have the power of metadata filtering and lazy instantiation of the selected implementation? Here is how to do just that using Managed Extensibility Framework (MEF) and also a neat trick to handle your implementation/metadata pairs that I [...]

Tags: , ,

Performing any Selector on the Main Thread

Fredrik Olsson

Many UI frameworks, including AppKit for Mac OS X and UIKit for iPhone OS, require that all methods to UI components are sent on the main UI thread. Cocoa and Cocoa Touch make this quite easy by providing for example -[NSObject performSelectorOnMainThread:withObject:waitUntilDone:] in Foundation. Making updating the text for a text field a snap: [someTextField [...]

Tags: , , , , , , , , ,