Skip to content

Commit

Permalink
useful ArrayUtils - EmptyArray<T> and ToArray
Browse files Browse the repository at this point in the history
  • Loading branch information
ssimek committed Aug 17, 2009
1 parent 758ed58 commit cdab952
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions RunSharp/ArrayUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

namespace TriAxis.RunSharp
{
static class EmptyArray<T>
{
public static readonly T[] Instance = { };
}

static class ArrayUtils
{
public static bool Equals(object[] array1, object[] array2)
Expand Down Expand Up @@ -81,5 +86,18 @@ public static Type[] GetTypes(ParameterInfo[] paramInfos)
types[i] = paramInfos[i].ParameterType;
return types;
}

public static T[] ToArray<T>(ICollection<T> collection)
{
if (collection == null)
return null;

if (collection.Count == 0)
return EmptyArray<T>.Instance;

T[] array = new T[collection.Count];
collection.CopyTo(array, 0);
return array;
}
}
}

0 comments on commit cdab952

Please sign in to comment.