Skip to content

Commit f74286d

Browse files
authored
Add Span<T> to test app (#198)
1 parent 60c9312 commit f74286d

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

MetadataProcessor.Tests/TestNFApp/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public static void Main()
8888
Console.WriteLine("Null attributes tests");
8989
_ = new ClassWithNullAttribs();
9090

91+
// testing Span<>
92+
Console.WriteLine("Span<> tests");
93+
_ = new TestingSpan();
94+
9195
Console.WriteLine("Exiting TestNFApp");
9296
}
9397

MetadataProcessor.Tests/TestNFApp/TestNFApp.nfproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Compile Include="OneClassOverAll.cs" />
3737
<Compile Include="Program.cs" />
3838
<Compile Include="Properties\AssemblyInfo.cs" />
39+
<Compile Include="TestingSpan.cs" />
3940
<Compile Include="TestingDestructors.cs" />
4041
<Compile Include="TestingDelegates.cs" />
4142
</ItemGroup>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Diagnostics;
6+
using TestNFClassLibrary;
7+
8+
namespace TestNFApp
9+
{
10+
public class TestingSpan
11+
{
12+
public TestingSpan()
13+
{
14+
int length = 3;
15+
16+
// base type
17+
Console.WriteLine("+++ Span<int> tests");
18+
Console.WriteLine();
19+
20+
Span<int> numbers = new Span<int>(new int[length]);
21+
for (int i = 0; i < length; i++)
22+
{
23+
numbers[i] = i;
24+
}
25+
26+
foreach (int number in numbers)
27+
{
28+
Console.WriteLine($">>{number.ToString()}");
29+
}
30+
31+
// string type
32+
Console.WriteLine("+++ Span<string> tests");
33+
Console.WriteLine();
34+
35+
Span<string> strings = new Span<string>(new string[length]);
36+
for (int i = 1; i < length; i++)
37+
{
38+
strings[i] = $">> '{i * 10}'";
39+
}
40+
41+
foreach (string str in strings)
42+
{
43+
Console.WriteLine($">> '{str}'");
44+
}
45+
46+
// class type
47+
Console.WriteLine("+++ Span<ClassOnAnotherAssembly> tests");
48+
Span<ClassOnAnotherAssembly> spanOfClass = new Span<ClassOnAnotherAssembly>(new ClassOnAnotherAssembly[length]);
49+
50+
for (int i = 0; i < length; i++)
51+
{
52+
spanOfClass[i] = new ClassOnAnotherAssembly(i * 100);
53+
}
54+
55+
foreach (ClassOnAnotherAssembly item in spanOfClass)
56+
{
57+
Console.WriteLine($">> '{item.DummyProperty}'");
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)