Tuesday, September 26, 2006

Lazy Load Property Example/Snippet

Vault of Thoughts - Lazy Load Property Snippet

"I have written an article on Visual Studio Code Snippets - how to use them, and how to create your own. I have provided there a couple of snippets that I use on daily basis. You can also check Mads Kristensen's blog where he provides a snippet for "safe events". Today I have thought of yet another useful snippet...

...

If using 2.0 version of the .NET Framework, you can do better and use the Nullable type for the field. And that is exactly the code snippet I provide. With it you can create such a lazy initialized property very quickly.

..."

I'm about to begin work on an API where I want to implement lazy property loading...

The nullable approach discussed above seems smart, simple and easy to maintain. Something to look at/think about anyway...

No comments: