SharperHacks.CoreLibs.Interfaces 2.0.0

Prefix Reserved
This package has a SemVer 2.0.0 package version: 2.0.0+2026.02.02.JwD.2396e50.
dotnet add package SharperHacks.CoreLibs.Interfaces --version 2.0.0
                    
NuGet\Install-Package SharperHacks.CoreLibs.Interfaces -Version 2.0.0
                    
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="SharperHacks.CoreLibs.Interfaces" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharperHacks.CoreLibs.Interfaces" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SharperHacks.CoreLibs.Interfaces" />
                    
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 SharperHacks.CoreLibs.Interfaces --version 2.0.0
                    
#r "nuget: SharperHacks.CoreLibs.Interfaces, 2.0.0"
                    
#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 SharperHacks.CoreLibs.Interfaces@2.0.0
                    
#: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=SharperHacks.CoreLibs.Interfaces&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SharperHacks.CoreLibs.Interfaces&version=2.0.0
                    
Install as a Cake Tool

SharperHacks logo

Interfaces

SharperHacks.CoreLibs.Interfaces

A collection of useful interfaces, with zero implementation dependancies.

Licensed under the Apache License, Version 2.0. See LICENSE.

Contact: joseph@sharperhacks.org

Nuget: https://www.nuget.org/packages/SharperHacks.CoreLibs.Interfaces

Targets

  • net8.0
  • net9.0
  • net10.0

Interfaces

IDeepCloneable<T>
// A simple interface for deeply cloneable objects.
//
//  @T The type that is deep cloneable.
//
public interface IDeepCloneable<T>
{
    // Perform a deep copy of the @T instance.
    //
    // Returns: A deep copy of the current instance.
    //
    T DeepClone();
}
IGetableState<T>
// A generic get state interface.
//
//  @T The type representing the state.
//
public interface IGetableState<T>
{
    // Get the current state.
    T GetState();
}
IInterval<T>
// Represents a interval in terms of upper and lower bounds and whether
// they are inclusive or exclusive.
//
// @T Any type that implements IComparable{T}.
//
// An interval in this context is not a fixed set of values. It is very 
// important to capture the full semantics of interval specifications
// and behaviors in implementations of this interface.
//
public interface IInterval<T> where T : IComparable<T>
{
    // Get the lower boundary of the interval.
    //
    T LowerBound { get; }

    // Get whether lower boundary is inclusive or exclusive.
    //
    IntervalBoundaryType LowerBoundaryType { get; }

    // Get whether the lower boundary is inclusive.
    //
    bool IsInclusiveLowerBound => LowerBoundaryType == IntervalBoundaryType.Inclusive;

    // Get whether the lower boundary is exclusive.
    //
    bool IsExclusiveLowerBound => LowerBoundaryType == IntervalBoundaryType.Exclusive;

    // Get the upper boundary of the interval.
    //
    T UpperBound { get; }

    // Get whether the upper boundary is inclusive or exclusive.
    //
    IntervalBoundaryType UpperBoundaryType { get; }

    // Get whether the upper boundary is inclusive.
    //
    bool IsInclusiveUpperBound => UpperBoundaryType == IntervalBoundaryType.Inclusive;

    // Get whether the upper boundary is exclusive.
    //
    bool IsExclusiveUpperBound => UpperBoundaryType == IntervalBoundaryType.Exclusive;

    // Get whether the defined interval is empty.
    //
    // Default implementation not adequate for all types of T.
    //
    bool IsEmpty => (LowerBound is null && UpperBound is null)
            || ((LowerBound is null || IsExclusiveLowerBound)
                && (UpperBound is null || IsExclusiveUpperBound))
            || ((IsExclusiveLowerBound || IsExclusiveUpperBound)
                && Equals(LowerBound, UpperBound));

    // Determine whether value falls within specified interval.
    //
    // Parameters:
    //  @value
    //   The value to test against the interval.
    //
    // Returns: True if value is within the specified interval.
    //
    public bool Contains(T value)
    {
        // 
        var lowerBoundComparison = value.CompareTo(LowerBound);
        var upperBoundComparison = value.CompareTo(UpperBound);

        var aboveLowerBound = IsInclusiveLowerBound ? lowerBoundComparison >= 0 : lowerBoundComparison >= 1;
        var belowUpperBound = IsInclusiveUpperBound ? upperBoundComparison <= 0 : upperBoundComparison <= -1;

        return aboveLowerBound && belowUpperBound;
    }
}
IInvokable<TResult>
// Defines the Invoke() interface with a generic return type.
//
// @TResult The result type return by @Invoke()
//
public interface IInvokable<TResult>
{
    // Invoke any encapsulated function or process with a generic return type.
    //
    // Return: @TResult
    //
    TResult Invoke();
}
IInvokable<TResult>
// Defines the Invoke() interface with a generic return type.
//
// @TResult The result type return by @Invoke()
//
public interface IInvokable<TResult>
{
    // Invoke any encapsulated function or process with a generic return type.
    //
    // Return: @TResult
    //
    TResult Invoke();
}
IKvp<TKey>
// A KVP interface, w/fixed key type and polymorphic value type.
//
// @TKey The type used as the key/label.
//
public interface IKvp<TKey> where TKey : IComparable, IComparable<TKey>, IEquatable<TKey>
{
    // The key.
    //
    // Keys SHOULD be immutable.
    //
    TKey Key { get; }

    // Whether the value is immutable.
    bool IsImmutable { get; }

    // The value object.
    object? Value { get; }

    // Return a deep clone of the underlying instance.
    //
    // Returns: IKvp<TKey>
    //
    IKvp<TKey> Clone();

    // Get the value as type TValue.
    //
    // Returns @TValue.
    //
    // Exceptions:
    //  See https://learn.microsoft.com/en-us/dotnet/api/system.convert.changetype?view=net-9.0/>
    //
    TValue? GetValue<TValue>() where TValue : IComparable, IComparable<TValue>, IEquatable<TValue>;

    // Set Value.
    //
    // Parameters:
    //  @value The value to set.
    //
    void SetValue<TValue>(TValue? value) where TValue : IComparable, IComparable<TValue>, IEquatable<TValue>;
}
IntervalBoundaryType

// Enumeration representing whether an interval boundary is inclusive/exclusive. //

public enum IntervalBoundaryType
{
    // Range boundary is inclusive.
    //
    Inclusive,

    // Range boundary is exclusive.
    //
    Exclusive
}
IPoint<T>
// A generic point interface.
//
// @TNumeric The numeric type used to specify locations.
//
public interface IPoint<TNumeric> where TNumeric : INumber<TNumeric>
{
    // Get the dimensionality associated with this point.
    //
    // Must be a non-zero positive value.
    //
    int Dimensions { get; }

    // Get a list of points on each axis.
    //
    ImmutableList<TNumeric> Coordinates { get; }

    // Get the component at the specified index.
    //
    // Parameters:
    //  @index
    //
    // Returns The component value at that index.
    //
    TNumeric this[int index] => Coordinates[index];
}
IPolygon<T>
// A generic polygon interface.
//
// @T The numeric type used to specify locations.
//
public interface IPolygon<T> where T : INumber<T>
{
    // Get the number of vertices, defining the polygon.
    //
    public int VertexCount { get; }

    // Get the list of IPoint{T}'s that specify vertex positions.
    //
    public ImmutableList<IPoint<T>> Vertices { get; }
}
IProgEnumerable<T>
// An interface for enumerable psuedo-random object generators (PROG's).
//
// Typeparam: T the type resulting from enumeration.
//
// Remarks:
//  Beware of LINQ's Count() and LongCount() extensions to IEnumerable.
//  Not all IEnumerable's have a fixed size, nor are they all countable.
//

public interface IProgEnumerable<T> : IEnumerable<T>, IProgSeed { }
IProgNextArray<T>
// Generic interface for psuedo-random object generators (PROG's) that implement
// a NextArray method returning T[].
//
// Typeparams: T Return type of the NextArray() method.
//
public interface IProgNextArray<T> : IProgSeed
{
    // Returns the next [length] sized array of random values of T.
    //
    // Params:
    //  [length]
    //
    public T[] NextArray(long length);

    // Fills [buffer] with random values of T.
    //
    // Params:
    //  [buffer]
    // 
    // Returns: [buffer]
    //
    public T[] NextArray(T[] buffer);
}
IProgNextInInterval<T>

Generic interface for PROG's that implement NextInInterval method.

T NextInInterval(IInterval<T> interval);
IProgNextInRange<T>

Generic interface for PROG's that implement NextInRange method.

T NextInRange(T min, T max);
IProgNextSpan<T>

Generic interface for PROG's that implement NextSpan methods.

 // Create a span of the specified size and fill it with random values.
 Span<T> NextSpan(int length);

 // Fill the specified buffer with random values and return it.
 Span<T> NextSpan(Span<T> buffer);
IProgNextValue<T>

Generic interface for PROG's that implement NextValue method.

T NextValue();
IProgSeed

Declares object Seed, used by the rest of the IProg* interfaces.

PRG's, must generally be initialized with a seed value. In many applications, it is important that each seed should be random, but there is often a requirement that playback, for diagnostic or other purposes must be possible. To solve this problem, most PRNG's allow for seeds to be injected by the caller, at initialization. This can lead to less than desirable results, when non-experts contrive their own naive sources of randomness.

The seed values used, should have characteristics that are at least as strong as the PRG. The consumers of such generators, should not be asked to generate seeds, so the need arises for the generators to expose their initial seed and other critical values, such as coefficients, etc, for testing and diagnostic purposes.

This interface provides an extreme level of abstraction over the above concepts, allowing the PRG to expose it's own, implementation specific, random and non-random initial state.

 // The seed used to initialize psuedo-random object generators (PROG's).
 object Seed { get; }
IProgState

A generic interface to access internal state of PROG's.

object State { get; }
IResultAccumulator

A result accumulator interface.

IResult<T>

A generic result type interface.

IResultStatus

generic result + status type interface.

IRunable

A Run() interface.

ISettableState<T>

A generic settable state interface.

IState<T>

A generic state interface.

IToJsonString

Defines a ToJsonString() interface.

IToJsonUtf8Bytes

Defines a ToJsonUtf8Bytes() interface.

IToJsonUtf8ByteSpan

Defines a ToJsonUtf8ByteSpan() interface.

IToJson

Combines IToJsonString, IToJsonUtf8Bytes and IToJsonUtf8ByteSpan in one interface.

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.  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 is compatible.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on SharperHacks.CoreLibs.Interfaces:

Package Downloads
SharperHacks.CoreLibs.CommandLineInterface

Command line parser.

SharperHacks.CoreLibs.Math

Package Description

SharperHacks.CoreLibs.InterfaceImplementations-ResultAccumulator

A collection SharperHacks.CoreLibs.Interfaces implementation projects.

SharperHacks.CoreLibs.DelegateContainers

System.Action wrappers.

SharperHacks.CoreLibs.InterfaceImplementations-InterfaceStatus

A collection SharperHacks.CoreLibs.Interfaces implementation projects.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 66 2/2/2026
1.3.1 35 1/27/2026
1.3.0 107 11/10/2025
1.2.0 62 10/17/2025
1.1.0 82 10/12/2025
1.0.0 100 7/18/2025
0.13.0 65 7/12/2025
0.12.0 116 4/18/2025
0.11.0 91 4/18/2025
0.10.0 115 3/26/2025
0.9.0 95 3/25/2025
0.8.0 85 3/25/2025
0.7.0 76 3/25/2025
0.6.0 94 3/25/2025
0.5.0 86 3/24/2025
0.4.0 131 12/20/2024
0.3.0 143 9/1/2024
0.2.0 96 9/1/2024
0.1.0 95 8/30/2024