TinyTypesObjects 1.0.2
dotnet add package TinyTypesObjects --version 1.0.2
NuGet\Install-Package TinyTypesObjects -Version 1.0.2
<PackageReference Include="TinyTypesObjects" Version="1.0.2" />
paket add TinyTypesObjects --version 1.0.2
#r "nuget: TinyTypesObjects, 1.0.2"
// Install TinyTypesObjects as a Cake Addin #addin nuget:?package=TinyTypesObjects&version=1.0.2 // Install TinyTypesObjects as a Cake Tool #tool nuget:?package=TinyTypesObjects&version=1.0.2
Tiny types in C#
Tiny types is a NuGET dll , https://www.nuget.org/packages/TinyTypesObjects/
Also , you can find the construction here: http://msprogrammer.serviciipeweb.ro/category/tinytypes/
The documentation is copied shameless from https://github.com/jan-molak/tiny-types
Installation
To install the module from nuget : ... Install-Package TinyTypesObjects ...
Defining Tiny Types
An int on its own is just a scalar with no meaning. With an object, even a small one, you are giving both the compiler and the programmer additional information about what the value is and why it is being used.
Single-value types
To define a single-value TinyType
- extend from TinyType<T>()
:
If you want operator ==, please use TinyTypeOf or TinyTypeOfString
using TinyTypesObjects;
public class Age : TinyTypeOf<int>
{
public Age(int nr) : base(nr)
{
}
}
public class FirstName : TinyTypeOfString
{
public FirstName(string str) : base(str)
{
}
}
Every tiny type defined this way has
a get property value
of type T
, which you can use to access the wrapped primitive value. For example:
var firstName = new FirstName("Jan");
Assert.AreEqual(firstName.value , "Jan");
Converting from / to original values
There are defined conversions between type T
and the class
public void TestConvert()
{
string s = "http://msprogrammer.serviciipeweb.ro";
TinyTypeOfString tt = s;
Assert.AreEqual(s, (string)tt);
int nr = 7;
TinyTypeOf<int> tt1 = nr;
Assert.AreEqual(nr, (int)tt1);
}
so the following code should work for the class with constructor string
class TestConstructor
{
public TestConstructor(string firstName)
{
FirstName = firstName;
}
public string FirstName { get; }
}
[TestMethod]
public void TestConstructor()
{
var firstName = new FirstName("Jan");
TestConstructor tc = new TestConstructor(firstName);
Assert.AreEqual(tc.FirstName, "Jan");
}
Equals or ==
Each tiny type object has an equals
method, which you can use to compare it by value:
int nr = 7;
TinyTypeOf<int> tt1 = nr;
TinyTypeOf<int> tt2 = nr;
Assert.AreEqual(tt1, tt2);
Assert.IsTrue(tt1 == tt2);
Links:
GitHub: https://github.com/ignatandrei/tinyTypes
Blog About: http://msprogrammer.serviciipeweb.ro/category/tinytypes/
Product | Versions 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 was computed. 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. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 1 .0.2.0 - just definition + equals + operator ==