TinyTypesObjects 1.0.2

Tiny types in C#
GitHub: https://github.com/ignatandrei/tinyTypes
Blog About: http://msprogrammer.serviciipeweb.ro/category/tinytypes/
NuGet: TinyTypesObjects

Install-Package TinyTypesObjects -Version 1.0.2
dotnet add package TinyTypesObjects --version 1.0.2
<PackageReference Include="TinyTypesObjects" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TinyTypesObjects --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Tiny types in C#

Build Status

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.

&dash; Jeff Bay, Object Calisthenics

Single-value types

To define a single-value TinyType - extend from TinyType&lt;T&gt;() :

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/

NuGet: https://www.nuget.org/packages/TinyTypesObjects/

Tiny types in C#

Build Status

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.

&dash; Jeff Bay, Object Calisthenics

Single-value types

To define a single-value TinyType - extend from TinyType&lt;T&gt;() :

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/

NuGet: https://www.nuget.org/packages/TinyTypesObjects/

Release Notes

Version 1 .0.2.0 - just definition + equals + operator ==

  • .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 History

Version Downloads Last updated
1.0.2 534 3/10/2018
1.0.1 364 3/10/2018
1.0.0 469 3/10/2018