Virtu/Library/Lazy.cs
Sean Fausett 8382195feb Initial sound emulation for WPF and XNA+Windows platforms via COM interop to DirectSound.
Added rudimentary UI to Silverlight and WPF platforms to enable disk selection at runtime.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4024459
2009-07-26 23:22:00 +00:00

38 lines
956 B
C#

using System;
using System.Threading;
namespace Jellyfish.Library
{
public sealed class Lazy<T> where T : class
{
public Lazy(Func<T> initializer)
{
_initializer = initializer;
}
public T Value
{
get
{
if (_value == null)
{
T value = _initializer();
if (Interlocked.CompareExchange(ref _value, value, null) != null)
{
IDisposable disposable = value as IDisposable; // dispose preempted instance
if (disposable != null)
{
disposable.Dispose();
}
}
}
return _value;
}
}
private Func<T> _initializer;
private T _value;
}
}