Add IReadOnlyList
This commit is contained in:
@@ -244,6 +244,7 @@
|
||||
<Compile Include="Scripting\ScriptPlayerInterface.cs" />
|
||||
<Compile Include="Traits\Player\FixedColorPalette.cs" />
|
||||
<Compile Include="Primitives\ReadOnlyDictionary.cs" />
|
||||
<Compile Include="Primitives\ReadOnlyList.cs" />
|
||||
<Compile Include="ModMetadata.cs" />
|
||||
<Compile Include="GameRules\Ruleset.cs" />
|
||||
<Compile Include="GameRules\RulesetCache.cs" />
|
||||
|
||||
71
OpenRA.Game/Primitives/ReadOnlyList.cs
Normal file
71
OpenRA.Game/Primitives/ReadOnlyList.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
/// <summary>
|
||||
/// A minimal read only list interface for .NET 4
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// .NET 4.5 has an implementation built-in, this code is not meant to
|
||||
/// duplicate it but provide a compatible interface that can be replaced
|
||||
/// when we switch to .NET 4.5 or higher.
|
||||
/// </remarks>
|
||||
public interface IReadOnlyList<T> : IEnumerable<T>
|
||||
{
|
||||
int Count { get; }
|
||||
T this[int index] { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A minimal read only list for .NET 4 implemented as a wrapper
|
||||
/// around an IList.
|
||||
/// </summary>
|
||||
public class ReadOnlyList<T> : IReadOnlyList<T>
|
||||
{
|
||||
private readonly IList<T> list;
|
||||
|
||||
public ReadOnlyList()
|
||||
: this(new List<T>())
|
||||
{
|
||||
}
|
||||
|
||||
public ReadOnlyList(IList<T> list)
|
||||
{
|
||||
if (list == null)
|
||||
throw new ArgumentNullException("list");
|
||||
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
#region IEnumerable implementation
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return list.GetEnumerator();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IEnumerable implementation
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return list.GetEnumerator();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IReadOnlyList implementation
|
||||
public int Count { get { return list.Count; } }
|
||||
|
||||
public T this[int index] { get { return list[index]; } }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user