Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add lazy implementation
  • Loading branch information
verdie-g committed Jul 29, 2025
commit babd9f525724b0727f627b505c98c73f89ba71b4
40 changes: 40 additions & 0 deletions src/System.Linq.Dynamic.Core/Compatibility/Lazy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Threading;

#if NET35
namespace System
{
internal class Lazy<T>
{
private readonly Func<T> _valueFactory;
private readonly object _lock;

private T? _value;
private bool _valueCreated;

public Lazy(Func<T> valueFactory, LazyThreadSafetyMode mode)
{
_valueFactory = valueFactory;
_lock = new object();
}

public T Value
{
get
{
lock (_lock)
{
if (_valueCreated)
{
return _value!;
}

_value = _valueFactory();
_valueCreated = true;
return _value;
}
}
}

}
}
#endif
11 changes: 11 additions & 0 deletions src/System.Linq.Dynamic.Core/Compatibility/LazyThreadSafetyMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if NET35
namespace System.Threading
{
internal enum LazyThreadSafetyMode
{
None,
PublicationOnly,
ExecutionAndPublication,
}
}
#endif