Sam.Wrappers
1.0.0
See the version list below for details.
dotnet add package Sam.Wrappers --version 1.0.0
NuGet\Install-Package Sam.Wrappers -Version 1.0.0
<PackageReference Include="Sam.Wrappers" Version="1.0.0" />
paket add Sam.Wrappers --version 1.0.0
#r "nuget: Sam.Wrappers, 1.0.0"
// Install Sam.Wrappers as a Cake Addin #addin nuget:?package=Sam.Wrappers&version=1.0.0 // Install Sam.Wrappers as a Cake Tool #tool nuget:?package=Sam.Wrappers&version=1.0.0
Sam.Wrappers
This package contains classes and methods designed for managing operation results, errors, and paginated responses in .NET applications.
Installation
To install the Sam.Wrappers package, simply use the following command
dotnet add package Sam.Wrappers
Features
BaseResult and BaseResult<T>:
- Handle operation results with an indication of success or failure.
- Provide support for single or multiple errors.
- Allow chaining and adding errors post-creation.
- Implicitly convert from error or list of errors to
BaseResult
for flexible error handling.
-
- Manage paginated data responses, encapsulating data along with pagination metadata like page number, total pages, and total items.
- Includes static factory methods to quickly generate paginated results.
-
- Define errors with an
ErrorCode
enum that covers standard HTTP status codes and custom application-specific errors. - Structure errors with optional descriptions and field names for context.
- Define errors with an
Usage
BaseResult
The BaseResult
and BaseResult<T>
classes are used to handle operation results, allowing you to check for success or failure and manage errors.
using Sam.Wrappers;
// Create a successful result
var successResult = BaseResult.Ok();
// Create a failed result with an error
var error = new Error(ErrorCode.BadRequest, "Invalid data");
var failureResult = BaseResult.Failure(error);
PagedResponse
The PagedResponse<T>
class is used to manage paginated responses in APIs and systems that require pagination.
using Sam.Wrappers;
using System.Collections.Generic;
// Sample data
var data = new List<string> { "Item1", "Item2", "Item3" };
int pageNumber = 1;
int pageSize = 3;
int totalCount = 3;
// Create a paginated response
var pagedResponse = PagedResponse<string>.Ok(data, totalCount, pageNumber, pageSize);
Error and ErrorCode
Use Error
and ErrorCode
to manage errors and refer to specific predefined error codes.
using Sam.Wrappers;
var error = new Error(ErrorCode.NotFound, "Item not found", "ItemId");
Contributing
Contributions are welcome! If you’d like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch (git checkout -b feature/YourFeature).
- Make your changes and commit them (git commit -am 'Add new feature').
- Push to the branch (git push origin feature/YourFeature).
- Open a Pull Request.
If you encounter any issues or have suggestions, feel free to open an issue in the repository.
License
This project is licensed under the MIT License.
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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.