Skip to content

Add Span<T> to test app #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MetadataProcessor.Tests/TestNFApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public static void Main()
Console.WriteLine("Null attributes tests");
_ = new ClassWithNullAttribs();

// testing Span<>
Console.WriteLine("Span<> tests");
_ = new TestingSpan();

Console.WriteLine("Exiting TestNFApp");
}

Expand Down
1 change: 1 addition & 0 deletions MetadataProcessor.Tests/TestNFApp/TestNFApp.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="OneClassOverAll.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestingSpan.cs" />
<Compile Include="TestingDestructors.cs" />
<Compile Include="TestingDelegates.cs" />
</ItemGroup>
Expand Down
61 changes: 61 additions & 0 deletions MetadataProcessor.Tests/TestNFApp/TestingSpan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using TestNFClassLibrary;

namespace TestNFApp
{
public class TestingSpan
{
public TestingSpan()
{
int length = 3;

// base type
Console.WriteLine("+++ Span<int> tests");
Console.WriteLine();

Span<int> numbers = new Span<int>(new int[length]);
for (int i = 0; i < length; i++)
{
numbers[i] = i;
}

foreach (int number in numbers)
{
Console.WriteLine($">>{number.ToString()}");
}

// string type
Console.WriteLine("+++ Span<string> tests");
Console.WriteLine();

Span<string> strings = new Span<string>(new string[length]);
for (int i = 1; i < length; i++)
{
strings[i] = $">> '{i * 10}'";
}

foreach (string str in strings)
{
Console.WriteLine($">> '{str}'");
}

// class type
Console.WriteLine("+++ Span<ClassOnAnotherAssembly> tests");
Span<ClassOnAnotherAssembly> spanOfClass = new Span<ClassOnAnotherAssembly>(new ClassOnAnotherAssembly[length]);

for (int i = 0; i < length; i++)
{
spanOfClass[i] = new ClassOnAnotherAssembly(i * 100);
}

foreach (ClassOnAnotherAssembly item in spanOfClass)
{
Console.WriteLine($">> '{item.DummyProperty}'");
}
}
}
}
Loading