Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ogulcanturan/ogu.extensions.saferesult
Safely creates collections from separated strings
https://github.com/ogulcanturan/ogu.extensions.saferesult
Last synced: 12 days ago
JSON representation
Safely creates collections from separated strings
- Host: GitHub
- URL: https://github.com/ogulcanturan/ogu.extensions.saferesult
- Owner: ogulcanturan
- License: apache-2.0
- Created: 2024-05-13T10:23:29.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-08-04T23:53:57.000Z (6 months ago)
- Last Synced: 2025-01-03T19:46:32.864Z (about 1 month ago)
- Language: C#
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
#
Ogu.Extensions.SafeResult
[![.NET](https://github.com/ogulcanturan/Ogu.Extensions.SafeResult/actions/workflows/dotnet.yml/badge.svg?branch=master)](https://github.com/ogulcanturan/Ogu.Extensions.SafeResult/actions/workflows/dotnet.yml)
[![NuGet](https://img.shields.io/nuget/v/Ogu.Extensions.SafeResult.svg?color=1ecf18)](https://nuget.org/packages/Ogu.Extensions.SafeResult)
[![Nuget](https://img.shields.io/nuget/dt/Ogu.Extensions.SafeResult.svg?logo=nuget)](https://nuget.org/packages/Ogu.Extensions.SafeResult)## Introduction
Ogu.Extensions.SafeResult is a library that safely creates collections from separated strings.
## Features
- **Safe Parsing:** Safely parse separated strings into collections without encountering exceptions.
- **Customization:** Specify whether parsing should stop on the first failure or continue parsing subsequent elements.
- **Supports:** List, HashSet, and Dictionary (extensions: ToSafeList, ToSafeHashSet, ToSafeDictionary)## Installation
You can install the library via NuGet Package Manager:
```bash
dotnet add package Ogu.Extensions.SafeResult
```## Usage
**HashSet:**
```csharp
public class Request
{
[FromQuery(Name = "ids"), JsonIgnore]
public string Ids { get; set; } = "1,2,3 , 4, a, 6";[BindNever, JsonIgnore]
public ISafeResult> IdList => _idList ??= SafeResult.HashSet(Ids, stopOnFailure: true);private ISafeResult> _idList;
}
```IdList.Result =>
```bash
[1,2,3,4]
```**EnumHashSet:**
```csharp
public enum Color
{
Red,
Green,
Blue,
}public class Request
{
[FromQuery(Name = "ids"), JsonIgnore]
public string Ids { get; set; } = "0, a, 16, 1, 2";[BindNever, JsonIgnore]
public ISafeResult> IdList => _idList ??= SafeResult.EnumHashSet(Ids, stopOnFailure: true);private ISafeResult> _idList;
}
```IdList.Result =>
```bash
[Red]
```**OrderedDictionary:**
```csharp
public class Request
{
[FromQuery(Name = "ids"), JsonIgnore]
public string Ids { get; set; } = "1,2,3 , 4, a, 6";[BindNever, JsonIgnore]
public ISafeResult> IdList => _idList ??= SafeResult.OrderedDictionary(Ids, stopOnFailure: false);private ISafeResult> _idList;
}
```IdList.Result =>
```bash
{
"1":0,
"2":1,
"3":2,
"4":3,
"6":4
}
```**List:**
```csharp
public class Request
{
[FromQuery(Name = "ids"), JsonIgnore]
public string Ids { get; set; } = "Item1,Item2,Item3,item3,25";[BindNever, JsonIgnore]
public ISafeResult> IdList => _idList ??= SafeResult.List(Ids, stopOnFailure: false);private ISafeResult> _idList;
}
```IdList.Result =>
```bash
[25]
```