Semantica.Lib.Types
8.1.0
dotnet add package Semantica.Lib.Types --version 8.1.0
NuGet\Install-Package Semantica.Lib.Types -Version 8.1.0
<PackageReference Include="Semantica.Lib.Types" Version="8.1.0" />
<PackageVersion Include="Semantica.Lib.Types" Version="8.1.0" />
<PackageReference Include="Semantica.Lib.Types" />
paket add Semantica.Lib.Types --version 8.1.0
#r "nuget: Semantica.Lib.Types, 8.1.0"
#:package Semantica.Lib.Types@8.1.0
#addin nuget:?package=Semantica.Lib.Types&version=8.1.0
#tool nuget:?package=Semantica.Lib.Types&version=8.1.0
Semantica.Lib.Types
This package is part of the core packages of Semantica.Lib.
Summary
A library that provides several value types and extensions for those types. This includes but is not limited to
DateSpan
, EmailAddress
, Hash
, Link
, RouteValues
. These simple stucts can make your models and
method signatures more readable/expressive, and be useful to write extensions.
Includes Converters.TypeConverterRestistrations
, a helper that can dynamically add typeconverter attributes to
types, eliminating the requirement to have your typeconverter classes in the same project as the types they can
convert, acting on the IRunTimeTypeConverter
interface.
Provides types and helpers for code keys, a compact, human-readable encoding of integers.
Dependencies
- Semantica.Lib.Checks
- Semantica.Lib.Core
- Semantica.Lib.Extensions
- Semantica.Lib.Linq
- Semantica.Lib.Patterns
- Semantica.Lib.Patterns.Converters
Documentation generated from the XMLDoc:
<a name='assembly'></a>
Lib.Types
Contents
- DateSpan
- EmailAddressExtensions
- IRuntimeTypeConverter`2
- LinkExtensions
- PartitionDate
- PartitionDateExtensions
- AsDateOnly(value)
- AsDateTime(value,dateTimeKind)
- AsNullableDateOnly(value)
- AsNullableDateTime(value,dateTimeKind)
- AsPartitionDate(value)
- AsPartitionDate(value)
- HasValidDay(value)
- HasValidMonth(value)
- HasValidYear(value)
- IsValidDate(value)
- TryAsDateOnly(value,dateOnly)
- TryAsDateTime(value,dateTime,dateTimeKind)
- PartitionDateTypeConverter
- TypeConverterRegistrations
<a name='T-Semantica-Types-DateSpan'></a>
DateSpan type
Namespace
Semantica.Types
Summary
Represents a difference between two dates, considering months and days separately.
<a name='F-Semantica-Types-DateSpan-_value'></a>
_value constants
Summary
Value holding the number of days (5 bits: 1-5), the total number of months (17 bits: 6-22) the amount of days till the end of the month in case of month-rollover (5 bits: 23-27), difference in weekday (3 bits: 28-30) and the sign (bit 31), and whether or not the span was constructed as a full difference (bit 32).
<a name='T-Semantica-Types-EmailAddressExtensions'></a>
EmailAddressExtensions type
Namespace
Semantica.Types
Summary
Provides extension methods for EmailAddress.
<a name='M-Semantica-Types-EmailAddressExtensions-IsValid-Semantica-Types-EmailAddress-'></a>
IsValid() method
Summary
Checks technical validity of the email, using System.Net.Mail.MailAddress.
Parameters
This method has no parameters.
Remarks
from
<a name='T-Semantica-Types-IRuntimeTypeConverter`2'></a>
IRuntimeTypeConverter`2 type
Namespace
Semantica.Types
Summary
Interface that provides standardizes a method to dynamically add a TypeConverterAttribute for a value type, that can be put on the typeconverter for that type. The default implementation should always suffice.
Generic Types
Name | Description |
---|---|
T | (value-)type the the typeconverter can convert. |
TConverter | Type of the typeconverter |
Remarks
This interface can be used for using type converters for value types that are in a different assembly than the corresponding typeconverter.
The AddTypeConverterAttribute method can be called at runtime for each custom type converter, or alternativly use TypeConverterRegistrations to search for all type converters implementing this interface in provided assemblies.
<a name='T-Semantica-Types-LinkExtensions'></a>
LinkExtensions type
Namespace
Semantica.Types
Summary
Provides extension methods for Link.
<a name='M-Semantica-Types-LinkExtensions-IsValid-Semantica-Types-Link-'></a>
IsValid() method
Summary
Checks technical validity of the email, using System.Uri.
Parameters
This method has no parameters.
<a name='T-Semantica-Types-PartitionDate'></a>
PartitionDate type
Namespace
Semantica.Types
Summary
Represents a date. Each part of the date is optional and can be empty (0). No validation is done on the values, but each part has a maximum amount of digits and cannot be negative.
Remarks
The value is only considered empty if all three parts are empty.
<a name='M-Semantica-Types-PartitionDate-#ctor-System-Int32,System-Int32,System-Int32-'></a>
#ctor(year,month,day) constructor
Parameters
Name | Type | Description |
---|---|---|
year | System.Int32 | A positive year value smaller or equal to YearMax. |
month | System.Int32 | A positive month value smaller than MonthMax. |
day | System.Int32 | A positive day value smaller than DayMax. |
Exceptions
Name | Description |
---|---|
System.InvalidCastException | throws if year cannot be cast to ushort , or month , day cannot be cast to byte . |
System.ArgumentException | throws if year is greater than , month is greater than , |
day is greater than . |
<a name='M-Semantica-Types-PartitionDate-#ctor-System-Int16,System-Byte,System-Byte-'></a>
#ctor(year,month,day) constructor
Parameters
Name | Type | Description |
---|---|---|
year | System.Int16 | A year value smaller or equal to YearMax. |
month | System.Byte | A month value smaller than MonthMax. |
day | System.Byte | A day value smaller than DayMax. |
Exceptions
Name | Description |
---|---|
System.ArgumentException | throws if year is greater than , month is greater than , |
day is greater than . |
<a name='P-Semantica-Types-PartitionDate-Day'></a>
Day property
<a name='P-Semantica-Types-PartitionDate-Month'></a>
Month property
<a name='P-Semantica-Types-PartitionDate-Year'></a>
Year property
<a name='M-Semantica-Types-PartitionDate-GetDay'></a>
GetDay() method
Parameters
This method has no parameters.
<a name='M-Semantica-Types-PartitionDate-GetMonth'></a>
GetMonth() method
Parameters
This method has no parameters.
<a name='M-Semantica-Types-PartitionDate-GetYear'></a>
GetYear() method
Parameters
This method has no parameters.
<a name='M-Semantica-Types-PartitionDate-HasDay'></a>
HasDay() method
Returns
true
if the day-part of the date is not 0.
Parameters
This method has no parameters.
<a name='M-Semantica-Types-PartitionDate-HasMonth'></a>
HasMonth() method
Returns
true
if the month-part of the date is not 0.
Parameters
This method has no parameters.
<a name='M-Semantica-Types-PartitionDate-HasYear'></a>
HasYear() method
Returns
true
if the year-part of the date is not 0.
Parameters
This method has no parameters.
<a name='T-Semantica-Types-PartitionDateExtensions'></a>
PartitionDateExtensions type
Namespace
Semantica.Types
Summary
Provides additional functionality for to PartitionDate values.
<a name='M-Semantica-Types-PartitionDateExtensions-AsDateOnly-Semantica-Types-PartitionDate-'></a>
AsDateOnly(value) method
Summary
Conversts a PartitionDate value to DateOnly.
Returns
A DateOnly instance.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | Date value to convert. |
Exceptions
Name | Description |
---|---|
System.ArgumentOutOfRangeException | |
System.ArgumentException |
<a name='M-Semantica-Types-PartitionDateExtensions-AsDateTime-Semantica-Types-PartitionDate,System-DateTimeKind-'></a>
AsDateTime(value,dateTimeKind) method
Summary
Conversts a PartitionDate value to DateTime.
Returns
A DateTime instance, with the time part set at midnight.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | Date value to convert. |
dateTimeKind | System.DateTimeKind | Optional. DateTimeKind used in the created DateTime. |
Exceptions
Name | Description |
---|---|
System.ArgumentOutOfRangeException | |
System.ArgumentException |
<a name='M-Semantica-Types-PartitionDateExtensions-AsNullableDateOnly-Semantica-Types-PartitionDate-'></a>
AsNullableDateOnly(value) method
Summary
Conversts a PartitionDate value to DateOnly. If input is invalid then null is returned (see IsValidDate.
Returns
A DateOnly instance; no value when invalid.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | Date value to convert. |
<a name='M-Semantica-Types-PartitionDateExtensions-AsNullableDateTime-Semantica-Types-PartitionDate,System-DateTimeKind-'></a>
AsNullableDateTime(value,dateTimeKind) method
Summary
Converts a PartitionDate value to DateTime. If input is invalid then null is returned (see IsValidDate.
Returns
A DateTime instance; no value when invalid.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | Date value to convert. |
dateTimeKind | System.DateTimeKind | Optional. DateTimeKind used in the created value. |
<a name='M-Semantica-Types-PartitionDateExtensions-AsPartitionDate-System-DateOnly-'></a>
AsPartitionDate(value) method
Summary
Converts a DateOnly value to PartitionDate.
Returns
A PartitionDate instance.
Parameters
Name | Type | Description |
---|---|---|
value | System.DateOnly | DateOnly value to convert. |
<a name='M-Semantica-Types-PartitionDateExtensions-AsPartitionDate-System-DateTime-'></a>
AsPartitionDate(value) method
Summary
Converts a DateTime value to PartitionDate. The time part is ignored.
Returns
A PartitionDate instance.
Parameters
Name | Type | Description |
---|---|---|
value | System.DateTime | DateTime value to convert. |
<a name='M-Semantica-Types-PartitionDateExtensions-HasValidDay-Semantica-Types-PartitionDate-'></a>
HasValidDay(value) method
Summary
Determines if the Day part of the input has a valid value. The combination of all parts can still be invalid.
Returns
true
if the day part is valid (in the range of 1-31); false
otherwise.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | PartitionDate to evaluate the day part of. |
<a name='M-Semantica-Types-PartitionDateExtensions-HasValidMonth-Semantica-Types-PartitionDate-'></a>
HasValidMonth(value) method
Summary
Determines if the Month part of the input has a valid value. The combination of all parts can still be invalid.
Returns
true
if the month part is valid (in the range of 1-12); false
otherwise.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | PartitionDate to evaluate the month part of. |
<a name='M-Semantica-Types-PartitionDateExtensions-HasValidYear-Semantica-Types-PartitionDate-'></a>
HasValidYear(value) method
Summary
Determines if the Year part of the input has a valid value. The combination of all parts can still be invalid.
Returns
true
if the year part is valid (in the range of 1-9999); false
otherwise.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | PartitionDate to evaluate the year part of. |
<a name='M-Semantica-Types-PartitionDateExtensions-IsValidDate-Semantica-Types-PartitionDate-'></a>
IsValidDate(value) method
Summary
Determines whether value
contains a valid date.
Returns
true
if date is convertable to DateTime.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | PartitionDate to convert |
<a name='M-Semantica-Types-PartitionDateExtensions-TryAsDateOnly-Semantica-Types-PartitionDate,System-DateOnly@-'></a>
TryAsDateOnly(value,dateOnly) method
Summary
Converts a PartitionDate value to DateOnly and returns whether conversion succeeded. Fails when the value is an invalid date (see IsValidDate).
Returns
true
if dateOnly
has been set; false
otherwise.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | PartitionDate to convert. |
dateOnly | System.DateOnly@ | Out parameter that will contain the DateOnly value if succeeded. |
<a name='M-Semantica-Types-PartitionDateExtensions-TryAsDateTime-Semantica-Types-PartitionDate,System-DateTime@,System-DateTimeKind-'></a>
TryAsDateTime(value,dateTime,dateTimeKind) method
Summary
Converts a PartitionDate value to DateTime and returns whether conversion succeeded. Fails when the value is an invalid date (see IsValidDate).
Returns
true
if dateTime
has been set; false
otherwise.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | PartitionDate to convert. |
dateTime | System.DateTime@ | Out parameter that will contain the DateTime value if succeeded. |
dateTimeKind | System.DateTimeKind | Optional. DateTimeKind used in the created value. |
<a name='T-Semantica-Types-Converters-PartitionDateTypeConverter'></a>
PartitionDateTypeConverter type
Namespace
Semantica.Types.Converters
Summary
TypeConverter for PartitionDate
<a name='M-Semantica-Types-Converters-PartitionDateTypeConverter-Deserialize-System-String-'></a>
Deserialize(str) method
Summary
Deserializes a string to a PartitionDate value. Will accept any string that has exactly two '|' chars in it, and at least one of the parts can be parsed to a Int16 (year) or Byte (day/month).
Returns
A PartitionDate value containing all valid parts of the parsed string.
Parameters
Name | Type | Description | ||
---|---|---|---|---|
str | System.String | String to parse, "yyyy | MM | dd". |
<a name='M-Semantica-Types-Converters-PartitionDateTypeConverter-Serialize-Semantica-Types-PartitionDate-'></a>
Serialize(value) method
Summary
Serializes a PartitionDate value
Returns
A String value representing the input value.
Parameters
Name | Type | Description |
---|---|---|
value | Semantica.Types.PartitionDate | A PartitionDate value. |
<a name='T-Semantica-Types-Converters-TypeConverterRegistrations'></a>
TypeConverterRegistrations type
Namespace
Semantica.Types.Converters
Summary
Provides functionality to dynamically add TypeConverterAttribute to types, so this can be used when the converter and the value type are in different assemblies. Converter classes have to implement IRuntimeTypeConverter`2 to be recognised.AddTypeConverterAttributesInAssembly is the main entry method.
<a name='M-Semantica-Types-Converters-TypeConverterRegistrations-AddTypeConverterAttribute-System-Type,System-Type-'></a>
AddTypeConverterAttribute(valueType,converterType) method
Summary
Adds a TypeConverterAttribute to valueType
.
Parameters
Name | Type | Description |
---|---|---|
valueType | System.Type | Value type to add the attribute to. |
converterType | System.Type | Converter type to use as the attribute argument. |
<a name='M-Semantica-Types-Converters-TypeConverterRegistrations-AddTypeConverterAttributes-System-Collections-Generic-IEnumerable{System-Type}-'></a>
AddTypeConverterAttributes(types) method
Summary
Filters the supplied types to ones that implement IRuntimeTypeConverter`2. Adds TypeConverterAttribute for the found types.
Parameters
Name | Type | Description |
---|---|---|
types | System.Collections.Generic.IEnumerable{System.Type} | An enumeration of types that include the typeconverter types. |
Exceptions
Name | Description |
---|---|
Semantica.Types.Converters.TypeConverterRegistrations.TypeConverterRegistrationsException | Throws if two converters are found for the same type. Throws if the converter type attribute of the |
IRuntimeTypeConverter`2 interface is not the converter type itself. |
<a name='M-Semantica-Types-Converters-TypeConverterRegistrations-AddTypeConverterAttributesInAssembly-System-Reflection-Assembly[]-'></a>
AddTypeConverterAttributesInAssembly(assemblies) method
Summary
Main entry method. Finds all classes that implement IRuntimeTypeConverter`2 in the supplied assemblies. Adds TypeConverterAttribute for the found types.
Parameters
Name | Type | Description |
---|---|---|
assemblies | System.Reflection.Assembly[] | Assemblies to look for typeconverters in. |
Exceptions
Name | Description |
---|---|
Semantica.Types.Converters.TypeConverterRegistrations.TypeConverterRegistrationsException | Throws if two converters are found for the same type. Throws if the converter type attribute of the |
IRuntimeTypeConverter`2 interface is not the converter type itself. |
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
- Semantica.Lib.Checks (>= 8.1.0)
- Semantica.Lib.Collections (>= 8.1.0-beta)
- Semantica.Lib.Core (>= 8.1.0)
- Semantica.Lib.Extensions (>= 8.1.0)
- Semantica.Lib.Linq (>= 8.1.0)
- Semantica.Lib.Patterns (>= 8.1.0)
- Semantica.Lib.Patterns.CanSerialize (>= 8.1.0)
-
net7.0
- Semantica.Lib.Checks (>= 8.1.0)
- Semantica.Lib.Collections (>= 8.1.0-beta)
- Semantica.Lib.Core (>= 8.1.0)
- Semantica.Lib.Extensions (>= 8.1.0)
- Semantica.Lib.Linq (>= 8.1.0)
- Semantica.Lib.Patterns (>= 8.1.0)
- Semantica.Lib.Patterns.CanSerialize (>= 8.1.0)
-
net8.0
- Semantica.Lib.Checks (>= 8.1.0)
- Semantica.Lib.Collections (>= 8.1.0-beta)
- Semantica.Lib.Core (>= 8.1.0)
- Semantica.Lib.Extensions (>= 8.1.0)
- Semantica.Lib.Linq (>= 8.1.0)
- Semantica.Lib.Patterns (>= 8.1.0)
- Semantica.Lib.Patterns.CanSerialize (>= 8.1.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Semantica.Lib.Types:
Package | Downloads |
---|---|
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. |
|
Semantica.Lib.TestTools.Core
Provides a set of specific MSTest.Assert extensions (Assert.That.), to facilitate more compact assertions, and more comprehensive fail messages. Assertions include epsilon-checking for floating point types, default/empty checking for enums, strings, ICanBeEmpty, etc., DateOnly/DateTime part assertions, as well as assertions for the Semantica.Lib.Checks.Chk type. Also contains a convenient mock for Semantica.Lib.Core.Providers.IDateTimeProvider, and ModuleTestBase, an abstract base class to facilitate making unit tests for DI modules based on Semantica.Lib.Core.DependencyInjection.ModuleBase. |
|
Semantica.Lib.Mvc
A library that provides types and extensions that help with configuration and specific usages of ASP.NET applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
8.1.0 | 150 | 5/30/2025 |
8.0.7 | 195 | 9/6/2024 |
8.0.6-beta | 753 | 7/10/2024 |
8.0.5-beta | 195 | 7/4/2024 |
8.0.4-beta | 166 | 7/2/2024 |
8.0.3-beta | 149 | 6/14/2024 |
8.0.2-beta | 217 | 6/4/2024 |
8.0.1-beta | 145 | 6/4/2024 |
8.0.0-beta | 164 | 6/4/2024 |
6.6.1-beta | 274 | 4/5/2024 |
6.6.0-beta | 314 | 3/5/2024 |
6.5.5-alpha2 | 142 | 3/4/2024 |
6.5.4-beta | 156 | 2/29/2024 |
6.5.3-beta | 584 | 10/5/2023 |
6.5.2-beta | 150 | 10/5/2023 |
6.5.1-beta | 214 | 9/29/2023 |
6.5.0-beta | 191 | 9/22/2023 |
6.4.0-beta | 478 | 7/11/2023 |