NetExt.Models 1.0.1-beta

Suggested Alternatives

NetExt.Models 1.0.3

Additional Details

legacy

This is a prerelease version of NetExt.Models.
There is a newer version of this package available.
See the version list below for details.
dotnet add package NetExt.Models --version 1.0.1-beta                
NuGet\Install-Package NetExt.Models -Version 1.0.1-beta                
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="NetExt.Models" Version="1.0.1-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetExt.Models --version 1.0.1-beta                
#r "nuget: NetExt.Models, 1.0.1-beta"                
#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 NetExt.Models as a Cake Addin
#addin nuget:?package=NetExt.Models&version=1.0.1-beta&prerelease

// Install NetExt.Models as a Cake Tool
#tool nuget:?package=NetExt.Models&version=1.0.1-beta&prerelease                

Namespace: NetExt.Models.*

Namespace contains the different models & exceptions.

Models:

  • IdNameModel
  • ListResult

Exceptions:

  • BadRequestException
  • ForbiddenException
  • NotFoundException
  • UnAuthorizationException

NetExt.Core

This is list of daily-useful .net extensions

Namespace: NetExt.Core.Actions

Await Extensions

The AwaitExt class provides utility methods for efficiently handling multiple asynchronous tasks, including tasks with and without return values. These extensions simplify combining, executing, and awaiting multiple tasks, making it easier to manage complex asynchronous workflows.

var noResultTasks = new [] { Task.Delay(100), Task.Delay(200), Task.Delay(300) };
var result = await AwaitExt.TasksAsync(
                 /* taskas with return results */
                 DelayValueAsync<int>(InputValue1),
                 DelayValueAsync<string>(InputValue2),
                 /* options tasks without results */
                 noResultTasks);

Assert.True(result.Item1 == InputValue1);
Assert.True(result.Item2 == InputValue2);
Benefits:
  1. Simplifies Asynchronous Workflows Enables easy execution and awaiting of multiple tasks, avoiding complex Task.WhenAll and manual result extraction.
  2. Supports Mixed Tasks Handles both returnable and non-returnable tasks in a single method call.
  3. Tuple Support for Results Returns results in a clean, structured tuple format, making it easier to work with multiple outputs.
  4. Scalability Supports up to 20 tasks with return values, accommodating even the most complex workflows.
When to Use:
  1. Combining Multiple Tasks When you need to wait for multiple tasks, possibly with mixed return types.
  2. Improved Readability To reduce boilerplate code for managing Task.WhenAll and extracting results.

Try Extensions

The TryExt class provides utility methods for safely executing synchronous and asynchronous actions with built-in support for exception handling and finalization logic. These methods are designed to simplify error-prone tasks by offering a clean, reusable, and configurable way to handle exceptions and ensure post-action cleanup.

TryExt.Execute(
    action: () => { /* execute some action, with or without return result */ },
    /* optional */
    catchAction: (exception) => { Trace.WriteLine(exception.Message); },
    /* optional */
    finallyAction: () => { /* final action */ });

/* The same for async */
await TryExt.ExecuteAsync(...);

Namespace: NetExt.Core.Require

The namespace provides utility methods to enforce object validity and condition checks at runtime. These methods are particularly useful for defensive programming, ensuring that objects meet necessary conditions before proceeding with execution.

Namespace: NetExt.Core.Collections

The namespace class provides utility methods for working with collections in a more intuitive and streamlined way. These extensions help convert individual items into various collection types and simplify iteration over collections.

ForEach Extension

The ForEachExt method is an extension for IEnumerable<T> that simplifies iterating over a collection by applying an action to each element. It reduces boilerplate code for loops, making your code cleaner and more expressive.

Namespace: NetExt.Core.Common

The namespace class provides a utility method to validate nullable values at runtime. This extension is particularly useful for ensuring required parameters are not null, improving code reliability and reducing the need for repetitive null-checking logic.

using NetExt.Core.Collections;

var numbers = new List<int> { 1, 2, 3, 4, 5 };

// Apply an action to each element
numbers.ForEachExt(number => Console.WriteLine(number * 2));
// Output:
// 2
// 4
// 6
// 8
// 10

Namespace: NetExt.Core.Enums

The namespace provides an extension method for enums, allowing seamless conversion of enum values to their underlying integer representation. This simplifies handling enums in scenarios where integer values are required, such as database storage, serialization, or calculations.

Also, contains Sort enum provides a straightforward way to represent sorting directions, commonly used in ordering datasets, database queries, or collections. Its simplicity and clarity make it ideal for scenarios where sorting logic needs to be explicitly defined.

  • ASC: Represents ascending order. Items are sorted from smallest to largest or in lexicographical order (A-Z).
  • DESC: Represents descending order. Items are sorted from largest to smallest or in reverse lexicographical order (Z-A).

Namespace: NetExt.Core.DateTime

The namespace provides a set of extension methods to enhance the functionality of System.DateTime. These methods simplify common operations like Unix time conversions and specifying the DateTimeKind for DateTime objects.

MayBe Struct (Result pattern)

The MayBe<T> struct is a lightweight, readonly wrapper for managing nullable references with enhanced safety and expressiveness. It simplifies handling scenarios where a value may or may not exist, providing built-in methods for validation and error handling.

interface IRepository
{
    Task<MayBe<UserEntity>> GetAsync(int id); 
}
...
MayBe<UserEntity> entity = await IRepository.GetAsync(123);
// check that entity exists or not
if (entity.Exists)
{
    // TBD
}
...
// OR
var entity = (await IRepository.GetAsync(123)).GetOrThrow("Entity");
// OR
var entity = await IRepository.GetAsync(123).GetOrThrow("Entity");
...

// return entity or throw exception
var result = entity.AssumeExists("error message");

Namespace: NetExt.Core.Strings

The namespace class provides a rich set of extension methods for enhancing string manipulation. These methods simplify common string operations such as trimming, checking for null or empty strings, encoding to Base64, and more, making string handling more efficient and expressive.

// use with params or like default
// stringValue.IsNullOrVoidExt(checkWhiteSpace:false, trim: false)
// OR
// stringValue.IsNullOrVoidExt()

var stringValue = "some string here";
if (stringValue.IsNullOrVoidExt(checkWhiteSpace:false, trim: false)) {
    return false;
} else {
    return true;
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 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.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on NetExt.Models:

Package Downloads
NetExt.MayBe

The NetExt.MayBe is a lightweight, readonly wrapper for managing nullable references with enhanced safety and expressiveness. It simplifies handling scenarios where a value may or may not exist, providing built-in methods for validation and error handling.

NetExt.Require

The package provides a lightweight, fluent API for runtime validation of objects and conditions. This library helps ensure that parameters meet expected conditions before execution, reducing boilerplate code for argument validation.

GitHub repositories

This package is not used by any popular GitHub repositories.

v1.0.1: migrate to separate nuget package from NetExt.Core