Skip to content

Commit

Permalink
Add support for .NET 6 (#81)
Browse files Browse the repository at this point in the history
* Enable implicit usings

* Add support for .NET 6
Fix nullable errors, which is on by default in .NET 6

* Setup .NET 5 in Windows for sonar tool

* Add emoji to release commit.
  • Loading branch information
eduherminio authored Nov 19, 2021
1 parent 0f31b8d commit 5b380e8
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
executors:
fileparser-executor:
docker:
- image: mcr.microsoft.com/dotnet/sdk:5.0
- image: mcr.microsoft.com/dotnet/sdk:6.0
working_directory: ~/FileParser

jobs:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ jobs:
- name: Inject slug/short variables
uses: rlespinasse/[email protected]

- name: Setup .NET Core
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x

- name: Setup .NET 5 for sonar
if: matrix.os == 'windows-latest'
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Release

on:
workflow_dispatch:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x

- name: Set version to ${{ github.event.inputs.new_package_version }}
shell: pwsh
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
run: |
git switch ${{ env.GITHUB_REF_SLUG }}
git status
git commit -am "Release v${{ github.event.inputs.new_package_version }}"
git commit -am "🚀 Release v${{ github.event.inputs.new_package_version }}"
git push
- name: Create git tag
Expand Down
7 changes: 4 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project>

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>Enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup Condition="'$(DeterministicBuild)' == 'true'">
<PropertyGroup Condition="'$(DeterministicBuild)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ schedules:
- main

variables:
SdkVersion: '5.0.x'
SdkVersion: '6.0.x'

stages:
- stage: CI
Expand Down
14 changes: 5 additions & 9 deletions src/FileParser/Implementations/ParsedFile.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text;
using Print = System.Diagnostics.Debug;

namespace FileParser
Expand Down Expand Up @@ -75,7 +71,7 @@ public IParsedLine LastLine()

public List<T> ToList<T>(string? lineSeparatorToAdd = null)
{
List<T> list = new List<T>();
List<T> list = new();

if (!string.IsNullOrEmpty(lineSeparatorToAdd))
{
Expand All @@ -95,7 +91,7 @@ public List<T> ToList<T>(string? lineSeparatorToAdd = null)

public string ToSingleString(string wordSeparator = " ", string? lineSeparator = null)
{
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();

while (!Empty)
{
Expand Down Expand Up @@ -140,11 +136,11 @@ public static List<List<string>> ReadAllGroupsOfLines(string path)
/// <returns></returns>
public static Queue<IParsedLine> ParseFile(string path, string? existingSeparator = null)
{
Queue<IParsedLine> parsedFile = new Queue<IParsedLine>();
Queue<IParsedLine> parsedFile = new();

try
{
using (StreamReader reader = new StreamReader(path))
using (StreamReader reader = new(path))
{
while (!reader.EndOfStream)
{
Expand Down
9 changes: 3 additions & 6 deletions src/FileParser/Implementations/ParsedLine.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;

namespace FileParser
{
Expand Down Expand Up @@ -64,7 +61,7 @@ public T LastElement<T>()

public List<T> ToList<T>()
{
List<T> list = new List<T>();
List<T> list = new();

while (!Empty)
{
Expand All @@ -76,7 +73,7 @@ public List<T> ToList<T>()

public string ToSingleString(string wordSeparator = " ")
{
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder = new();

while (!Empty)
{
Expand Down
4 changes: 1 addition & 3 deletions src/FileParser/Interfaces/IParsedFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;

namespace FileParser
namespace FileParser
{
public interface IParsedFile
{
Expand Down
4 changes: 1 addition & 3 deletions src/FileParser/Interfaces/IParsedLine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;

namespace FileParser
namespace FileParser
{
public interface IParsedLine
{
Expand Down
11 changes: 5 additions & 6 deletions src/FileParser/ParsingException.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization;

namespace FileParser
{
[Serializable]
public class ParsingException : Exception
{
private const string _genericMessage = "Exception triggered during parsing process";
private const string GenericMessage = "Exception triggered during parsing process";

public ParsingException() : base(_genericMessage)
public ParsingException() : base(GenericMessage)
{
}

public ParsingException(string message) : base(message ?? _genericMessage)
public ParsingException(string message) : base(message ?? GenericMessage)
{
}

public ParsingException(string message, Exception inner) : base(message ?? _genericMessage, inner)
public ParsingException(string message, Exception inner) : base(message ?? GenericMessage, inner)
{
}

Expand Down
3 changes: 1 addition & 2 deletions src/FileParser/Utils/StringConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.ComponentModel;

namespace FileParser
{
Expand Down
11 changes: 4 additions & 7 deletions src/FileParser/Utils/TConverter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;

namespace FileParser
{
Expand All @@ -19,7 +16,7 @@ internal static T ChangeType<T>(object value, TypeConverter? typeConverter = nul
{
return typeConverter is null
? (T)ChangeType(typeof(T), value)
: (T)typeConverter.ConvertFrom(value);
: (T)typeConverter.ConvertFrom(value)!;
}

private static object ChangeType(Type t, object value)
Expand All @@ -32,15 +29,15 @@ private static object ChangeType(Type t, object value)
{
TypeConverter tc = TypeDescriptor.GetConverter(t);

return tc.ConvertFrom(value);
return tc.ConvertFrom(value)!;
}
}

private static object ParseDouble(object value)
{
double result;

string doubleAsString = value.ToString() ?? throw new ParsingException($"Error parsing value as double");
string doubleAsString = value.ToString() ?? throw new ParsingException("Error parsing value as double");
IEnumerable<char> doubleAsCharList = doubleAsString.ToList();

if (doubleAsCharList.Count(ch => ch == '.' || ch == ',') <= 1)
Expand Down
15 changes: 5 additions & 10 deletions tests/FileParser.Test/ExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
using Xunit;

namespace FileParser.Test
{
Expand Down Expand Up @@ -40,10 +37,8 @@ public void IOException()
{
const string fileName = "Any.txt";

using (StreamWriter writer = new StreamWriter(fileName))
{
Assert.Throws<IOException>(() => new ParsedFile(fileName));
}
using StreamWriter writer = new(fileName);
Assert.Throws<IOException>(() => new ParsedFile(fileName));
}

[Fact]
Expand Down Expand Up @@ -74,8 +69,8 @@ public void ParsingException()

Assert.Throws<ParsingException>(() => line.NextElement<object>());

Queue<string> testQueue = new Queue<string>(new string[] { string.Empty });
ParsedLine testLine = new ParsedLine(testQueue);
Queue<string> testQueue = new(new string[] { string.Empty });
ParsedLine testLine = new(testQueue);
Assert.Throws<ParsingException>(() => testLine.NextElement<char>());
}
}
Expand Down
13 changes: 5 additions & 8 deletions tests/FileParser.Test/ParsedFileTest/ExtractTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text;
using Xunit;

namespace FileParser.Test.ParsedFileTest
Expand All @@ -14,10 +11,10 @@ public void CustomLineParse()
const string fileName = "CustomLineParse.txt";
const string sampleContent = " 3 1154 508 100 vegetable ";

List<long> expectedList = new List<long>() { 1154, 508, 100 };
List<long> expectedList = new() { 1154, 508, 100 };
const string expectedString = "vegetable";

using (StreamWriter writer = new StreamWriter(fileName))
using (StreamWriter writer = new(fileName))
{
writer.WriteLine(sampleContent);
}
Expand Down Expand Up @@ -48,9 +45,9 @@ public void ExtractChar()
const string line1 = "+-*/!?#$%&";
const string line2 = "@()[]{}\"";

StringBuilder parsedFile = new StringBuilder(string.Empty);
StringBuilder parsedFile = new(string.Empty);

using (StreamWriter writer = new StreamWriter(fileName))
using (StreamWriter writer = new(fileName))
{
writer.WriteLine(Math.PI.ToString());
writer.WriteLine(line1);
Expand Down
13 changes: 5 additions & 8 deletions tests/FileParser.Test/ParsedFileTest/GeneralTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit;

namespace FileParser.Test.ParsedFileTest
{
Expand All @@ -17,8 +14,8 @@ public void BasicTest()
// Following lines firstly indicate how many numeric elements are following.
// After those numeric elements, they include an unknown number of items.

List<int> numberList = new List<int>();
List<string> stringList = new List<string>();
List<int> numberList = new();
List<string> stringList = new();

IParsedFile file = new ParsedFile(_sampleFolderPath + "Sample_file.txt");

Expand Down Expand Up @@ -85,8 +82,8 @@ public void PeekTestEmptyingFile()

while (!file.Empty)
{
List<int> peekedNumberList = new List<int>();
List<string> peekedStringList = new List<string>();
List<int> peekedNumberList = new();
List<string> peekedStringList = new();

IParsedLine peekedLine = file.PeekNextLine();
int peekedCounter = peekedLine.PeekNextElement<int>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.IO;
using System.Linq;
using Xunit;
using Xunit;

namespace FileParser.Test.ParsedFileTest
{
Expand Down
Loading

0 comments on commit 5b380e8

Please sign in to comment.