Altemiq 1.4.0
See the version list below for details.
dotnet add package Altemiq --version 1.4.0
NuGet\Install-Package Altemiq -Version 1.4.0
<PackageReference Include="Altemiq" Version="1.4.0" />
<PackageVersion Include="Altemiq" Version="1.4.0" />
<PackageReference Include="Altemiq" />
paket add Altemiq --version 1.4.0
#r "nuget: Altemiq, 1.4.0"
#:package Altemiq@1.4.0
#addin nuget:?package=Altemiq&version=1.4.0
#tool nuget:?package=Altemiq&version=1.4.0
Altemiq Core Library
This is the code library for base classes, extension methods, etc.
This contains code for LINQ extensions, as well as base string parsing, and options types.
OneOf
Provides F# style unions for C#, using a custom type OneOf<T0, ... Tn>
.
An instance of this type holds a single value, which is one of the types in its generic argument list.
Creation
These can be created using the From
methods, on the static OneOf
class.
var oneOf = OneOf.From<int, string>(1);
var result = oneOf.AsT0;
You can also use the implicit operators.
OneOf<int, string> oneOf = "1";
var result = oneOf.AsT1;
Use Cases
As a method return
This is used to return different values from a method.
public OneOf<User, InvalidName, NameTaken> CreateUser(string username)
{
if (!IsValid(username))
{
return new InvalidName();
}
var user = this.repo.FindByUsername(username);
if (user is not null)
{
return new NameTaken();
}
var user = new User(username);
this.repo.Save(user);
return user;
}
As an 'Option' Type
This is used to pass in different values to a method, just declare a OneOf<Something, None>
.
As a method parameter value
You can use also use OneOf
as a parameter type, without additional overloads. Having multiple parameters, the number of overloads required increases rapidly.
As a property/variable
You can use OneOf
when a value is constrained to certain types, rather than using object
.
Matching/Switching
You use the TOut Match(Func<T0, TOut> f0, ... Func<Tn,TOut> fn)
method to get a value out, with the number of handles matching the number of generic arguments.
For example:
OneOf<string, ColorName, Color> backgroundColor = ...;
var color = backgroundColor.Match(
str => CssHelper.GetColorFromString(str),
name => new Color(name),
col => col,
);
this.window.BackgroundColor = color;
There is also a .Switch
method, for when you aren't returning a value:
OneOf<string, DateTime> dateValue = ...;
dateValue.Switch(
str => AddEntry(DateTime.Parse(str), foo),
dateTime => AddEntry(dateTime, foo),
);
Splitting Spans
With string
, there are methods to split the string into an array, based on separators.
This library allows the same for ReadOnlySpan<char>
values.
For example:
ReadOnlySpan<char> span = ...;
var enumerator = span.Split(',');
var firstValueAsString = span.GetNextString(ref enumerator);
var secondValueAsInt32 = span.GetNextInt32(ref enumerator);
while (enumerator.MoveNext())
{
yield return span[enumerator.Current];
}
String Extensions
This contains extensions to help with quoted strings, such as data coming from CSV files.
Reading quoted strings
var value = """"
1,2,"This is a quoted string
With a newline in it and ""embedded quotes""",4,5
"""";
value.SplitQuoted(',');
Writing quoted strings
This can allow for embedded delimiters, quotes, new-lines, and also non 7-bit ASCII characters.
This will also quote an empty string as ""
to distinguish it from a null
string which will be empty.
// will be quoted
"value,\rsecond".Quote(',', StringQuoteOptions.QuoteAll);
// quotes not necessary
"value".Quote(',', StringQuoteOptions.QuoteAll);
// this will always be quoted
"".Quote(',');
// this will never be quoted
((string)null).Quote(',');
LINQ methods
IndexOfClosest
This contains extensions to get the closest value in a list, based on how close a value is.
For example:
IReadOnlyList<double> list = new[] { 1D, 5D, 10D, 15D, 20D };
# this will return 1
list.IndexOfClosest(7D);
QuickSort
This performs a quick sort of a list with an IComparable
implementation or a Comparison
.
var first = new SimpleStruct(0, 0D);
var second = new SimpleStruct(1, 1D);
var third = new SimpleStruct(2, 2D);
var forth = new SimpleStruct(3, 3D);
var list = new List<SimpleStruct>
{
third,
forth,
second,
first
};
list.QuickSort();
Streams
EchoStream
This class echos the data written in to be able to be read. This can be useful for reading data that only writes to a stream.
var stream = new EchoStream();
Task.Run(() =>
{
stream.Write(/* data to write */);
});
Task.Run(() =>
{
stream.Read(/* data read */);
});
MultipleStream
This class have multiple backing streams, represented as a single stream. This can be useful to attempt to allow writing to streams in a backward sense when we can only seek forwards.
This is highlighted by data formats that have a header than contains information about the data in the file, such as the number of records. Generally these are written at the end of the process, once the number of records is known. For forwards only streams, this is not possible.
var stream = new MultipleStream();
stream.SwitchTo("header");
// write uninitialized header.
stream.SwitchTo("data");
// write data
stream.SwitchTo("header");
// write updated header
stream.CopyTo(/* output stream */);
MultipleMemoryStream
Implementation of MultipleStream
backed by MemoryStream
instances.
SeekableStream
This class allows forwards only seeking through a stream that does not allow seeking. This is done by reading the data until the required position is reached.
var stream = new SeekableStream(/* stream that is not seekable */);
// seek should not throw
stream.Seek(123);
Bit Manipulation
BitConverter
Replica of System.BitConverter
with all types allowed for, and the ability to specify the byte ordering.
BinaryPrimitives
Replica of System.Buffers.Binary.BinaryPrimitives
with all types allow for.
NanoId
Implementation of nanoid.
Security
Random
Implementation of System.Random
using System.Security.Cryptography.RandomNumberGenerator
as the generator.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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. 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 | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 is compatible. netstandard1.2 was computed. netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 is compatible. 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 | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- System.Memory (>= 4.5.0)
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
- System.Text.RegularExpressions (>= 4.3.1)
- System.ValueTuple (>= 4.3.0)
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
- System.Memory (>= 4.5.0)
- System.Net.Http (>= 4.3.4)
- System.Text.RegularExpressions (>= 4.3.1)
- System.ValueTuple (>= 4.3.0)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- System.Memory (>= 4.5.0)
- System.Net.Http (>= 4.3.4)
- System.Reflection.TypeExtensions (>= 4.1.0)
- System.Text.RegularExpressions (>= 4.3.1)
- System.ValueTuple (>= 4.3.0)
-
.NETStandard 2.0
- System.Memory (>= 4.5.0)
- System.Net.Http (>= 4.3.4)
-
.NETStandard 2.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Altemiq:
Package | Downloads |
---|---|
Altemiq.IO.Compression
Provides classes that extend the compression and decompression of streams. |
GitHub repositories
This package is not used by any popular GitHub repositories.