StaticDictionaries 1.0.0-beta
See the version list below for details.
dotnet add package StaticDictionaries --version 1.0.0-beta
NuGet\Install-Package StaticDictionaries -Version 1.0.0-beta
<PackageReference Include="StaticDictionaries" Version="1.0.0-beta" />
paket add StaticDictionaries --version 1.0.0-beta
#r "nuget: StaticDictionaries, 1.0.0-beta"
// Install StaticDictionaries as a Cake Addin #addin nuget:?package=StaticDictionaries&version=1.0.0-beta&prerelease // Install StaticDictionaries as a Cake Tool #tool nuget:?package=StaticDictionaries&version=1.0.0-beta&prerelease
StaticDictionaries 📚
Simple high performance solution for data hardcoding. Smart. Flexible. Powerful.
Powered by source generators. Without using reflection ❌
StaticDictionaries is a convinient library for data hardcoding in your project.
Just decorate the enum
using attributes, the source generator will do the rest for you.
Minimum code and time spent - maximum result and performance. Property management has never been so convenient.
Generated methods for managing enum
without reflection will make development pleasant and faster than ever.
Installing StaticDictionaries
StaticDictionaries is available on NuGet.
dotnet add package StaticDictionaries
Install-Package StaticDictionaries
Powerful enum
management 🦾
Source generator creates some methods in [EnumName]Extensions class for convenient and fast enum
management:
Length
quantity of all enum members.MinId
returns minId()
.MaxId
returns maxId()
.All()
returns an array of allenum
members.GetById()
returns member orNotSupportedException
.
Dictionary supported primitive types 🗿
CLR type | Status |
---|---|
int |
✅ |
bool |
✅ |
char |
✅ |
double |
✅ |
string |
✅ |
Samples 🤝
Employee dictionary with Name
, Age
and Active
properties:
[StaticDictionary("Name", "Age", "Active")]
public enum Employee
{
[Value("Maxim Jhonson", 18, true)]
Maxim = 1,
[Value("John Jhonson", 23, false)]
John = 2
}
public static void Main()
{
int johnAge = Employee.John.Age();
int maximAge = Employee.Maxim.Age();
string johnName = Employee.John.Name();
string maximName = Employee.Maxim.Name();
}
Source generator creates [EnumName]Extensions class that provide some powerful functionality for managing your enum
:
[StaticDictionary("Name", "IsLast")]
public enum Status
{
[Value("New state", false)]
New = 1,
[Value("In progress", false)]
InProgress = 2,
[Value("In progress", true)]
Completed = 3
}
public static void Main()
{
Status status = StatusExtensions.GetById(2);
Status[] statuses = StatusExtensions
.All()
.Where(x => !x.IsLast())
.ToArray();
}
Id()
and Name()
methods are generated by default if you do not override them.
[StaticDictionary]
public enum Metal
{
[Value]
Gold = 1,
[Value]
Ferrum = 2
}
public static void Main()
{
int goldId = Metal.Gold.Id();
string ferrumName = Metal.Ferrum.Name();
}
Important notes ⚠️
StaticDictionary
parameter names must not be duplicated.StaticDictionary
parameter names must use the English alphabet only because they will be generated into methods.- All
Value
attrubutes must contain such arguments quantity asStaticDictionary
. - All
StaticDictionary
enum
members must containValue
attribute with arguments. - Generator creates two methods by default:
Id()
with(int)member
andName()
withnameof(member)
if you do not override them. enum
members withoutValue
attribute will be ignored.- Parameter types are determined automatically, so all parameters in a sequence must be of the same type.
For example, all of the first types should be
string
, and all of the second types should bebool
.
Disclaimer ❗️
The material embodied in this software is provided to you "as-is" and without warranty of any kind, express, implied or otherwise, including without limitation, any warranty of fitness for a particular purpose. In no event shall the Centers for Disease Control and Prevention (CDC) or the United States (U.S.) government be liable to you or anyone else for any direct, special, incidental, indirect or consequential damages of any kind, or any damages whatsoever, including without limitation, loss of profit, loss of use, savings or revenue, or the claims of third parties, whether or not CDC or the U.S. government has been advised of the possibility of such loss, however caused and on any theory of liability, arising out of or in connection with the possession, use or performance of this software.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.1 | 4,877 | 11/19/2022 |
1.3.1-preview1 | 163 | 11/18/2022 |
1.3.0 | 360 | 11/11/2022 |
1.2.0 | 3,042 | 10/1/2022 |
1.1.0 | 455 | 8/10/2022 |
1.0.0 | 437 | 7/10/2022 |
1.0.0-rc | 189 | 7/3/2022 |
1.0.0-beta2 | 154 | 7/2/2022 |
1.0.0-beta | 287 | 7/2/2022 |
First release with main functionality.