Migrate to System.Lazy.

This commit is contained in:
Paul Chote
2014-03-12 22:48:47 +13:00
parent 67cd0645a4
commit 1b2a90c00c
25 changed files with 87 additions and 125 deletions

View File

@@ -35,6 +35,8 @@ namespace OpenRA
fn(ee);
}
public static Lazy<T> Lazy<T>(Func<T> p) { return new Lazy<T>(p); }
public static IEnumerable<string> GetNamespaces(this Assembly a)
{
return a.GetTypes().Select(t => t.Namespace).Distinct().Where(n => n != null);

View File

@@ -113,7 +113,6 @@
<Compile Include="Primitives\Cached.cs" />
<Compile Include="Primitives\DisposableAction.cs" />
<Compile Include="Primitives\IObservableCollection.cs" />
<Compile Include="Primitives\Lazy.cs" />
<Compile Include="Primitives\ObservableCollection.cs" />
<Compile Include="Primitives\ObservableDictionary.cs" />
<Compile Include="Primitives\Pair.cs" />

View File

@@ -22,7 +22,7 @@ namespace OpenRA
{
public static PlatformType CurrentPlatform { get { return currentPlatform.Value; } }
static OpenRA.FileFormats.Lazy<PlatformType> currentPlatform = Lazy.New((Func<PlatformType>)GetCurrentPlatform);
static Lazy<PlatformType> currentPlatform = new Lazy<PlatformType>(GetCurrentPlatform);
static PlatformType GetCurrentPlatform()
{

View File

@@ -1,48 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
namespace OpenRA.FileFormats
{
public class Lazy<T>
{
Func<T> p;
T value;
public Lazy(Func<T> p)
{
if (p == null)
throw new ArgumentNullException();
this.p = p;
}
public T Value
{
get
{
if (p == null)
return value;
value = p();
p = null;
return value;
}
}
public T Force() { return Value; }
}
public static class Lazy
{
public static Lazy<T> New<T>(Func<T> p) { return new Lazy<T>(p); }
}
}