EnumCentricStatusManagement 1.0.0
dotnet add package EnumCentricStatusManagement --version 1.0.0
NuGet\Install-Package EnumCentricStatusManagement -Version 1.0.0
<PackageReference Include="EnumCentricStatusManagement" Version="1.0.0" />
paket add EnumCentricStatusManagement --version 1.0.0
#r "nuget: EnumCentricStatusManagement, 1.0.0"
// Install EnumCentricStatusManagement as a Cake Addin #addin nuget:?package=EnumCentricStatusManagement&version=1.0.0 // Install EnumCentricStatusManagement as a Cake Tool #tool nuget:?package=EnumCentricStatusManagement&version=1.0.0
EnumCentricStatusManagement
EnumCentricStatusManagement is an open-source C# library that provides a modern approach to enum-based state management in software projects. This library enhances enums with customizable attributes and improves code quality with centralized error handling.
Features
- Enum Based Management: Simplifies state management by adding descriptive attributes to enums.
- Centralized Error Management: Provides a centralized error handling mechanism through enum metadata.
- Easy Integration: Easily integrates into your project and is extendable for custom use cases.
- Code Readability: Makes your code cleaner and more descriptive by avoiding complex if/else structures.
Quick Start
1. Installing the Library
First, include the EnumCentricStatusManagement
library in your project by using the following NuGet command:
dotnet add package EnumCentricStatusManagement
2. Define an Enum with Attributes
Use the library to define enums enriched with metadata for status management:
public enum Status
{
[Status("Operation Successful", StatusType.Success)]
Success,
[Status("Operation Failed", StatusType.Error)]
Failure,
[Status("User Not Found", StatusType.Warning)]
UserNotFound
}
### 3. Access Enum Metadata
Access the descriptive attributes attached to enums easily:
4. Centralized Error Management
Use enum metadata to implement a centralized error handling mechanism:
try
{
var status = Status.Failure;
var statusInfo = status.GetEnumStatus();
if (statusInfo.Type == StatusType.Error)
{
throw new Exception(statusInfo.Message);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message); // Output: "Operation Failed"
}
5. Running Tests
Run the built-in tests to ensure the library works as expected:
dotnet test
Test run successful.
Total tests: 3
Passed: 3
6. Real-World Usage
Integrate this library into your application. For example, in a Web API, you can use it as follows:
public IActionResult GetUser(int id)
{
var user = userRepository.FindById(id);
if (user == null)
return BadRequest(Status.UserNotFound.GetEnumStatus().Message);
return Ok(user);
}
Project Structure
The project is organized as follows:
EnumCentricStatusManagement/
├── src/
│ ├── Enums/
│ ├── Attributes/
│ ├── Extensions/
├── tests/
│ ├── DatabaseTests.cs
│ ├── EnumTests.cs
├── docs/
│ ├── README.md
│ ├── USAGE.md
│ ├── CHANGELOG.md
src: Contains core library code. tests: Includes unit and integration tests. docs: Contains documentation files.
Contributing
To contribute to this project:
Fork the repository. Create a new branch: git checkout -b feature/your-feature. Make your changes and commit them: git commit -m "Add some feature". Push to the branch: git push origin feature/your-feature. Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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
- System.Data.SqlClient (>= 4.9.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.0.0 | 94 | 12/4/2024 |