Skip to content

Commit

Permalink
Merge pull request #140 from SteveDunn/extend-members-attribute-for-s…
Browse files Browse the repository at this point in the history
…trings

Extend Members attribute to allow strings
  • Loading branch information
SteveDunn authored Jul 12, 2024
2 parents 7461479 + b5386ed commit dd3a2a9
Show file tree
Hide file tree
Showing 12,518 changed files with 272,247 additions and 53,092 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
20 changes: 10 additions & 10 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
param($verbosity = "minimal") #quite|q, minimal|m, normal|n, detailed|d
param($verbosity = "minimal", $buildConfig = "Release") #quite|q, minimal|m, normal|n, detailed|d

$artifacts = ".\artifacts"
$localPackages = ".\local-global-packages"
Expand Down Expand Up @@ -42,7 +42,7 @@ function Exec
}
}

WriteStage("Building release version of Intellenum...")
WriteStage("Building $buildConfig version of Intellenum...")

if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }

Expand All @@ -52,22 +52,22 @@ New-Item -Path $localPackages -ItemType Directory -ErrorAction SilentlyContinue

if(Test-Path $localPackages) { Remove-Item $localPackages\intellenum.* -Force -ErrorAction SilentlyContinue }

WriteStage("Cleaning, restoring, and building release version of Intellenum...")
WriteStage("Cleaning, restoring, and building $buildConfig version of Intellenum...")

WriteStage("... clean ...")
exec { & dotnet clean Intellenum.sln -c Release --verbosity $verbosity}
exec { & dotnet clean Intellenum.sln -c $buildConfig --verbosity $verbosity}

WriteStage("... restore ...")
exec { & dotnet restore Intellenum.sln --no-cache --verbosity $verbosity }

exec { & dotnet build Intellenum.sln -c Release -p Thorough=true --no-restore --verbosity $verbosity}
exec { & dotnet build Intellenum.sln -c $buildConfig -p Thorough=true --no-restore --verbosity $verbosity}

# run the analyzer tests
WriteStage("Running analyzer tests...")
exec { & dotnet test tests/AnalyzerTests/AnalyzerTests.csproj -c Release --no-build -l trx -l "GitHubActions;report-warnings=false" --verbosity $verbosity }
exec { & dotnet test tests/AnalyzerTests/AnalyzerTests.csproj -c $buildConfig --no-build -l trx -l "GitHubActions;report-warnings=false" --verbosity $verbosity }

WriteStage("Running unit tests...")
exec { & dotnet test tests/Intellenum.Tests/Intellenum.Tests.csproj -c Release --no-build -l trx -l "GitHubActions;report-warnings=false" --verbosity $verbosity }
exec { & dotnet test tests/Intellenum.Tests/Intellenum.Tests.csproj -c $buildConfig --no-build -l trx -l "GitHubActions;report-warnings=false" --verbosity $verbosity }

# Run the end to end tests. The tests can't have project references to Intellenum. This is because, in Visual Studio,
# it causes conflicts caused by the difference in runtime; VS uses netstandard2.0 to load and run the analyzers, but the
Expand All @@ -92,7 +92,7 @@ exec { & dotnet pack ./src/Intellenum.Pack.csproj -c Debug -o:$localPackages /p:
WriteStage("Cleaning and building consumers (tests and samples)")

exec { & dotnet restore Consumers.sln --no-cache --verbosity $verbosity }
exec { & dotnet clean Consumers.sln -c Release --verbosity $verbosity}
exec { & dotnet clean Consumers.sln -c $buildConfig --verbosity $verbosity}


# Restore the project using the custom config file, restoring packages to a local folder
Expand All @@ -111,10 +111,10 @@ WriteStage("Building samples using the local version of the NuGet package...")
exec { & dotnet run --project samples/Intellenum.Examples/Intellenum.Examples.csproj -c Debug --no-build --no-restore }


WriteStage("Finally, packing the release version into " + $artifacts)
WriteStage("Finally, packing the $buildConfig version into " + $artifacts)


exec { & dotnet pack src/Intellenum.Pack.csproj -c Release -o $artifacts --no-build --verbosity $verbosity }
exec { & dotnet pack src/Intellenum.Pack.csproj -c $buildConfig -o $artifacts --no-build --verbosity $verbosity }

WriteStage("Done! Package generated at " + $artifacts)

2 changes: 1 addition & 1 deletion samples/Intellenum.Examples/Intellenum.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Dapper" Version="2.0.143" />
<PackageReference Include="linq2db" Version="3.7.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Intellenum.Examples.TypicalScenarios.Basic;

[UsedImplicitly]
internal class BasicExamples : IScenario
internal class BasicScenario : IScenario
{
public Task Run()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace Intellenum.Examples.TypicalScenarios.Deconstruction;

internal class DeconstructionExamples : IScenario
[UsedImplicitly]
internal class DeconstructionScenario : IScenario
{
public Task Run()
{
Expand Down
30 changes: 0 additions & 30 deletions samples/Intellenum.Examples/TypicalScenarios/EqualityExamples.cs

This file was deleted.

31 changes: 31 additions & 0 deletions samples/Intellenum.Examples/TypicalScenarios/EqualityScenario.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;

// ReSharper disable RedundantCast

namespace Intellenum.Examples.TypicalScenarios.Equality;

[UsedImplicitly]
internal class EqualityScenario : IScenario
{
public Task Run()
{
Console.WriteLine(Centigrade.AbsoluteZero == Centigrade.FromName("AbsoluteZero")); // true
Console.WriteLine(Centigrade.AbsoluteZero == Centigrade.FromValue(-273.15m)); // true
Console.WriteLine(Centigrade.AbsoluteZero == -273.15m); // true

return Task.CompletedTask;
}
}

[Intellenum<decimal>]
public partial class Centigrade
{
static Centigrade()
{
Member("AbsoluteZero", -273.15m);
Member("FreezingPointOfWater", 0m);
Member("BoilingPointOfWater", 100m);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace Intellenum.Examples.TypicalScenarios.ExplicitCasting
namespace Intellenum.Examples.TypicalScenarios.ExplicitCasting;

[UsedImplicitly]
internal class ExplicitCastingScenario : IScenario
{
internal class ExplicitCastingScenario : IScenario
public Task Run()
{
public Task Run()
{
// We can create an instance with an explicit cast. If there is validation, it is still run.
Result result1 = (Result)2;
Result result2 = Result.FromValue(2);
Expand All @@ -20,14 +22,13 @@ public Task Run()

return Task.CompletedTask;
}
}
}

// defaults to int
[Intellenum]
[Member("Won", 2)]
[Member("Drawn", 1)]
[Member("Lost", 0)]
internal partial class Result
{
}
// defaults to int
[Intellenum]
[Member("Won", 2)]
[Member("Drawn", 1)]
[Member("Lost", 0)]
internal partial class Result
{
}
34 changes: 0 additions & 34 deletions samples/Intellenum.Examples/TypicalScenarios/IComparable.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Linq;
using System.Threading.Tasks;

namespace Intellenum.Examples.TypicalScenarios.IComparable;

internal class IComparableScenario : IScenario
{
public Task Run()
{
// The underlying type of PlanetEnum is Planet, which implements IComparable<Planet> and
// compares on circumference. This means that the Intellenum can be sorted.

Console.WriteLine(PlanetEnum.Mars < PlanetEnum.Jupiter); // true

Console.WriteLine(string.Join(", ", PlanetEnum.List().OrderDescending())); // Jupiter, Venus, Mars

return Task.CompletedTask;
}
}

[Intellenum<Planet>]
public partial class PlanetEnum
{
public static readonly PlanetEnum Jupiter = new(new Planet("Brown", 273_400));
public static readonly PlanetEnum Mars= new(new Planet("Red", 13_240));
public static readonly PlanetEnum Venus= new(new Planet("White", 23_622));
}

public record class Planet(string Colour, int CircumferenceInMiles) : IComparable<Planet>
{
public int CompareTo(Planet other) => CircumferenceInMiles.CompareTo(other.CircumferenceInMiles);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System;
using System.Threading.Tasks;

namespace Intellenum.Examples.TypicalScenarios.Lists;

internal class ListExamples : IScenario
internal class ListsScenario : IScenario
{
public Task Run()
{
Expand All @@ -27,6 +27,3 @@ public Task Run()
internal partial class Result
{
}



Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,43 @@
namespace Intellenum.Examples.TypicalScenarios.Members;

[UsedImplicitly]
internal class MemberExamples : IScenario
internal class MembersScenario : IScenario
{
public Task Run()
{
VendorInformation vi = new VendorInformation();
Console.WriteLine((bool) (vi.VendorId == VendorType.Unspecified)); // true
Console.WriteLine((bool) (vi.VendorId != VendorType.Invalid)); // true
Console.WriteLine(vi.VendorType == VendorType.Unspecified); // true
Console.WriteLine(vi.VendorType != VendorType.Invalid); // true

// from a text file that is screwed, we'll end up with:
var invalidVi = VendorInformation.FromTextFile();

Console.WriteLine((bool) (invalidVi.VendorId == VendorType.Invalid)); // true
Console.WriteLine((bool) (invalidVi.VendorType == VendorType.Invalid)); // true

Console.WriteLine("Implied field, \"Member1\" has a value of " + ImpliedMemberNames.Member1); // Implied field, "Member1" is 1

return Task.CompletedTask;
}
}

[Intellenum<string>]
[Members("Zero, One, Two, Three")]
[Member("Four")]
[Member("Five")]
[Member("Six")]
public partial class Mixture
{
static Mixture()
{
Member("Nine");
Member("Ten");
Members("Eleven, Twelve");
Member("Thirteen");
}
public static readonly Mixture Seven = new();
public static readonly Mixture Eight = new();
}

[Intellenum]
public partial class ImpliedMemberNames
{
Expand Down Expand Up @@ -68,14 +86,14 @@ static CondimentMixedMembers()

public class VendorInformation
{
public VendorType VendorId { get; private init; } = VendorType.Standard;
public VendorType VendorType { get; private init; } = VendorType.Standard;

public static VendorInformation FromTextFile()
{
// imagine the text file is screwed...
return new VendorInformation
{
VendorId = VendorType.Invalid
VendorType = VendorType.Invalid
};
}
}
Loading

0 comments on commit dd3a2a9

Please sign in to comment.