MicroKnights.Collections
1.0.0
See the version list below for details.
dotnet add package MicroKnights.Collections --version 1.0.0
NuGet\Install-Package MicroKnights.Collections -Version 1.0.0
<PackageReference Include="MicroKnights.Collections" Version="1.0.0" />
paket add MicroKnights.Collections --version 1.0.0
#r "nuget: MicroKnights.Collections, 1.0.0"
// Install MicroKnights.Collections as a Cake Addin #addin nuget:?package=MicroKnights.Collections&version=1.0.0 // Install MicroKnights.Collections as a Cake Tool #tool nuget:?package=MicroKnights.Collections&version=1.0.0
Enumeration
First of all, this is a fork of Headspring Enumeration, so all credits to them.
This Enumeration has a breaking change, the reason for this fork. No exceptions thrown, but returns null itstead. Also now running .net core v2.0, and added Parser methods with fallback of default.
But again, all credits to Headpring for introducing the way...
Nuget package
Install-Package MicroKnights.Collections -Version 1.0.0 (-alpha)
Usage
Declare your enumeration by doing this:
public abstract class StatusType : Enumeration<StatusType>
{
protected StatusType(int value, string displayName)
: base(value, displayName)
{}
public static readonly StatusType Draft = new DraftStatus();
public static readonly StatusType Created = new CreatedStatus();
public static readonly StatusType Open = new StartedStatus();
public static readonly StatusType Waiting = new WaitingStatus();
public static readonly StatusType Complete = new CompletedStatus();
public static readonly StatusType Failed = new FailedStatus();
public virtual bool InProgress => false;
public virtual bool CanCreate => false;
public virtual bool CanWork => false;
public virtual bool HasFailed => false;
public abstract Color Color { get; }
public virtual string ColorHtmlRgb => $"rgb({Color.R},{Color.G},{Color.B})";
public abstract string FontawesomeGlyphName { get; }
public abstract string FontawesomeGlyphHex { get; }
}
public sealed class DraftStatus : StatusType
{
public DraftStatus()
: base(0, "Draft")
{ }
public override bool CanCreate => true;
public override Color Color => Color.Gray;
public override string FontawesomeGlyphName => "fa-circle-thin";
public override string FontawesomeGlyphHex => "f1db";
}
public sealed class CreatedStatus : StatusType
{
public CreatedStatus()
: base(10, "Created")
{ }
public override bool CanWork => true;
public override Color Color => Color.Green;
public override string FontawesomeGlyphName => "fa-plus-circle";
public override string FontawesomeGlyphHex => "f055";
}
public sealed class StartedStatus : StatusType
{
public StartedStatus()
: base(20, "Started")
{ }
public override bool InProgress => true;
public override bool CanWork => true;
public override Color Color => Color.Green;
public override string FontawesomeGlyphName => "fa-pencil";
public override string FontawesomeGlyphHex => "f040";
}
public sealed class WaitingStatus : StatusType
{
public WaitingStatus()
: base(30, "Waiting")
{ }
public override bool InProgress => true;
public override bool CanWork => true;
public override Color Color => Color.DarkGreen;
public override string FontawesomeGlyphName => "fa-pause";
public override string FontawesomeGlyphHex => "f04c";
}
public sealed class CompletedStatus : StatusType
{
public CompletedStatus()
: base(1000, "Completed")
{ }
public override Color Color => Color.Blue;
public override string FontawesomeGlyphName => "fa-flag-checkered";
public override string FontawesomeGlyphHex => "f11e";
}
public sealed class FailedStatus : StatusType
{
public FailedStatus()
: base(-1, "Failed")
{ }
public override Color Color => Color.Red;
public override bool HasFailed => true;
public override string FontawesomeGlyphName => "fa-exclamation-triangle";
public override string FontawesomeGlyphHex => "f071";
}
Now think of many entities with this status property, they can now easily be integrated for specific status by using linq:
var failedStatus = StatusType.GetAll().Where( st => st.HasFailed );
or when showing a list of entities and their status:
foreach( var entity in entities )
{
var statusType = entity.Status;
<tr>
<td>@entity.Number</td>
<td style="text-color: @statusType.ColorHtmlRgb"><i class="fa-@statusType.FontawesomeGlyphName">@statusType.DisplayName</i>
<td>@statusType.DisplayName</td>
@if( statusType.CanCreate ) {
<button>Create</button>
}
... (you get the picture)
</tr>
}
For use with Entity Framework, this can easily be done:
public class MyEntity
{
private int _statusTypeValue;
public int StatusValue => _statusTypeValue;
public StatusType Status
{
get { return StatusType.FromValue(_statusTypeVal); }
set { _statusTypeValue = value.value; }
}
}
and in your mapping:
modelBuilder.Entity<MyEntity>()
.Property(b => b.StatusValue)
.HasField("_statusTypeValue");
modelBuilder.Entity<MyEntity>()
.Property(b => b.Status)
.Ignore();
(Possible to avoid StatusValue, or another way around - anyone?)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MicroKnights.Collections:
Package | Downloads |
---|---|
MicroKnights.Gender-API
C# Implementation of https://gender-api.com |
|
MicroKnights.Enumerations
Complete set of all countries, with alpha 2 and 3 codes, Sovereignty and Internet CcTld |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.3 | 46,822 | 11/6/2018 |
1.1.3-alpha1 | 832 | 3/21/2018 |
1.1.2 | 3,335 | 1/9/2018 |
1.1.1 | 885 | 11/8/2017 |
1.1.0 | 936 | 11/6/2017 |
1.0.0 | 1,235 | 10/28/2017 |
1.0.0-alpha | 1,086 | 10/26/2017 |
First release