Skip to content

Commit

Permalink
Update deps, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Jun 7, 2024
1 parent 6bffad8 commit 1bcd83b
Show file tree
Hide file tree
Showing 37 changed files with 1,394 additions and 1,343 deletions.
5 changes: 4 additions & 1 deletion Build/Build.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpInteractive" Version="1.0.7" />
<PackageReference Include="CSharpInteractive" Version="1.0.7"/>
</ItemGroup>

</Project>
34 changes: 4 additions & 30 deletions Build/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,17 @@ public static string Get(string name, string defaultProp, bool showWarning = fal

static class Assertion
{
public static bool Succeed(int? exitCode, string shortName)
public static void Succeed(int? exitCode, string shortName)
{
if (exitCode == 0)
{
return true;
return;
}

Error($"{shortName} failed.");
Exit();
return false;
}

public static async Task<bool> Succeed(Task<int?> exitCodeTask, string shortName) =>
Succeed(await exitCodeTask, shortName);


private static bool CheckBuildResult(IBuildResult result)
{
if (result.ExitCode == 0)
Expand All @@ -143,29 +139,7 @@ public static void Succeed(IBuildResult result)
Exit();
}
}

public static async Task<bool> Succeed(Task<IBuildResult> resultTask)
{
if (CheckBuildResult(await resultTask))
{
return true;
}

Exit();
return true;
}

public static async Task<bool> Succeed(Task<IBuildResult[]> resultsTask)
{
if ((await resultsTask).All(CheckBuildResult))
{
return true;
}

Exit();
return true;
}


private static void Exit()
{
if (!Tools.UnderTeamCity)
Expand Down
4 changes: 2 additions & 2 deletions Immutype.Benchmark/Immutype.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Immutype\Immutype.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<ProjectReference Include="..\Immutype\Immutype.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12"/>
</ItemGroup>

</Project>
92 changes: 46 additions & 46 deletions Immutype.Benchmark/RecordWithFourProperties.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
// ReSharper disable UnusedVariable
namespace Immutype.Benchmark
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
// ReSharper disable WithExpressionModifiesAllMembers
namespace Immutype.Benchmark;

[Target]
public record PersonRecordWithFourProperties(string? Name, int Age, string? LastName, bool HasPassport);
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;

[Target]
public readonly record struct PersonRecordStructWithFourProperties(string? Name, int Age, string? LastName, bool HasPassport);
[Target]
public record PersonRecordWithFourProperties(string? Name, int Age, string? LastName, bool HasPassport);

[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class RecordWithFourProperties
{
private readonly PersonRecordWithFourProperties _john = new("John", 15, "Smith", false);
private readonly PersonRecordStructWithFourProperties _johnStruct = new("John", 15, "Smith", false);
[Target]
public readonly record struct PersonRecordStructWithFourProperties(string? Name, int Age, string? LastName, bool HasPassport);

[Benchmark]
public void WithForRecord()
{
var david = _john with
{
Name = "David",
Age = 17,
LastName = "Black",
HasPassport = true
};
}

[Benchmark]
public void WithForRecordStruct()
{
var david = _johnStruct with
{
Name = "David",
Age = 17,
LastName = "Black",
HasPassport = true
};
}

[Benchmark]
public void ImmutypeForRecord()
[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class RecordWithFourProperties
{
private readonly PersonRecordWithFourProperties _john = new("John", 15, "Smith", false);
private readonly PersonRecordStructWithFourProperties _johnStruct = new("John", 15, "Smith", false);

[Benchmark]
public void WithForRecord()
{
var david = _john with
{
var david = _john.WithName("David").WithAge(17).WithLastName("Black").WithHasPassport(true);
}
Name = "David",
Age = 17,
LastName = "Black",
HasPassport = true
};
}

[Benchmark]
public void ImmutypeForRecordStruct()
[Benchmark]
public void WithForRecordStruct()
{
var david = _johnStruct with
{
var david = _johnStruct.WithName("David").WithAge(17).WithLastName("Black").WithHasPassport(true);
}
Name = "David",
Age = 17,
LastName = "Black",
HasPassport = true
};
}

[Benchmark]
public void ImmutypeForRecord()
{
var david = _john.WithName("David").WithAge(17).WithLastName("Black").WithHasPassport(true);
}

[Benchmark]
public void ImmutypeForRecordStruct()
{
var david = _johnStruct.WithName("David").WithAge(17).WithLastName("Black").WithHasPassport(true);
}
}
81 changes: 41 additions & 40 deletions Immutype.Benchmark/RecordWithOneProperty.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
// ReSharper disable UnusedVariable
namespace Immutype.Benchmark
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
// ReSharper disable WithExpressionModifiesAllMembers
// ReSharper disable NotAccessedPositionalProperty.Global
namespace Immutype.Benchmark;

[Target]
public record PersonRecordWithOneProperty(string? Name);
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;

[Target]
public readonly record struct PersonRecordStructWithOneProperty(string? Name);
[Target]
public record PersonRecordWithOneProperty(string? Name);

[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class RecordWithOneProperty
{
private readonly PersonRecordWithOneProperty _john = new("John");
private readonly PersonRecordStructWithOneProperty _johnStruct = new("John");
[Target]
public readonly record struct PersonRecordStructWithOneProperty(string? Name);

[Benchmark]
public void WithForRecord()
{
var david = _john with
{
Name = "David"
};
}

[Benchmark]
public void WithForRecordStruct()
{
var david = _johnStruct with
{
Name = "David"
};
}

[Benchmark]
public void ImmutypeForRecord()
[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class RecordWithOneProperty
{
private readonly PersonRecordWithOneProperty _john = new("John");
private readonly PersonRecordStructWithOneProperty _johnStruct = new("John");

[Benchmark]
public void WithForRecord()
{
var david = _john with
{
var david = _john.WithName("David");
}
Name = "David"
};
}

[Benchmark]
public void ImmutypeForRecordStruct()
[Benchmark]
public void WithForRecordStruct()
{
var david = _johnStruct with
{
var david = _johnStruct.WithName("David");
}
Name = "David"
};
}

[Benchmark]
public void ImmutypeForRecord()
{
var david = _john.WithName("David");
}

[Benchmark]
public void ImmutypeForRecordStruct()
{
var david = _johnStruct.WithName("David");
}
}
84 changes: 42 additions & 42 deletions Immutype.Benchmark/RecordWithTwoProperties.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
// ReSharper disable UnusedVariable
namespace Immutype.Benchmark
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
// ReSharper disable WithExpressionModifiesAllMembers
namespace Immutype.Benchmark;

[Target]
public record PersonRecordWithTwoProperties(string? Name, int Age);
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;

[Target]
public readonly record struct PersonRecordStructWithTwoProperties(string? Name, int Age);
[Target]
public record PersonRecordWithTwoProperties(string? Name, int Age);

[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class RecordWithTwoProperties
{
private readonly PersonRecordWithTwoProperties _john = new("John", 15);
private readonly PersonRecordStructWithTwoProperties _johnStruct = new("John", 15);
[Target]
public readonly record struct PersonRecordStructWithTwoProperties(string? Name, int Age);

[Benchmark]
public void WithForRecord()
{
var david = _john with
{
Name = "David",
Age = 17
};
}

[Benchmark]
public void WithForRecordStruct()
{
var david = _johnStruct with
{
Name = "David",
Age = 17
};
}

[Benchmark]
public void ImmutypeForRecord()
[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class RecordWithTwoProperties
{
private readonly PersonRecordWithTwoProperties _john = new("John", 15);
private readonly PersonRecordStructWithTwoProperties _johnStruct = new("John", 15);

[Benchmark]
public void WithForRecord()
{
var david = _john with
{
var david = _john.WithName("David").WithAge(17);
}
Name = "David",
Age = 17
};
}

[Benchmark]
public void ImmutypeForRecordStruct()
[Benchmark]
public void WithForRecordStruct()
{
var david = _johnStruct with
{
var david = _johnStruct.WithName("David").WithAge(17);
}
Name = "David",
Age = 17
};
}

[Benchmark]
public void ImmutypeForRecord()
{
var david = _john.WithName("David").WithAge(17);
}

[Benchmark]
public void ImmutypeForRecordStruct()
{
var david = _johnStruct.WithName("David").WithAge(17);
}
}
12 changes: 6 additions & 6 deletions Immutype.Tests/Immutype.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Immutype\Immutype.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<ProjectReference Include="..\Immutype\Immutype.csproj"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/>
<PackageReference Include="xunit" Version="2.8.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.1" PrivateAssets="all" />
<PackageReference Include="Shouldly" Version="4.2.1"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.1" PrivateAssets="all"/>
</ItemGroup>

</Project>
Loading

0 comments on commit 1bcd83b

Please sign in to comment.