Skip to content

Commit

Permalink
#636 - Change TargetFramework to .NET 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Jun 6, 2023
1 parent ff9359a commit 6c4f028
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CI/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

- task: PublishPipelineArtifact@1
inputs:
path: xFunc.Maths/bin/Release/netstandard2.1
path: xFunc.Maths/bin/Release/net6.0
artifact: xFunc.Maths

- task: PublishPipelineArtifact@1
Expand Down
24 changes: 20 additions & 4 deletions xFunc.Maths/Expressions/Units/AngleUnits/AngleUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,28 @@ private AngleUnit(double factor, params string[] unitNames)
=> !left.Equals(right);

/// <inheritdoc />
public bool Equals(AngleUnit other)
=> Factor.Equals(other.Factor) && UnitNames.SequenceEqual(other.UnitNames);
public bool Equals(AngleUnit? other)
{
if (ReferenceEquals(null, other))
return false;
if (ReferenceEquals(this, other))
return true;

return Factor.Equals(other.Factor) && UnitNames.Equals(other.UnitNames);
}

/// <inheritdoc />
public override bool Equals(object? obj)
=> obj is AngleUnit other && Equals(other);
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != GetType())
return false;

return Equals((AngleUnit)obj);
}

/// <inheritdoc />
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -116,7 +132,7 @@ static void AddUnits(IDictionary<string, AngleUnit> dictionary, AngleUnit unit)
/// <param name="unit">When this method returns, the value associated with the specified name, if the unit is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
/// <returns><c>true</c> if area units contain an unit with the specified <paramref name="name"/>; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
public static bool FromName(string name, out AngleUnit unit)
public static bool FromName(string name, [NotNullWhen(true)] out AngleUnit? unit)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
Expand Down
27 changes: 23 additions & 4 deletions xFunc.Maths/Expressions/Units/AreaUnits/AreaUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,31 @@ private AreaUnit(double factor, string unitName)
=> !left.Equals(right);

/// <inheritdoc />
public bool Equals(AreaUnit other)
=> Factor.Equals(other.Factor) && UnitName == other.UnitName;
public bool Equals(AreaUnit? other)
{
if (ReferenceEquals(null, other))
return false;

if (ReferenceEquals(this, other))
return true;

return Factor.Equals(other.Factor) && UnitName == other.UnitName;
}

/// <inheritdoc />
public override bool Equals(object? obj)
=> obj is AreaUnit other && Equals(other);
{
if (ReferenceEquals(null, obj))
return false;

if (ReferenceEquals(this, obj))
return true;

if (obj.GetType() != GetType())
return false;

return Equals((AreaUnit)obj);
}

/// <inheritdoc />
[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -173,7 +192,7 @@ private static IDictionary<string, AreaUnit> GetUnits()
/// <param name="unit">When this method returns, the value associated with the specified name, if the unit is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
/// <returns><c>true</c> if area units contain an unit with the specified <paramref name="name"/>; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
public static bool FromName(string name, out AreaUnit unit)
public static bool FromName(string name, [NotNullWhen(true)] out AreaUnit? unit)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Units/AreaUnits/AreaValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public int CompareTo(AreaValue other)
}

/// <inheritdoc />
public int CompareTo(object obj)
public int CompareTo(object? obj)
=> obj switch
{
null => 1,
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Units/LengthUnits/LengthValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public int CompareTo(LengthValue other)
}

/// <inheritdoc />
public int CompareTo(object obj)
public int CompareTo(object? obj)
=> obj switch
{
null => 1,
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Units/MassUnits/MassValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public int CompareTo(MassValue other)
}

/// <inheritdoc />
public int CompareTo(object obj)
public int CompareTo(object? obj)
=> obj switch
{
null => 1,
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Units/PowerUnits/PowerValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public int CompareTo(PowerValue other)
}

/// <inheritdoc />
public int CompareTo(object obj)
public int CompareTo(object? obj)
=> obj switch
{
null => 1,
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Units/TimeUnits/TimeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public int CompareTo(TimeValue other)
}

/// <inheritdoc />
public int CompareTo(object obj)
public int CompareTo(object? obj)
=> obj switch
{
null => 1,
Expand Down
31 changes: 26 additions & 5 deletions xFunc.Maths/Expressions/Units/VolumeUnits/VolumeUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,38 @@ private VolumeUnit(double factor, string unitName)
=> !left.Equals(right);

/// <inheritdoc />
public bool Equals(VolumeUnit other)
=> Factor.Equals(other.Factor) && UnitName == other.UnitName;
public bool Equals(VolumeUnit? other)
{
if (ReferenceEquals(null, other))
return false;

if (ReferenceEquals(this, other))
return true;

return Factor.Equals(other.Factor) && UnitName == other.UnitName;
}

/// <inheritdoc />
public override bool Equals(object? obj)
=> obj is VolumeUnit other && Equals(other);
{
if (ReferenceEquals(null, obj))
return false;

if (ReferenceEquals(this, obj))
return true;

if (obj.GetType() != GetType())
return false;

return Equals((VolumeUnit)obj);
}

/// <inheritdoc />
[ExcludeFromCodeCoverage]
public override int GetHashCode()
=> HashCode.Combine(Factor, UnitName);
{
return HashCode.Combine(Factor, UnitName);
}

/// <inheritdoc />
public override string ToString()
Expand Down Expand Up @@ -129,7 +150,7 @@ private static IDictionary<string, VolumeUnit> GetUnits()
/// <param name="unit">When this method returns, the value associated with the specified name, if the unit is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
/// <returns><c>true</c> if volume units contain an unit with the specified <paramref name="name"/>; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c>.</exception>
public static bool FromName(string name, out VolumeUnit unit)
public static bool FromName(string name, [NotNullWhen(true)] out VolumeUnit? unit)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Expressions/Units/VolumeUnits/VolumeValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public int CompareTo(VolumeValue other)
}

/// <inheritdoc />
public int CompareTo(object obj)
public int CompareTo(object? obj)
=> obj switch
{
null => 1,
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Parser.ExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class Parser
{
private IExpression CreateFunction(in Token token, ImmutableArray<IExpression> arguments)
{
Debug.Assert(token.IsId(), "Token should be Id.");
Debug.Assert(token.Is(Id), "Token should be Id.");
Debug.Assert(!string.IsNullOrWhiteSpace(token.StringValue), "Id is empty.");

return token.StringValue.ToLowerInvariant() switch
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/Results/ExpressionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ExpressionResult(IExpression exp)
=> Result = exp ?? throw new ArgumentNullException(nameof(exp));

/// <inheritdoc />
public override string ToString() => Result.ToString();
public override string ToString() => Result.ToString()!;

/// <inheritdoc cref="IResult.Result" />
public IExpression Result { get; }
Expand Down
22 changes: 2 additions & 20 deletions xFunc.Maths/Tokenization/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public static Token Create(TokenKind kind)
[ExcludeFromCodeCoverage]
public override string ToString()
{
if (IsId() || Is(TokenKind.String))
if (Is(TokenKind.Id) || Is(TokenKind.String))
return $"String: {StringValue}";

if (IsNumber())
if (Is(TokenKind.Number))
return $"Number: {NumberValue}";

return $"Kind: {Kind}";
Expand Down Expand Up @@ -161,24 +161,6 @@ public override string ToString()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsNotEmpty() => !Is(TokenKind.Empty);

/// <summary>
/// Determines whether the current token is <c>Id</c> token.
/// </summary>
/// <returns>
/// <c>true</c> if the current token is <c>Id</c> token; otherwise, <c>false</c>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsId() => Is(TokenKind.Id);

/// <summary>
/// Determines whether the current token is <c>Number</c> token.
/// </summary>
/// <returns>
/// <c>true</c> if the current token is <c>Number</c> token; otherwise, <c>false</c>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsNumber() => Is(TokenKind.Number);

/// <summary>
/// Gets a token kind.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion xFunc.Maths/xFunc.Maths.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>xFunc.Maths</RootNamespace>
<PackageId>xFunc.Maths</PackageId>
Expand Down
16 changes: 16 additions & 0 deletions xFunc.Tests/Expressions/Units/AngleUnits/AngleUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ namespace xFunc.Tests.Expressions.Units.AngleUnits;

public class AngleUnitTest
{
[Fact]
public void EqualsNullTest()
{
var a = AngleUnit.Degree;

Assert.False(a.Equals(null));
}

[Fact]
public void EqualsTest()
{
Expand All @@ -20,6 +28,14 @@ public void NotEqualsTest()
Assert.False(a.Equals(b));
}

[Fact]
public void ObjectEqualsNullTest()
{
var a = AngleUnit.Degree;

Assert.False(a.Equals(null as object));
}

[Fact]
public void ObjectEqualsTest()
{
Expand Down
16 changes: 16 additions & 0 deletions xFunc.Tests/Expressions/Units/AreaUnits/AreaUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ namespace xFunc.Tests.Expressions.Units.AreaUnits;

public class AreaUnitTest
{
[Fact]
public void EqualsNullTest()
{
var a = AreaUnit.Meter;

Assert.False(a.Equals(null));
}

[Fact]
public void EqualsTest()
{
Expand All @@ -23,6 +31,14 @@ public void NotEqualsTest()
Assert.False(a.Equals(b));
}

[Fact]
public void ObjectEqualsNullTest()
{
var a = AreaUnit.Meter;

Assert.False(a.Equals(null as object));
}

[Fact]
public void ObjectEqualsTest()
{
Expand Down
16 changes: 16 additions & 0 deletions xFunc.Tests/Expressions/Units/VolumeUnits/VolumeUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ namespace xFunc.Tests.Expressions.Units.VolumeUnits;

public class VolumeUnitTest
{
[Fact]
public void EqualsNullTest()
{
var a = VolumeUnit.Meter;

Assert.False(a.Equals(null));
}

[Fact]
public void EqualsTest()
{
Expand All @@ -23,6 +31,14 @@ public void NotEqualsTest()
Assert.False(a.Equals(b));
}

[Fact]
public void ObjectEqualsNullTest()
{
var a = VolumeUnit.Meter;

Assert.False(a.Equals(null as object));
}

[Fact]
public void ObjectEqualsTest()
{
Expand Down

0 comments on commit 6c4f028

Please sign in to comment.