DMNSN.Extensions 8.0.1

dotnet add package DMNSN.Extensions --version 8.0.1                
NuGet\Install-Package DMNSN.Extensions -Version 8.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="DMNSN.Extensions" Version="8.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DMNSN.Extensions --version 8.0.1                
#r "nuget: DMNSN.Extensions, 8.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.
// Install DMNSN.Extensions as a Cake Addin
#addin nuget:?package=DMNSN.Extensions&version=8.0.1

// Install DMNSN.Extensions as a Cake Tool
#tool nuget:?package=DMNSN.Extensions&version=8.0.1                

DMNSN Extensions

License: MIT

DMNSN Extensions is a C# library that provides extension methods for working with enums and exceptions. This library aims to simplify common tasks and improve code readability.

Table of Contents

Installation

You can install DMNSN Extensions via NuGet Package Manager:

Install-Package DMNSN.Extensions

Usage

Enum Extensions

The EnumExtensions class provides extension methods for working with enums. It is located in src/EnumExtensions.cs.

Methods
  • ToInt<T>(this T source) where T : Enum
    • Converts the enum value to its corresponding integer representation.
    • Parameters:
      • source: The enum value to convert.
    • Returns: The integer representation of the enum value.
  • GetDescription<T>(this T source) where T : Enum
    • Gets the description attribute value of the enum value.
    • Parameters:
      • source: The enum value.
    • Returns: The description attribute value of the enum value.
Example
using DMNSN.Extensions;

public enum SampleEnum
{
    [Description("Sample Description")]
    SampleValue
}

var value = SampleEnum.SampleValue;
int intValue = value.ToInt();
string description = value.GetDescription();

Exception Extensions

The ExceptionExtensions class provides extension methods for the Exception class. It is located in src/ExceptionExtensions.cs.

Methods
  • GetMessage(this Exception ex, bool getInner = true, string inSeparator = INNER_EX_SEPARATOR)
    • Gets the message of the exception and its inner exceptions recursively.
    • Parameters:
      • ex: The exception.
      • getInner: Flag indicating whether to include inner exceptions.
      • inSeparator: Separator string between the exception messages.
      • Returns: The concatenated message of the exception and its inner exceptions.
  • GetMessageUrlEncoded(this Exception ex, bool getInner = true, string inSeparator = INNER_EX_SEPARATOR)
    • Gets the URL-encoded message of the exception and its inner exceptions recursively.
    • Parameters:
      • ex: The exception.
      • getInner: Flag indicating whether to include inner exceptions.
      • inSeparator: Separator string between the exception messages.
      • Returns: The URL-encoded concatenated message of the exception and its inner exceptions.
Example
using DMNSN.Extensions;

try
{
    // Some code that throws an exception
}
catch (Exception ex)
{
    string message = ex.GetMessage();
    string urlEncodedMessage = ex.GetMessageUrlEncoded();
}

License

his project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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
8.0.1 126 8/11/2024

Initial release. Starting base version with version of dotnet