MO.Result
3.0.1
dotnet add package MO.Result --version 3.0.1
NuGet\Install-Package MO.Result -Version 3.0.1
<PackageReference Include="MO.Result" Version="3.0.1" />
<PackageVersion Include="MO.Result" Version="3.0.1" />
<PackageReference Include="MO.Result" />
paket add MO.Result --version 3.0.1
#r "nuget: MO.Result, 3.0.1"
#:package MO.Result@3.0.1
#addin nuget:?package=MO.Result&version=3.0.1
#tool nuget:?package=MO.Result&version=3.0.1
MO.Result NuGet Package
MO.Result, .NET projeleri için özel olarak tasarlanmış bir sonuç dönüşüm kütüphanesidir. Bu kütüphane, metotlarınızın dönüş değerlerini daha açıklayıcı hale getirmenize olanak tanırken, hata işleme sürecini kolaylaştırmak için kullanılır.
Nasıl Kullanılır
Kullanım: MO.Result'ı kullanmak için aşağıdaki adımları izleyin:
using MO.Result;
public class ExampleService
{
public Result<int> Divide(int numerator, int denominator)
{
if (denominator == 0)
{
return Result<int>.Fail("Denominator cannot be zero.");
}
int result = numerator / denominator;
return Result<int>.Success(result);
}
}
Kullanımda, Result <T> tipini metotların dönüş değeri olarak kullanabilirsiniz. Bu tip, başarılı veya başarısız bir işlemi temsil eder. Success ve Fail metotlarıyla sonuç döndürülebilir.
Özellikler Açıklayıcı Sonuçlar: Metotların dönüş değerlerini daha açıklayıcı hale getirir. Hata İşleme: Başarısız işlemlerin yönetimini kolaylaştırır. Generics Desteği: Herhangi bir tür için sonuçlar döndürmek için generics desteği sağlar. Katkıda Bulunma
Source Code
public sealed class Result<T>
{
public T? Data { get; private set; }
public bool IsSuccess { get; private set; }
public List<string>? ErrorMessages { get; private set; }
[JsonIgnore]
public int StatusCode { get; private set; }
private Result(T data)
{
Data = data;
StatusCode = 200;
IsSuccess = true;
}
private Result(string errorMessage, int statusCode)
{
ErrorMessages = new List<string> { errorMessage };
StatusCode = statusCode;
IsSuccess = false;
Data = default;
}
private Result(List<string> errorMessages, int statusCode)
{
ErrorMessages = errorMessages;
StatusCode = statusCode;
IsSuccess = false;
Data = default;
}
public static Result<T> Success(T data)
{
return new Result<T>(data);
}
public static Result<T> Failure(string errorMessage, int statusCode = 500)
{
return new Result<T>(errorMessage, statusCode);
}
public static Result<T> Failure(List<string> errorMessages, int statusCode = 500)
{
return new Result<T>(errorMessages, statusCode);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- 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.