Acidmanic.Utilities 1.0.21

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

// Install Acidmanic.Utilities as a Cake Tool
#tool nuget:?package=Acidmanic.Utilities&version=1.0.21

Icon

Utilities

This package contains some useful classes that commonly are being used in different project types.

Results

Its a cleaner substitution of tupples where a function needs to return the success/failure status of its operation along side or without the actual result of the operation (in case of success).

It has been implemented in three levels

  • Result: Only represents the success/failure
  • Result<T>: provides the success/failure status and also holds a value of type T which in case of success would be the operation result
    • It's cast-able to both boolean (success/failure) and T
  • Result<TPrimary,TSecondary>: same as Result<T>, but it can carry two different values.

Factory Base

The class FactoryBase<TProduct,TArgument> provides an implementation of Factory Design Pattern. Where TProduct would be the type of what factory would be making. and TArgument is the type of argument passing to Make() method, and factory should decide which the implementation based on this argument.

for example if you have an ICar interface, and you have implementations like MohaveCar, CamaroCar, CameryCar and X3Car. And you want to have a factory that makes a car by it's brand name. So for this case, the TProduct would be ICar and TArgument would be string.

Next step you would extend FactoryBase class and implement it's match methods:

  • implement MatchesByType(Type,TArgument) if your factory would be able to decide only by type and the argument. And it does not need to have the instance to make a decision.
  • implement MatchByInstance(TProduct,TArgument) if your factory needs an instance of the object to be able to decide if it matches the argument or not.

you also would need to satisfy the factoryMatching argument in base class's constructor. This argument determines which of two methods above are you using.

What about my DI?

If your implementations are needed to be created by any kind of DI or IOC, all you have to do is to pass a Func<Type,object> delegate to constructor. this delegate will make the Factory class enable to use your Di resolver to instantiate your implementations.

In the other hand, if you are not using a DI or any alternative for instantiating your implementations, Factory class would still work while your implementations have a non-parametric constructor.

How The Factory Finds My Implementations?

By default, the factory, when instantiated, scans the assembly containing your factory class, (which you derived from FactoryBase<,>) for all implementations of TProduct. If your implementations are in any other assembly, you can just call the method ScanAssembly passing that assembly to it.

What There is no valid implementation for given Argument?

Usually the best practice would be to use a NULL Implementation for such situations. FactoryBase would return null if it does not find any implementation. But you can change this behavior by overriding the method DefaultValue and return your Null Implementation there.

If you have a class derived from TProduct that is actually a NullObject implementation, to Prevent the FactoryBase to use it as a valid implementation, simply just Use NullObject attribute on your implementation.

Naming Conventions

The class NamingConvention allows to parse and convert an string from
one convention into another. For standard conventions, it can automatically detect the source convention. You can also define and use your own conventions by simply providing a new instance of ConventionDescriptor object.

NamingConvention class's methods:

  • Result<ProcessedName> Parse(string name)
    • This method trys to identify the naming convention that the given name is confirming with, by searching across the builtin standard conventions.
    • Returns a successful result of ProcessedName object containing the detected convention's descriptor and segmented values of the name, if be able to find one. otherwise returns a failure result.
  • Render(string[] segments, ConventionDescriptor convention) and Render(ProcessedName processedName)
    • Takes a separated segments of a name and the target convention's descriptor, directly or via a ProcessedName object, and assembles the segments together to create a name confirming with target convention.
  • string Convert(string name, ConventionDescriptor convention)
    • Takes a source name and target convention. Trys to detect the source name's convention and if found one, then will convert given name to target convention.

Standard Builtin Conventions:

You can find predefined standard conventions in ConventionDescriptor.Standard class. it also provides all standard conventions as an array in StandardConventions property.

The following code shows an example use-case for naming convention classes:

var names = new[]
{
    "ahmad-mahmud-kababi", "FAT_SNAKE", "_internalShit",
    "lame_snake", "MrPascal", "stupidCamel"
};

var namingConvention = new NamingConvention();



foreach (var name in names)
{
    var parsed = namingConvention.Parse(name);

    Console.WriteLine("--------------------------");

    if (parsed)
    {
        Console.WriteLine("Parsed " + name + ", Detected: " + parsed.Value.Convention.Name);

        Console.WriteLine("-----------");

        foreach (var convention in ConventionDescriptor.Standard.StandardConventions)
        {
            Console.WriteLine(convention.Name + ": " +
                              namingConvention.Render(parsed.Value.Segments, convention));
        }
    }
}

Compressions

There are two small methods that simply just wrap up System.IO.Compression tools in two extension methods: string.CompressAsync(string,Compression,[CompressionLevel]) and string.DeCompressAsync(string,Compression). The Compress method, takes and string and returns the compressed data as base64 string. And the DeCompress method does exactly the opposite.

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

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Acidmanic.Utilities:

Package Downloads
EnTier

Easy N-Tier Architecture, Working out of the box!(Kind of!!)

Meadow.Framework

Managed and Enhanced ADO Wrapper

EnTier.DataAccess.Meadow

This package adds extensions to use Meadow with EnTier

CoreCommandLine

This library provides an easy setup for a commandline application.

EnTier.EventStore.WebView

Web based event-browser for EnTier event-srouced applications

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.22-b03 0 6/20/2024
1.0.22-b02 370 10/28/2023
1.0.22-b01 63 10/26/2023
1.0.21 412 10/21/2023
1.0.20 140 10/3/2023
1.0.19 113 10/3/2023
1.0.18 454 9/12/2023
1.0.17 106 9/12/2023
1.0.16 137 9/6/2023
1.0.15 78 9/6/2023
1.0.14 104 9/6/2023
1.0.14-internal01 60 9/4/2023
1.0.13 282 8/31/2023
1.0.12 205 8/28/2023
1.0.11 129 8/27/2023
1.0.10 114 8/26/2023
1.0.9 87 8/26/2023
1.0.8 86 8/26/2023
1.0.7 171 8/21/2023
1.0.6 540 3/6/2023
1.0.4 635 2/26/2023
1.0.2 1,508 11/4/2022
1.0.0 5,170 9/5/2022