JJ.Framework.Common 0.250.2313

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package JJ.Framework.Common --version 0.250.2313
                    
NuGet\Install-Package JJ.Framework.Common -Version 0.250.2313
                    
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="JJ.Framework.Common" Version="0.250.2313" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JJ.Framework.Common" Version="0.250.2313" />
                    
Directory.Packages.props
<PackageReference Include="JJ.Framework.Common" />
                    
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 JJ.Framework.Common --version 0.250.2313
                    
#r "nuget: JJ.Framework.Common, 0.250.2313"
                    
#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 JJ.Framework.Common@0.250.2313
                    
#: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=JJ.Framework.Common&version=0.250.2313
                    
Install as a Cake Addin
#tool nuget:?package=JJ.Framework.Common&version=0.250.2313
                    
Install as a Cake Tool

JJ.Framework.Common

A mixed bag of general-purpose utilities with minimal dependencies. Later versions of this library split functionality into focused packages like JJ.Framework.Text, JJ.Framework.Collections, and JJ.Framework.Exceptions. This "prequel" version contains a little bit of everything: a version released in aid of releasing older legacy apps, still holding value. Now targets .NET 9 and .NET Standard for wide compatibility and tested with 💯% code coverage.

Contents

String Extensions

  • Left / Right

    • Return the left or right part of a string:
    • "12345".Left(2) = "12"
    • "12345".Right(2) = "45"
    • (Throws exception if string shorter than requested length.)

  • FromTill

    • Take the middle of a string by start/end index (zero‑based, inclusive)
    • "12345".FromTill(2, 3) = "34"
    • (Throws exception if indexes out of range.)

  • CutLeft / CutRight

    • Trim at most one occurrence of a value from the given string:
    • "BlaLala".CutLeft("Bla") = "Lala"
    • "12345".CutRight(2) = "123"

  • CutLeftUntil / CutRightUntil

    • Remove text until the delimiter, keeping the delimiter:
    • "Path/to/file.txt".CutRightUntil("/") = "Path/to/"
    • "Hello world!".CutLeftUntil("world") = "world!"

  • StartWithCap / StartWithLowerCase

    • Change just the first character's case:
    • "test".StartWithCap() = "Test"
    • "TEST".StartWithLowerCase() = "tEST"

  • Split

    • Adds overloads missing until .NET 5 and a params variant for delimiters:
    • "apple-banana|cherry".Split("-", "|") = [ "apple", "banana", "cherry" ]

  • SplitWithQuotation

    • Parse CSV-like lines honoring quotes to allow use of separator and quote characters within the values themselves:
    • "apple|~banana|split~|cherry".SplitWithQuotation("|", '~') = [ "apple", "banana|split", "cherry" ]

  • RemoveExcessiveWhiteSpace

    • Trim and replace sequences of two or more white space characters by a single space:
    • " This is a test. ".RemoveExcessiveWhiteSpace() = "This is a test."

  • Replace

    • String.Replace variant with optional case-insensitive match:
    • "HelloWORLD".Replace("world", "Universe", ignoreCase: true ) = "HelloUniverse"

Collection Extensions

  • Distinct

    • Variation that takes a key selector that determines what makes an item unique, e.g.
    • myItems.Distinct(x => x.LastName);
    • For multi-part as keys, use:
    • myItems.Distinct(x => new { x.FirstName, x.LastName });

  • Except

    • Variations with:
    • A single item, e.g. myCollection.Except(myItem);
    • The choice to keep duplicates. (The original Except method from .NET automatically does a distinct, which is something you do not always want.)

  • Union

    • Variations with:
    • A single item, e.g. myCollection.Union(myItem);
    • Starts with a single item and then adds a collection to it e.g. myItem.Union(myCollection);

  • Add

    • Add multiple items to a collection by means of a comma separated argument list, e.g. myCollection.Add(1, 5, 12);

  • AddRange

    • AddRange is a member of List<T>. Here is a variation for IList<T> to support more collection types.

  • ForEach

    • Not all collection types have the ForEach method. Here you have an overload for IEnumerable<T> so you can use it for more collection types.

  • AsEnumerable
    • Converts a single item to a enumerable, so you can for instance use it with LINQ:
    • IEnumerable<int> myInts = 3.AsEnumerable();

  • TrimAll

    • Trims all the strings in the collection:
    • string[] trimmedTexts = myTexts.TrimAll()

Recursive Collection Extensions

LINQ methods already allow you to process a whole collection of items in one blow. Process a whole tree of items in one blow? For many cases these Recursive Collection Extensions offer a one-line solution.

This line of code:

var allItems = myRootItems.UnionRecursive(x => x.Children);

Gives you a list of all the nodes in a tree structure like the following:

var root = new Item
{
    Children = new[]
    {
        new Item()
        new Item
        {
            Children = new[]
            {
                new Item()
            }
        },
        new Item
        {
            Children = new[]
            {
                new Item(),
                new Item(),
            }
        },
    }
};

There is also a SelectRecursive method:

var allItemsExceptRoots = myRootItems.SelectRecursive(x => x.Children);

The difference with UnionRecursive is that SelectRecursive does not include the roots in the result collection.

KeyValuePairHelper

Converts a single array to KeyValuePair or Dictionary, where the 1st item is a name, the 2nd a value, the 3rd a name, the 4th a value, etc. This can be useful to be able to specify name/value pairs as params (variable amount of arguments). For instance:

void MyMethod(params object[] namesAndValues)
{
    var dictionary = KeyValuePairHelper.ConvertNamesAndValuesListToDictionary(namesAndValues);
    ...
}

Calling MyMethod looks like this:

MyMethod("Name1", 3, "Name2", 5, "Name3", 6);

Exception Types

2 exception types with subtle differences:

  • InvalidValueException

    • With messages like:
      Invalid CustomerType value: 'Undefined'.
      when you throw:
      throw new InvalidValueException(CustomerType.Undefined)

  • ValueNotSupportedException

    • With messages like:
      CustomerType value: 'Subscriber' is not supported.
      when you throw:
      throw new ValueNotSupportedException(CustomerType.Subscriber)

Misc Helpers

  • EmbeddedResourceHelper

    • Make it a little easier to get embedded resource Streams, bytes and strings.

  • CultureHelper

    • To set thread culture with a single code line.

  • ConfigurationHelper

    • Legacy helper for using configuration settings on platforms where System.Configuration was not available.

  • KeyHelper

    • Utility to produce keys for use in Dictionaries by concatenating values with a GUID separator in between.

💬 Feedback

Found an issue? Let me know.

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 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.  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. 
.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.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on JJ.Framework.Common:

Package Downloads
JJ.Framework.Reflection

Expressions like "myParam.MyList[i].MyProperty" can be converted to text or their value retrieved or info like { "MyMethod", Parameters = { "myParameter", int, 3 } } Accessor IsIndexer IsNullableType IsProperty IsReferenceType IsStatic IsSimpleType IsDefault GetBaseClasses GetImplementations GetItemType GetPropertyOrException GetUnderlyingNullableTypeFast TypesFromObjects. ReflectionCache with fast GetProperties GetFields GetConstructor GetTypeByShortName. Overloads for PropertInfo.GetValue IsAssignableFrom IsAssignableTo CreateInstance.

JJ.Framework.Conversion

Makes it easier to convert simple types.

JJ.Framework.Collections

LINQ overloads. SelectRecursive SelectAncestors Add Remove AddRange Concat CrossJoin Distinct DistinctMany Except FirstWithClearException SingleOrDefaultWithClearException SingleWithClearException ForEach IndexOf TryGetIndexOf MinOrDefault MaxOrDefault PeekOrDefault PopOrDefault Product RemoveFirst Repeat ToHashSet ToNonUniqueDictionary TrimAll TryRemoveFirst Union Zip item.AsArray item.AsList item.AsEnumerable. Also a RedBlackTree and KeyValuePairHelper ConvertNamesAndValuesListToKeyValuePairs and ConvertNamesAndValuesListToDictionary.

JJ.Framework.Mathematics

Interpolator Smooth Bezier Cubic Hermite TextPlotter NumberBases ToBase FromBase ToHex FromHex ToLetterSequence FromLetterSequence Randomizer GetRandomItem GetInt32 GetDouble GetSingle IsInRectangle GetCenter AbsoluteDistance IsPowerOf2 LogRatio RoundToSignificantDigits RoundWithStep ScaleLinearly SpeadItems SpreadIntegers SpreadDoubles. Integer variation of Pow and Log.

JJ.Framework.Configuration

Allows you to work with complex configuration structures in your app.config or web.config files. Doing it the classic way with System.Configuration is difficult and error prone. JJ.Framework.Configuration makes it super easy.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.5.6877.41321 3,173 10/31/2018
1.4.6862.40439 36,358 10/15/2018
1.3.6681.33418 8,541 4/17/2018
1.2.6640.39171 7,157 3/7/2018
1.1.0.31223 7,702 3/4/2018
1.0.6636.31308 1,366 3/3/2018
1.0.6633.34564 1,348 2/28/2018
1.0.6633.33247 13,037 2/28/2018
0.250.3184 272 6/24/2025
0.250.3081 288 6/14/2025
0.250.3080 370 6/14/2025
0.250.2324 255 4/27/2025
0.250.2323 255 4/27/2025
0.250.2322 253 4/27/2025
0.250.2313 288 4/27/2025
0.250.2207 344 4/22/2025
0.250.2204 239 4/22/2025
0.250.2175 227 4/21/2025
0.250.2174 193 4/21/2025
0.250.2171 313 4/21/2025
0.250.2122 205 4/19/2025
0.250.2120 210 4/19/2025
0.250.2115 239 4/19/2025
0.250.2093 251 4/17/2025