MO.Result 3.0.1

dotnet add package MO.Result --version 3.0.1
                    
NuGet\Install-Package MO.Result -Version 3.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MO.Result" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MO.Result" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MO.Result" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MO.Result --version 3.0.1
                    
#r "nuget: MO.Result, 3.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MO.Result@3.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MO.Result&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MO.Result&version=3.0.1
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
3.0.1 548 3/26/2025
3.0.0 218 3/11/2025
2.0.0 220 8/26/2024
1.0.2 183 8/26/2024
1.0.1 183 5/12/2024
1.0.0 179 5/12/2024