Changes ISpriteSource.Frames to be of type IReadOnlyList<ISpriteFrame>.
- Updated implementations to return a ReadOnlyList around an array (to reduce wasted memory from exposing lists or lazy enumerators around lists). - Protect non-public ISpriteFrame classes by making them inner classes to prevent casting. - Added an AsReadOnly extension method for lists.
This commit is contained in:
@@ -21,12 +21,20 @@ namespace OpenRA
|
||||
/// 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>
|
||||
public interface IReadOnlyList<out T> : IEnumerable<T>
|
||||
{
|
||||
int Count { get; }
|
||||
T this[int index] { get; }
|
||||
}
|
||||
|
||||
public static class ReadOnlyList
|
||||
{
|
||||
public static IReadOnlyList<T> AsReadOnly<T>(this IList<T> list)
|
||||
{
|
||||
return list as IReadOnlyList<T> ?? new ReadOnlyList<T>(list);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A minimal read only list for .NET 4 implemented as a wrapper
|
||||
/// around an IList.
|
||||
|
||||
Reference in New Issue
Block a user