Semantica.Lib.Core
8.1.0
dotnet add package Semantica.Lib.Core --version 8.1.0
NuGet\Install-Package Semantica.Lib.Core -Version 8.1.0
<PackageReference Include="Semantica.Lib.Core" Version="8.1.0" />
<PackageVersion Include="Semantica.Lib.Core" Version="8.1.0" />
<PackageReference Include="Semantica.Lib.Core" />
paket add Semantica.Lib.Core --version 8.1.0
#r "nuget: Semantica.Lib.Core, 8.1.0"
#:package Semantica.Lib.Core@8.1.0
#addin nuget:?package=Semantica.Lib.Core&version=8.1.0
#tool nuget:?package=Semantica.Lib.Core&version=8.1.0
Semantica.Lib.Core
This package is part of the core packages of Semantica.Lib.
Summary
Contains many basic helpers and base classes, useful in most C#.NET Framework projects. Including an injectable
DateTimeProvider
, base classes for compact type converters and json converters, and a generic dependency
injection module base class to streamline splitting your registrations per module.
Contents
Statics
Comparable
A collection of methods for types that implement IComparable<T>
, or to aide in the implementation of Compare
methods of
a IComparable<T>
or IComparer<T>
implementation.
DateTimeConstant
Exposes many constants that exists only as privates on the native DateTime
, like the amount of ticks for certain units of
time, the amount of days in each month, etc. Also provides a few basic methods for date calculations.
Logic
Provides a number of methods that implement logical operators on a variable number of (boolean) parameters.
StaticSelectors
A few simple selector functions used elsewhere in the library.
Base classes
StringTypeConverterBase
A base class used to streamline making TypeConverter classes for simple value types that map to a single string-based value. Having a TypeConverter for your value type means that you can use that type in AspMvc route or querystring parameters.
Semantica.Lib.Types.Converter.TypeConverterRegistration can be used to add the TypeConverterAttribute to a type programmatically, which removes the necessity to have the TypeConverter in the same project as the type, and allows for adding TypeConverters for external types.
DependencyInjection.ModuleBase<T>
A base class for defining dependency injection module classes in your projects. An implementation of this module can define the
assemblies and/or modules it's dependent on, and the registrations that the implementations that the code module provides. The
container type is the generic parameter for the base class, making it possible to use it with any DI-container package that
supports code-based registrations, as well as the standard IServiceCollection
.
DependencyInjection.ServiceCollectionExtensions
An extension method for IServiceCollection, typically used in a Program.cs, that adds all registrations of an implemetation of
ModuleBase<IServiceCollection>
, as well as those in all of the modules it depends on.
Json.JsonConverterBase
Contains a number of nested abstract classes used to streamline making JsonConverter classes for simple value types that map to a single json value. There is a generic base class, as well as a specific base class for each value type System.Text.Json supports reading/writing.
Json.StringConverterBase
A base class to streamline making JsonConverter classes for value types that are representable as a string value.is a generic base class, as well as a specific base class for each value type System.Text.Json supports reading/writing.
Injectables
Providers.IDateTimeProvider
Provides a number of methods that are usually called as static methods on DateTime
, DateTimeOffset
or DateOnly
,
such as Now()
, Today()
, etc. Using an injected interface for this rather than the static methods makes it possible to
make much better unit tests.
Providers.DateTimeProvider
A default implementation of IDateTimeProvider
. Implementations depend on each other as much as possible, making it possible
to make a custom implementation that used this as a base class, and by only overriding the TimeZoneInfo method all other methods
will use a different timezone than the default System.TimeZoneInfo.Local
, or override UtcNow()
to make all methods use a
different (remote) time.
Core.Module can be used to register the implementation with theIServiceCollection
.
Semantica.Lib.TestTools.Core package contains an implementation that can be set to a datetime value on instantiation, for
unittesting purposes.
Providers.ISnapshotDateTimeProvider
Inherits from IDateTimeProvider
, and adds a single reset-method.
Providers.SnapshotDateTimeProvider
Provides the same functionality as DateTimeProvider
, but will remember the time that a method that uses the
current time is first called. All subsequent calls will use that remembered time when calculating their output, until the Reset
method is called. This can be used to make sure all methods requiring the current time use the exact same value without needing
to pass that value around between them.
Core.Module can be used to register the implementation with theIServiceCollection
as a Scoped registration.
Documentation generated from the XMLDoc:
<a name='assembly'></a>
Lib.Core
Contents
- Base`2
- Boolean`1
- Byte`1
- Comparable
- DateOnly`1
- DateTimeConstants
- DaysPer100Years
- DaysPer400Years
- DaysPer4Years
- DaysPerYear
- DaysToMonth365
- DaysToMonth366
- MillisPerDay
- MillisPerHour
- MillisPerMinute
- MillisPerSecond
- TicksPerDay
- TicksPerHour
- TicksPerMillisecond
- TicksPerMinute
- TicksPerSecond
- DaysInMonth365
- DaysInMonth366
- GetDaysInMonth()
- GetDaysInMonth()
- GetDaysInMonth()
- MonthNumberAfter(month)
- MonthNumberBefore(month)
- DateTimeOffset`1
- DateTime`1
- Decimal`1
- Double`1
- FuncComparer`2
- Guid`1
- IDateTimeProvider
- ISnapshotDateTimeProvider
- Int16`1
- Int32`1
- Int64`1
- JsonConverterBase
- Logic
- Module
- ModuleBase`1
- ModuleException
- SByte`1
- Single`1
- StaticSelectors
- StringJsonConverterBase`1
- StringTypeConverterBase`1
- UInt16`1
- UInt32`1
- UInt64`1
<a name='T-Semantica-Core-Json-JsonConverterBase-Base`2'></a>
Base`2 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Don't use this base class, but use one of the specific type base classes.
<a name='M-Semantica-Core-Json-JsonConverterBase-Base2-FromUnderlyingType-
1-'></a>
FromUnderlyingType(underlyingValue) method
Summary
Implementation of the conversion to T
.
Returns
An instance of T
.
Parameters
Name | Type | Description |
---|---|---|
underlyingValue | `1 | Value to convert. |
<a name='M-Semantica-Core-Json-JsonConverterBase-Base`2-GetDefault'></a>
GetDefault() method
Summary
Returns default(T?) (null
). Override if a different value to should be returned when reading of
the underlying type value fails.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-Json-JsonConverterBase-Base2-ToUnderlyingType-
0-'></a>
ToUnderlyingType(value) method
Summary
Implementation of the conversion of T
to the underlying type.
Returns
A representation of the input as Nullable`1 of the underlying type.
Parameters
Name | Type | Description |
---|---|---|
value | `0 | Value of T to convert. |
<a name='T-Semantica-Core-Json-JsonConverterBase-Boolean`1'></a>
Boolean`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Boolean.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to boolean. |
<a name='T-Semantica-Core-Json-JsonConverterBase-Byte`1'></a>
Byte`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Byte.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to byte. |
<a name='T-Semantica-Core-Comparable'></a>
Comparable type
Namespace
Semantica.Core
Summary
Provides a number of static methods used for comparison of instances of types implementing IComparable`1.
<a name='M-Semantica-Core-Comparable-CompareOrNull1-
0,``0-'></a>
CompareOrNull``1(this,other) method
Summary
Used to easily chain comparisons in a CompareTo implementation where there are multiple
IComparable`1 properties used for comparison, utilizing the ??
operator.
Returns
default(int?)
if both arguments are compared as equal, otherwise the result of the evaluation of
CompareTo .
Parameters
Name | Type | Description |
---|---|---|
this | ``0 | A IComparable`1 instance. (typically the property of this ). |
other | ``0 | A IComparable`1 instance. (typically the property of other ). |
Example
class MyClass: IComparable{MyClass} {
double A;
double B;
int Compare(MyClass other) {
return Comparable.CompareOrNull(A, other.A) ?? B.CompareTo(other.B);
}
}
<a name='M-Semantica-Core-Comparable-Max1-
0[]-'></a>
Max``1(array) method
Summary
Compares all arguments and returns the one that comes after all the others.
Returns
The maximal instance: the one that becomes after all the others if they would be ordered.
Parameters
Name | Type | Description |
---|---|---|
array | ``0[] | Any number of instances to evaluate. |
Generic Types
Name | Description |
---|---|
T | Any type implementing IComparable`1. |
Remarks
If multiple instances could be ordered last, the first one that was encountered would be returned.
<a name='M-Semantica-Core-Comparable-Max1-
0,``0-'></a>
Max``1(left,right) method
Summary
Compares both arguments and returns the one that comes after the other.
Returns
The maximal instance: the one that becomes after the other if they would be ordered.
Parameters
Name | Type | Description |
---|---|---|
left | ``0 | First instance to evaluate. |
right | ``0 | Second instance to evaluate. |
Generic Types
Name | Description |
---|---|
T | Any type implementing IComparable`1. |
Remarks
If the instances are ordered equal, left
is returned.
<a name='M-Semantica-Core-Comparable-Min1-
0[]-'></a>
Min``1(array) method
Summary
Compares all arguments and returns the one that comes before all the others.
Returns
The minimal instance: the one that becomes before all the others if they would be ordered.
Parameters
Name | Type | Description |
---|---|---|
array | ``0[] | Any number of instances to evaluate. |
Generic Types
Name | Description |
---|---|
T | Any type implementing IComparable`1. |
Remarks
If multiple instances could be ordered first, the first one that was encountered would be returned.
<a name='M-Semantica-Core-Comparable-Min1-
0,``0-'></a>
Min``1(left,right) method
Summary
Compares both arguments and returns the one that comes before the other.
Returns
The minimal instance: the one that becomes before the other if they would be ordered.
Parameters
Name | Type | Description |
---|---|---|
left | ``0 | First instance to evaluate. |
right | ``0 | Second instance to evaluate. |
Generic Types
Name | Description |
---|---|
T | Any type implementing IComparable`1. |
Remarks
If the instances are ordered equal, left
is returned.
<a name='M-Semantica-Core-Comparable-TryCompareHasValue-System-Boolean,System-Boolean,System-Int32@,System-Boolean-'></a>
TryCompareHasValue(thisHasValue,otherHasValue,val,noValueIsBigger) method
Summary
Used to implement comparisons in a CompareTo implementation where the properties used for comparison do not always have values.
Returns
true
if the comparison can be made on the basis of HasValue alone.
false
if both arguments have values, and the comparison has to be made on the actual values.
Parameters
Name | Type | Description |
---|---|---|
thisHasValue | System.Boolean | bool indicating whether the left argument has a value (typically the value of this ). |
otherHasValue | System.Boolean | bool indicating whether the right argument has a value (typically the value of other). |
val | System.Int32@ | Out parameter containing the comparison result. |
noValueIsBigger | System.Boolean | When true , a value is always considered smaller than no value. Default false . |
Example
class MyClass: IComparable{MyClass} {
double? A;
int Compare(MyClass other) {
return Comparable.TryCompareValue(A.HasValue, other.A.HasValue, out int val) ? val : A.Value.CompareTo(other.A.Value);
}
}
<a name='M-Semantica-Core-Comparable-TryCompareIsEmpty-System-Boolean,System-Boolean,System-Int32@,System-Boolean-'></a>
TryCompareIsEmpty(thisIsEmpty,otherIsEmpty,val,emptyIsSmaller) method
Summary
Used to implement comparisons in a CompareTo implementation where the properties used for comparison can be empty.
Returns
true
if the comparison can be made on the basis of empty/not empty alone.
false
if both have values, and the comparison has to be made on the actual values.
Parameters
Name | Type | Description |
---|---|---|
thisIsEmpty | System.Boolean | bool indicating whether the left argument is empty (typically the value of this ). |
otherIsEmpty | System.Boolean | bool indicating whether the right argument is empty (typically the value of other). |
val | System.Int32@ | Out parameter containing the comparison result. |
emptyIsSmaller | System.Boolean | When false , an empty value is always considered larger than no value. Default true . |
Example
class MyClass: IComparable{MyClass} {
string A;
int Compare(MyClass other) {
return Comparable.TryCompareValue(string.IsNullOrEmpty(A), string.IsNullOrEmpty(other.A), out int val) ? val : A.CompareTo(other.A);
}
}
<a name='T-Semantica-Core-Json-JsonConverterBase-DateOnly`1'></a>
DateOnly`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a DateOnly.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to dateonly. |
Remarks
DateOnly is currently not supported by System.Text.Json, so an extra conversion to and from DateTime is used.
<a name='T-Semantica-Core-DateTimeConstants'></a>
DateTimeConstants type
Namespace
Semantica.Core
Summary
Contains many useful constants used in date/time calculations, that are private in DateTime.
<a name='F-Semantica-Core-DateTimeConstants-DaysPer100Years'></a>
DaysPer100Years constants
<a name='F-Semantica-Core-DateTimeConstants-DaysPer400Years'></a>
DaysPer400Years constants
<a name='F-Semantica-Core-DateTimeConstants-DaysPer4Years'></a>
DaysPer4Years constants
<a name='F-Semantica-Core-DateTimeConstants-DaysPerYear'></a>
DaysPerYear constants
<a name='F-Semantica-Core-DateTimeConstants-DaysToMonth365'></a>
DaysToMonth365 constants
<a name='F-Semantica-Core-DateTimeConstants-DaysToMonth366'></a>
DaysToMonth366 constants
<a name='F-Semantica-Core-DateTimeConstants-MillisPerDay'></a>
MillisPerDay constants
<a name='F-Semantica-Core-DateTimeConstants-MillisPerHour'></a>
MillisPerHour constants
<a name='F-Semantica-Core-DateTimeConstants-MillisPerMinute'></a>
MillisPerMinute constants
<a name='F-Semantica-Core-DateTimeConstants-MillisPerSecond'></a>
MillisPerSecond constants
<a name='F-Semantica-Core-DateTimeConstants-TicksPerDay'></a>
TicksPerDay constants
<a name='F-Semantica-Core-DateTimeConstants-TicksPerHour'></a>
TicksPerHour constants
<a name='F-Semantica-Core-DateTimeConstants-TicksPerMillisecond'></a>
TicksPerMillisecond constants
<a name='F-Semantica-Core-DateTimeConstants-TicksPerMinute'></a>
TicksPerMinute constants
<a name='F-Semantica-Core-DateTimeConstants-TicksPerSecond'></a>
TicksPerSecond constants
<a name='P-Semantica-Core-DateTimeConstants-DaysInMonth365'></a>
DaysInMonth365 property
<a name='P-Semantica-Core-DateTimeConstants-DaysInMonth366'></a>
DaysInMonth366 property
<a name='M-Semantica-Core-DateTimeConstants-GetDaysInMonth-System-Int32,System-Int32-'></a>
GetDaysInMonth() method
Summary
Returns the number of days in the month represented by that month
and year
.
Returns
A byte
value between 28 and 31.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-DateTimeConstants-GetDaysInMonth-System-DateOnly-'></a>
GetDaysInMonth() method
Summary
Returns the number of days in the month that date
is in.
Returns
A byte
value between 28 and 31.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-DateTimeConstants-GetDaysInMonth-System-DateTime-'></a>
GetDaysInMonth() method
Summary
Inherit from parent.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-DateTimeConstants-MonthNumberAfter-System-Int32-'></a>
MonthNumberAfter(month) method
Summary
Returns the monthnumber of the month that follows month
. If the input value is invalid, the
output is invalid too.
Returns
A month number (1-12).
Parameters
Name | Type | Description |
---|---|---|
month | System.Int32 | A month number (1-12). |
<a name='M-Semantica-Core-DateTimeConstants-MonthNumberBefore-System-Int32-'></a>
MonthNumberBefore(month) method
Summary
Returns the monthnumber of the month that precedes month
. If the input value is invalid, the
output is invalid too.
Returns
A month number (1-12).
Parameters
Name | Type | Description |
---|---|---|
month | System.Int32 | A month number (1-12). |
<a name='T-Semantica-Core-Json-JsonConverterBase-DateTimeOffset`1'></a>
DateTimeOffset`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a DateTimeOffset.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to datetime offset. |
<a name='T-Semantica-Core-Json-JsonConverterBase-DateTime`1'></a>
DateTime`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a DateTime.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to datetime. |
<a name='T-Semantica-Core-Json-JsonConverterBase-Decimal`1'></a>
Decimal`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Decimal`1.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to decimal. |
<a name='T-Semantica-Core-Json-JsonConverterBase-Double`1'></a>
Double`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Double.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to double. |
<a name='T-Semantica-Core-FuncComparer`2'></a>
FuncComparer`2 type
Namespace
Semantica.Core
Summary
A class that implements IComparer`1, that is constructed with a function selector to extract the required key from a source instance.
Generic Types
Name | Description |
---|---|
TSource | The type of the source instances. |
TKey | The type of the key used for source comparison. |
<a name='M-Semantica-Core-FuncComparer2-#ctor-System-Func{
0,1},System-Boolean,System-Boolean,System-Collections-Generic-IComparer{
1}-'></a>
#ctor(selector,invertOrder,emptyIsSmaller,keyComparer) constructor
Parameters
Name | Type | Description |
---|---|---|
selector | System.Func{`0,`1} | Selector function used to extract keys. |
invertOrder | System.Boolean | When false (default), comparisons are regular. When true, comparison is inverted. |
emptyIsSmaller | System.Boolean | When true (default), a null source will be ordered smaller than a non-null source. |
keyComparer | System.Collections.Generic.IComparer{`1} | When provided, this comparer is used to compare keys instead of the default comparer. |
<a name='M-Semantica-Core-FuncComparer2-Compare-
0,`0-'></a>
Compare() method
Summary
Inherit from parent.
Parameters
This method has no parameters.
<a name='T-Semantica-Core-Json-JsonConverterBase-Guid`1'></a>
Guid`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Guid.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to guid. |
<a name='T-Semantica-Core-Providers-IDateTimeProvider'></a>
IDateTimeProvider type
Namespace
Semantica.Core.Providers
Summary
Provides methods to get the current date and time.
Remarks
The implementation is just a wrapper around the DateTime's static Now, UtcNow and Today members in order to be able to mock it in tests.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-ConvertLocalToOffset-System-DateTime-'></a>
ConvertLocalToOffset(dateTime) method
Summary
Will convert a non-UTC datetime to DateTimeOffset with an explicit offset of the local timezone.
Returns
A local DateTimeOffset.
Parameters
Name | Type | Description |
---|---|---|
dateTime | System.DateTime | Input (non-UTC) DateTime to convert DateTimeOffset. |
Exceptions
Name | Description |
---|---|
System.ArgumentException | If the kind of the input is Utc and local timezone is not. |
<a name='M-Semantica-Core-Providers-IDateTimeProvider-ConvertUtcToOffset-System-DateTime-'></a>
ConvertUtcToOffset(dateTime) method
Summary
Will convert a UTC datetime to the local timezone, and return it as a DateTimeOffset.
Returns
A local DateTimeOffset.
Parameters
Name | Type | Description |
---|---|---|
dateTime | System.DateTime | Input UTC DateTime to adjust to local time. |
Exceptions
Name | Description |
---|---|
System.ArgumentException | If the kind of the input is not Utc. |
<a name='M-Semantica-Core-Providers-IDateTimeProvider-MidnightToday'></a>
MidnightToday() method
Summary
Returns a DateTime representing the current date. The date part of the returned value is the current date, and the time-of-day part of the returned value is zero (midnight).
Parameters
This method has no parameters.
Remarks
The value wil have DateTimeKind.Local.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-MidnightTodayOffset'></a>
MidnightTodayOffset() method
Summary
Returns a DateTimeOffset representing the current date. The date part of the returned value is the current date, and the time-of-day part of the returned value is zero (midnight).
Parameters
This method has no parameters.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-Now'></a>
Now() method
Summary
Returns a DateTime representing the current date and time.
Parameters
This method has no parameters.
Remarks
The resolution of the returned value depends on the system timer. The value wil have DateTimeKind.Local, unless OffsetKind is overridden.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-NowOffset'></a>
NowOffset() method
Summary
Returns a DateTimeOffset representing the current date and time.
Parameters
This method has no parameters.
Remarks
The resolution of the returned value depends on the system timer.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-Offset-System-DateTime-'></a>
Offset(dateTime) method
Summary
Returns a TimeSpan containing the local offset compared to UTC. Non-constant for locations that have daylight-savings time (DST).
Parameters
Name | Type | Description |
---|---|---|
dateTime | System.DateTime | The date and time for wich the offset needs to be determined, according to the TimeZoneInfo. |
Remarks
Override this or TimeZoneInfo to make methods return non-local time. When doing so, OffsetKind should also be overridden to return Unspecified.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-OffsetKind'></a>
OffsetKind() method
Summary
Returns the DateTimeKind used for all DateTimes returned.
Parameters
This method has no parameters.
Remarks
Local, unless the default implementation is overridden.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-Time'></a>
Time() method
Summary
Returns a TimeOnly representing the current time of day.
Parameters
This method has no parameters.
Remarks
The resolution of the returned value depends on the system timer.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-TimeZoneInfo'></a>
TimeZoneInfo() method
Summary
Returns the TimeZoneInfo used for all non-utc methods.
Parameters
This method has no parameters.
Remarks
Will use the local timezone unless overridden. When doing so, OffsetKind should also be overridden to return Unspecified.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-Today'></a>
Today() method
Summary
Returns a DateOnly representing the current date.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-UtcMidnightToday'></a>
UtcMidnightToday() method
Summary
Returns a DateTime representing the current date in Utc-time. The date part of the returned value is the current date, and the time-of-day part of the returned value is zero (midnight).
Parameters
This method has no parameters.
Remarks
The value wil have DateTimeKind.Utc.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-UtcMidnightTodayOffset'></a>
UtcMidnightTodayOffset() method
Summary
Returns a DateTimeOffset representing the current date in Utc-time. The date part of the returned value is the current date, and the time-of-day part of the returned value is zero (midnight).
Parameters
This method has no parameters.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-UtcNow'></a>
UtcNow() method
Summary
Returns a DateTime representing the current date and time in Utc-time.
Parameters
This method has no parameters.
Remarks
The resolution of the returned value depends on the system timer. The value wil have DateTimeKind.Utc.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-UtcNowOffset'></a>
UtcNowOffset() method
Summary
Returns a DateTime representing the current date and time in Utc-time.
Parameters
This method has no parameters.
Remarks
The resolution of the returned value depends on the system timer.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-UtcTime'></a>
UtcTime() method
Summary
Returns a TimeOnly representing the current time of day in Utc-time.
Parameters
This method has no parameters.
Remarks
The resolution of the returned value depends on the system timer.
<a name='M-Semantica-Core-Providers-IDateTimeProvider-UtcToday'></a>
UtcToday() method
Summary
Returns a DateOnly representing the current date in Utc-time.
Parameters
This method has no parameters.
<a name='T-Semantica-Core-Providers-ISnapshotDateTimeProvider'></a>
ISnapshotDateTimeProvider type
Namespace
Semantica.Core.Providers
Summary
Provides methods to get the current date and time. Contrary to the normal IDateTimeProvider, the first time the current date or time is retrieved in the current scope, this value is always returned until Reset is called.
Remarks
When the implementation is registered with a scoped lifetime, this can be used to ensure that all multiple calls utilize the same time, even when there is some process delaying parts of the execution by a significant amount of time.
<a name='M-Semantica-Core-Providers-ISnapshotDateTimeProvider-Reset'></a>
Reset() method
Summary
Resets the stored date/time value for this scope. The next call to get the date/time will set the value to the exact current date/time value at the moment of calling.
Parameters
This method has no parameters.
<a name='T-Semantica-Core-Json-JsonConverterBase-Int16`1'></a>
Int16`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Int16.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to short. |
<a name='T-Semantica-Core-Json-JsonConverterBase-Int32`1'></a>
Int32`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Int32.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to int. |
<a name='T-Semantica-Core-Json-JsonConverterBase-Int64`1'></a>
Int64`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Int64.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to long. |
<a name='T-Semantica-Core-Json-JsonConverterBase'></a>
JsonConverterBase type
Namespace
Semantica.Core.Json
Summary
Provides base classes inheriting from JsonConverter`1 for value types that hold a single underlying value
type (struct
) that is supported by System.Text.Json.
Remarks
For conversions from the underlying type, override GetDefault if a value
different to default(T?) (null
) should be returned when reading of the underlying type fails.
<a name='T-Semantica-Core-Logic'></a>
Logic type
Namespace
Semantica.Core
Summary
Provides a number of static methods used for logic (Boolean) operations that are not natively supported.
<a name='M-Semantica-Core-Logic-ExactlyOne-System-Boolean[]-'></a>
ExactlyOne(bools) method
Summary
Determines if of the provided booleans, exactly one is true
.
Returns
true
if and only if one of the parameters is true
, and all others are
false
.
Parameters
Name | Type | Description |
---|---|---|
bools | System.Boolean[] | Any number of bool parameters. |
<a name='M-Semantica-Core-Logic-Follows-System-Boolean,System-Boolean[]-'></a>
Follows(if,bools) method
Summary
Determines if the provided booleans follow from if
[if
→ bools
].
Returns
true
if either if
is false
, or if
and all
bools
are true
.
Parameters
Name | Type | Description |
---|---|---|
if | System.Boolean | The bool parameter to be tested. |
bools | System.Boolean[] | Any number of bool parameters. |
<a name='M-Semantica-Core-Logic-None-System-Boolean[]-'></a>
None(bools) method
Summary
Determines if of the provided booleans, all are false
.
Returns
true
if and only if all of the parameters are false
.
Parameters
Name | Type | Description |
---|---|---|
bools | System.Boolean[] | Any number of bool parameters. |
Remarks
Logically equivalent to ! param1 && ! param2 && (...)
.
<a name='M-Semantica-Core-Logic-NoneOrOne-System-Boolean[]-'></a>
NoneOrOne(bools) method
Summary
Determines if of the provided booleans, none or exactly one is true
.
Returns
true
if and only if zero or one of the parameters are true
, and all others are
false
.
Parameters
Name | Type | Description |
---|---|---|
bools | System.Boolean[] | Any number of bool parameters. |
<a name='T-Semantica-Core-Module'></a>
Module type
Namespace
Semantica.Core
Summary
Module that registers implementations of:
<a name='T-Semantica-Core-DependencyInjection-ModuleBase`1'></a>
ModuleBase`1 type
Namespace
Semantica.Core.DependencyInjection
Summary
Provides a neat way of organising DI registrations per project and within a project.
Assemblies containing dependencies are registered by overriding GetDependencyAssemblies. Individual modules containing dependencies can be registered by overriding GetDependencyModules.
When Register is called, all classes in all relevant assemblies that inherit from ModuleBase`1 with a compatible container are recursively instantiated and called.
Generic Types
Name | Description |
---|---|
TContainer | The type of the used CI container or builder. |
<a name='M-Semantica-Core-DependencyInjection-ModuleBase`1-GetDependencyAssemblies'></a>
GetDependencyAssemblies() method
Summary
Override if this module has dependencies within other assemblies. This method should yield all Assemblies containing dependencies once.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-DependencyInjection-ModuleBase`1-GetDependencyModules'></a>
GetDependencyModules() method
Summary
Override if this module has dependencies within other modules. This method provides more granular dependency paths than by using GetDependencyAssemblies, when a single assembly has multiple modules.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-DependencyInjection-ModuleBase`1-GetMicrosoftDependencyInjectionModules'></a>
GetMicrosoftDependencyInjectionModules() method
Summary
Override if this module has dependencies within other modules. This method provides more granular dependency paths than by using GetDependencyAssemblies, when a single assembly has multiple modules. Only use if ToMicrosoftDependencyInjectionAbstractions is overridden.
Parameters
This method has no parameters.
<a name='M-Semantica-Core-DependencyInjection-ModuleBase1-Register-
0,System-Boolean-'></a>
Register(container,findOtherModulesInSameAssembly) method
Summary
Applies all registrations for the module, other modules in the same assembly, and modules in dependent assemblies. Ensures modules are only used once, even if there are multiple paths to a dependency assembly.
Parameters
Name | Type | Description |
---|---|---|
container | `0 | The CI container or builder instance used to do all registrations. |
findOtherModulesInSameAssembly | System.Boolean | If true , the current assembly will be searched for other implementations of |
ModuleBase`1, and not just assemblies referenced in . |
Remarks
If TContainer
is not IServiceCollection,
and ToMicrosoftDependencyInjectionAbstractions is overridden and doesn't return null
,
modules that implement ModuleBase`1 of type IServiceCollection are also searched for.
Registrations are done in order:
Module order within the assemblies is determined by GetTypes.
<a name='M-Semantica-Core-DependencyInjection-ModuleBase1-ToMicrosoftDependencyInjectionAbstractions-
0-'></a>
ToMicrosoftDependencyInjectionAbstractions(container) method
Summary
Override this method if at any point in the Dependency Assemblies, there are modules that are defined using IServiceCollection instead of a third party DI framework. ..
Returns
A wrapper around container
that implements at least the Add method from
IServiceCollection.
Parameters
Name | Type | Description |
---|---|---|
container | `0 | The container of type TContainer used for third party registrations. |
Remarks
This will only work if the modules using IServiceCollection do only registrations in a manner that is
compatible to the third party container
.
<a name='T-Semantica-Core-DependencyInjection-ModuleException'></a>
ModuleException type
Namespace
Semantica.Core.DependencyInjection
Summary
Represents errors that occur during DI registrations using ModuleBase`1.
<a name='T-Semantica-Core-Json-JsonConverterBase-SByte`1'></a>
SByte`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a SByte.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to sbyte. |
<a name='T-Semantica-Core-Json-JsonConverterBase-Single`1'></a>
Single`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a Single.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to float. |
<a name='T-Semantica-Core-StaticSelectors'></a>
StaticSelectors type
Namespace
Semantica.Core
Summary
Provides predefined selector functions.
<a name='M-Semantica-Core-StaticSelectors-SelfNotNull1-System-Nullable{
0}-'></a>
SelfNotNull``1(t) method
Summary
Returns the value of the element itself. Throws if element has no value.
Returns
t
.
Parameters
Name | Type | Description |
---|---|---|
t | System.Nullable{``0} | The source element. |
Generic Types
Name | Description |
---|---|
T | The type of element to select. |
<a name='M-Semantica-Core-StaticSelectors-SelfNotNull1-
0-'></a>
SelfNotNull``1(t) method
Summary
Returns the element itself.
Returns
t
.
Parameters
Name | Type | Description |
---|---|---|
t | ``0 | The source element. |
Generic Types
Name | Description |
---|---|
T | The type of element to select. |
<a name='M-Semantica-Core-StaticSelectors-Self1-
0-'></a>
Self``1(t) method
Summary
Returns the element itself.
Returns
t
.
Parameters
Name | Type | Description |
---|---|---|
t | ``0 | The source element. |
Generic Types
Name | Description |
---|---|
T | The type of element to select. |
<a name='T-Semantica-Core-Json-StringJsonConverterBase`1'></a>
StringJsonConverterBase`1 type
Namespace
Semantica.Core.Json
Summary
Base class that inherits from JsonConverter`1, meant for conversions of T
from and to
string
. Only FromString and ToString abstract methods need to be implemented.
For conversions from string, exceptions are thrown by default when an unexpected token is encountered. Override GetDefaultOnUnexpectedTokenType to change this behaviour. When FromString throws a (parse-)exception, this exception is caught and rethrown in GetDefaultOnParseException. Override this method to change that behaviour. Override DefaultOnNull or DefaultOnEmpty when a special default value (and not default(T)) is needed on null or empty input respectively. Overriding Default if these situations require the same value.
Generic Types
Name | Description |
---|---|
T | Type to convert to and from String. |
Remarks
Like the base JsonConverter`1, if the property type is a class, or Nullable`1 and the input is null, the value of null is assigned directly unless HandleNull is overriden.
<a name='P-Semantica-Core-Json-StringJsonConverterBase`1-Default'></a>
Default property
Summary
Returns default(T). Override if a different value to should be returned when a default value is needed. Override If both other default properties are overriden, this property is no longer used.
<a name='P-Semantica-Core-Json-StringJsonConverterBase`1-DefaultOnEmpty'></a>
DefaultOnEmpty property
Summary
This property is called by Read to get the value that's used when the input is an empty string (or whitespace if DoTrim is true).
<a name='P-Semantica-Core-Json-StringJsonConverterBase`1-DefaultOnNull'></a>
DefaultOnNull property
Summary
This property is called by Read to get the value that's used when the input is null
.
<a name='P-Semantica-Core-Json-StringJsonConverterBase`1-DoTrim'></a>
DoTrim property
Summary
Returns false
unless overriden. When true
, the read string is trimmed before
evaluating whether it's empty, and passing it to FromString.
<a name='M-Semantica-Core-Json-StringJsonConverterBase`1-FromString-System-String-'></a>
FromString(str) method
Summary
Implementation of the conversion to T
.
Returns
An instance of T
.
Parameters
Name | Type | Description |
---|---|---|
str | System.String | String value to convert. |
<a name='M-Semantica-Core-Json-StringJsonConverterBase`1-GetDefaultOnParseException-System-Exception-'></a>
GetDefaultOnParseException(e) method
Summary
Rethrows the passed exception e
. Called by Read when an exception occured during
FromString (i.e. parsing). Override this method to make Read return a default value rather
than throwing when this happens.
Parameters
Name | Type | Description |
---|---|---|
e | System.Exception | The previously caught parse exception. |
Exceptions
Name | Description |
---|---|
System.Exception | (Re-)throws always. |
<a name='M-Semantica-Core-Json-StringJsonConverterBase`1-GetDefaultOnUnexpectedTokenType-System-Exception-'></a>
GetDefaultOnUnexpectedTokenType(e) method
Summary
Rethrows the passed exception e
. Called by Read when an unexpected token type is
encountered. Override this method to make Read return a default value rather than throwing when this
happens.
Parameters
Name | Type | Description |
---|---|---|
e | System.Exception | The previously caught token exception. |
Exceptions
Name | Description |
---|---|
System.Exception | (Re-)throws always. |
<a name='M-Semantica-Core-Json-StringJsonConverterBase1-ToString-
0-'></a>
ToString(value) method
Summary
Implementation of the conversion of T
to string.
Returns
An string representation of the input.
Parameters
Name | Type | Description |
---|---|---|
value | `0 | Value of T to convert. |
<a name='T-Semantica-Core-StringTypeConverterBase`1'></a>
StringTypeConverterBase`1 type
Namespace
Semantica.Core
Summary
Base class that inherits from TypeConverter, meant for conversions of T
from and to
string
. Only FromString and ToString abstract methods need to be implemented.
Generic Types
Name | Description |
---|---|
T | Type to convert to and from String. |
Remarks
For conversions from string, override DefaultOnNull if a value different to default(T) should be returned on a
null
value.
<a name='P-Semantica-Core-StringTypeConverterBase`1-Default'></a>
Default property
Summary
Returns default(T). Override if a different value to should be returned when a default value is needed. Override If both other default properties are overriden, this property is no longer used.
<a name='P-Semantica-Core-StringTypeConverterBase`1-DefaultOnEmpty'></a>
DefaultOnEmpty property
Summary
This property is called by ConvertTo to get the value that's used when the input is an empty string (or whitespace if DoTrim is true).
<a name='P-Semantica-Core-StringTypeConverterBase`1-DefaultOnNull'></a>
DefaultOnNull property
Summary
This property is called by ConvertFrom to get the value that's used when the input is
null
, or cannot be cast to a string.
<a name='P-Semantica-Core-StringTypeConverterBase`1-DoTrim'></a>
DoTrim property
Summary
Returns false
unless overriden. When true
, the read string is trimmed before
evaluating whether it's empty, and passing it to FromString.
<a name='M-Semantica-Core-StringTypeConverterBase`1-FromString-System-String-'></a>
FromString(str) method
Summary
Implementation of the conversion to T
.
Returns
An instance of T
.
Parameters
Name | Type | Description |
---|---|---|
str | System.String | String value to convert. |
<a name='M-Semantica-Core-StringTypeConverterBase`1-GetDefaultOnParseException-System-Exception-'></a>
GetDefaultOnParseException(e) method
Summary
Rethrows the passed exception e
. Called by ConvertFrom when an exception occured during
FromString (i.e. parsing). Override this method to make ConvertFrom return a default value
rather than throwing when this happens.
Parameters
Name | Type | Description |
---|---|---|
e | System.Exception | The previously caught parse exception. |
Exceptions
Name | Description |
---|---|
System.Exception | (Re-)throws always. |
<a name='M-Semantica-Core-StringTypeConverterBase1-ToString-
0-'></a>
ToString(value) method
Summary
Implementation of the conversion of T
to string.
Returns
An string representation of the input.
Parameters
Name | Type | Description |
---|---|---|
value | `0 | Value of T to convert. |
<a name='T-Semantica-Core-Json-JsonConverterBase-UInt16`1'></a>
UInt16`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a UInt16.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to ushort. |
<a name='T-Semantica-Core-Json-JsonConverterBase-UInt32`1'></a>
UInt32`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a UInt32.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to uint. |
<a name='T-Semantica-Core-Json-JsonConverterBase-UInt64`1'></a>
UInt64`1 type
Namespace
Semantica.Core.Json.JsonConverterBase
Summary
Use for value types that can be represented as a UInt64.
Generic Types
Name | Description |
---|---|
T | The type to convert from or to ulong. |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
-
net6.0
-
net7.0
-
net8.0
NuGet packages (13)
Showing the top 5 NuGet packages that depend on Semantica.Lib.Core:
Package | Downloads |
---|---|
Semantica.Lib.Extensions
A library that provides general useful extensions for many built in types, including but not limited to Array<T>, Attribute, DateOnly, DateTime, DateTimeOffset, Enum, List<T>, Expression<T>, PropertyInfo, as well as an optimized fluentAPI string splitter/tokenizer (string.Tokenize()) leveraging ReadOnlySpan<T>. |
|
Semantica.Lib.Linq
A library that provides extensions that expand on the standard System.Linq functionality on IEnumerable<T> and IQueryable<T>, as well as provide optimized extensions/overloads for the IReadOnlyList<T>, IReadOnlyCollection<T> and IReadOnlyDictionary<TKey,T> interfaces. |
|
Semantica.Lib.Order
A library that provides types and extensions that represent and help with ordering of collections. |
|
Semantica.Lib.Intervals
A library that provides types that can be used to represent intervals and collections of intervals as well as extensions for these types. |
|
Semantica.Lib.Package.Core
Combines all primary Semantica.Lib.Core packages in a single package. Check the ReadMe of each package for further elaboration on package contents. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
8.1.0 | 209 | 5/30/2025 |
8.0.7 | 337 | 9/6/2024 |
8.0.6-beta | 867 | 7/10/2024 |
8.0.5-beta | 931 | 7/4/2024 |
8.0.4-beta | 255 | 7/2/2024 |
8.0.3-beta | 245 | 6/14/2024 |
8.0.2-beta | 309 | 6/4/2024 |
8.0.1-beta | 239 | 6/4/2024 |
8.0.0-beta | 250 | 6/4/2024 |
6.6.1-beta | 380 | 4/5/2024 |
6.6.0-beta | 390 | 3/5/2024 |
6.5.5-alpha2 | 173 | 3/4/2024 |
6.5.5-alpha | 138 | 3/4/2024 |
6.5.4-beta | 193 | 2/29/2024 |
6.5.3-beta | 928 | 10/5/2023 |
6.5.2-beta | 206 | 10/5/2023 |
6.5.1-beta | 260 | 9/29/2023 |
6.5.0-beta | 202 | 9/22/2023 |
6.4.0-beta | 511 | 7/11/2023 |
6.3.0-beta | 235 | 6/15/2023 |
6.2.5-beta | 280 | 3/14/2023 |
6.2.4-beta | 656 | 10/12/2022 |
6.2.3-beta | 344 | 9/1/2022 |
6.2.1-beta | 264 | 8/25/2022 |