Skip to content

Commit

Permalink
Merge pull request #25 from SteveDunn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
SteveDunn authored Apr 4, 2023
2 parents b8f4622 + ebfb4aa commit dc677a5
Show file tree
Hide file tree
Showing 230 changed files with 6,250 additions and 17,023 deletions.
3 changes: 3 additions & 0 deletions Consumers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E89977F3-1B28-498E-8D63-9E49EE4D84D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E89977F3-1B28-498E-8D63-9E49EE4D84D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E89977F3-1B28-498E-8D63-9E49EE4D84D3}.Release|Any CPU.Build.0 = Release|Any CPU
{E89977F3-1B28-498E-8D63-9E49EE4D84D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9FAC951-7F77-49B5-9DCD-C8278B45EE65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9FAC951-7F77-49B5-9DCD-C8278B45EE65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9FAC951-7F77-49B5-9DCD-C8278B45EE65}.Release|Any CPU.Build.0 = Release|Any CPU
{B9FAC951-7F77-49B5-9DCD-C8278B45EE65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53C7CAAF-5A7F-4AF0-9C9E-216F13A054D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53C7CAAF-5A7F-4AF0-9C9E-216F13A054D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53C7CAAF-5A7F-4AF0-9C9E-216F13A054D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public partial class CustomerType
}
}
```

## Features

* `FromName()` and `FromValue()` (and `TryFrom...`)
Expand Down Expand Up @@ -197,10 +196,25 @@ _note that EnumGenerators isn't here as we use the standard C# enum to get its v
| SmartEnums | 0.3246 ns | 0.0082 ns | 0.0069 ns | - |
| **Intellenums** | **0.3198 ns** | **0.0103 ns** | **0.0096 ns** | **-** |

Note that Intellenums also has a `ValueCheck` property which throws if the
value hasn't been initialised. This takes twice as long. This isn't usually a problem
but if you're in a very tight loop and you're sure everything is initialized, then use
`Value` instead
### What does `ToString` return?
It returns the **name** of the instance.
There is also a TypeConverter; when this is asked to convert an instance to a `string',
it returns the **value** of the instance as a string.

### What can the `TypeConverters` convert to and from?
They can convert an underlying type back to a matching enum.

### Can it serialize/deserialize?
Yes, it can. There's various ways to do this, including:
* System.Text.Json
* Newtonsoft.Json
* Dapper
* Entity Framework Core
* Linq2Db
* TypeConverters

Right now, Intellenum serializes using the `Value` property just like native enums.



> NOTE: Intellenum is in pre-release at the moment, so probably isn't production ready and the API might (and probably will) change.
Expand Down
44 changes: 23 additions & 21 deletions Scratch/GeneralTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
using FluentAssertions;
using Xunit.Abstractions;
#nullable disable

using System.ComponentModel;
using FluentAssertions;
using Intellenum;
using Intellenum.IntegrationTests.TestTypes.ClassVos;

namespace Scratch;

// [Intellenum(conversions: Conversions.TypeConverter, underlyingType: typeof(Bar))]
// public partial class NoJsonFooVo
// {
// static NoJsonFooVo()
// {
// Instance("Item1", new NoJsonFooVo(new Bar(42, "Fred")));
// Instance("Item2", new NoJsonFooVo(new Bar(2, "Two")));
// }
// }

public record struct Bar(int Age, string Name) : IComparable<Bar>
{
public int CompareTo(Bar other) => Age.CompareTo(other.Age);
}



public class GeneralTests
{
Expand All @@ -12,6 +32,7 @@ enum ECustomerType
Gold
}


[Fact]
public void ToStringTest()
{
Expand Down Expand Up @@ -81,23 +102,4 @@ public void General()
((int) t1 == t1).Should().BeTrue();
((int) t1 == 1).Should().BeTrue();
}
}
public class ListTests
{
private readonly ITestOutputHelper _testOutputHelper;

public ListTests(ITestOutputHelper testOutputHelper) => _testOutputHelper = testOutputHelper;

[Fact]
public void General()
{
var l = CustomerType.List();

l.Count().Should().Be(2);

foreach (var (name, value) in CustomerType.List())
{
_testOutputHelper.WriteLine($"{name} - {value}");
}
}
}
37 changes: 37 additions & 0 deletions Scratch/ImpliedFieldNameTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using FluentAssertions;
using Intellenum;

namespace Scratch
{
public class ImpliedFieldNameTests
{
[Fact]
public void General()
{
ImpliedFieldName.Instance1.Value.Should().Be(1);
ImpliedFieldName.Instance2.Value.Should().Be(2);
ImpliedFieldName.Instance3.Value.Should().Be(3);

ImpliedFieldName.IsDefined(1).Should().BeTrue();
ImpliedFieldName.IsDefined(2).Should().BeTrue();
ImpliedFieldName.IsDefined(3).Should().BeTrue();

ImpliedFieldName.TryFromName("Instance1", out var i1).Should().BeTrue();
i1.Value.Should().Be(1);

ImpliedFieldName.TryFromName("INSTANCE 3!!", out var i3).Should().BeTrue();
i3.Value.Should().Be(3);

ImpliedFieldName.IsDefined(3).Should().BeTrue();
ImpliedFieldName.IsNamedDefined("INSTANCE 3!!").Should().BeTrue();
}
}

[Intellenum]
public partial class ImpliedFieldName
{
public static readonly ImpliedFieldName Instance1 = new(1);
public static readonly ImpliedFieldName Instance2 = new(2);
public static readonly ImpliedFieldName Instance3 = new("INSTANCE 3!!", 3);
}
}
25 changes: 25 additions & 0 deletions Scratch/ListTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using FluentAssertions;
using Xunit.Abstractions;

namespace Scratch
{
public class ListTests
{
private readonly ITestOutputHelper _testOutputHelper;

public ListTests(ITestOutputHelper testOutputHelper) => _testOutputHelper = testOutputHelper;

[Fact]
public void General()
{
var l = CustomerType.List();

l.Count().Should().Be(2);

foreach (var (name, value) in CustomerType.List())
{
_testOutputHelper.WriteLine($"{name} - {value}");
}
}
}
}
4 changes: 2 additions & 2 deletions Scratch/Scratch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<PropertyGroup>
<!-- Test directory-->
<LocalPackagesDirectory>$(MSBuildProjectDirectory)local-global-packages</LocalPackagesDirectory>
<LocalPackagesDirectory>$(MSBuildProjectDirectory)\..\local-global-packages</LocalPackagesDirectory>
</PropertyGroup>

<Target Name="EnsureLocalPackagesFolderExists" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(BuildingInsideVisualStudio)' == 'true'">
Expand All @@ -26,7 +26,7 @@


<ItemGroup>
<TestPath Include="../../local-global-packages" />
<TestPath Include="../local-global-packages" />
</ItemGroup>
<Target Name="OnlyIfExists" Condition="Exists(@(TestPath))">
<Message Text="Please run Test.ps1 to build the latest local nuget package that these tests consume" Importance="high" />
Expand Down
Loading

0 comments on commit dc677a5

Please sign in to comment.