Skip to content

Commit 750f1c7

Browse files
committed
Added ArrayCache
1 parent d680275 commit 750f1c7

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Nancy.MSBuild/Nancy.csproj

+5-2
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@
236236
<Compile Include="..\Nancy\DefaultRootPathProvider.cs">
237237
<Link>DefaultRootPathProvider.cs</Link>
238238
</Compile>
239+
<Compile Include="..\Nancy\ArrayCache.cs">
240+
<Link>ArrayCache.cs</Link>
241+
</Compile>
239242
<Compile Include="..\Nancy\DefaultRouteConfigurationProvider.cs">
240243
<Link>DefaultRouteConfigurationProvider.cs</Link>
241244
</Compile>
@@ -1520,11 +1523,11 @@
15201523
</EmbeddedResource>
15211524
</ItemGroup>
15221525
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
1523-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
1526+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
15241527
Other similar extension points exist, see Microsoft.Common.targets.
15251528
<Target Name="BeforeBuild">
15261529
</Target>
15271530
<Target Name="AfterBuild">
15281531
</Target>
15291532
-->
1530-
</Project>
1533+
</Project>

src/Nancy/ArrayCache.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Nancy
2+
{
3+
/// <summary>
4+
/// A cache for empty arrays.
5+
/// </summary>
6+
public class ArrayCache
7+
{
8+
/// <summary>
9+
/// Gets a cached, empty array of the specified type.
10+
/// </summary>
11+
/// <typeparam name="T">the type of array to get.</typeparam>
12+
public static T[] Empty<T>()
13+
{
14+
return EmptyArray<T>.Value;
15+
}
16+
17+
private static class EmptyArray<T>
18+
{
19+
public static readonly T[] Value = new T[0];
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)