ValueObjectCore 1.0.0

dotnet add package ValueObjectCore --version 1.0.0
NuGet\Install-Package ValueObjectCore -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ValueObjectCore" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ValueObjectCore --version 1.0.0
#r "nuget: ValueObjectCore, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ValueObjectCore as a Cake Addin
#addin nuget:?package=ValueObjectCore&version=1.0.0

// Install ValueObjectCore as a Cake Tool
#tool nuget:?package=ValueObjectCore&version=1.0.0

What is a value object?

A value object is a design pattern that represents an immutable object with equality based on its state, not its identity. This means that two value objects are equal if they have the same properties and values, regardless of their references. For example, two money objects with the same amount and currency are equal, even if they are different instances.

A value object has the following characteristics:

  • It is immutable, meaning that its state cannot be changed after creation
  • It has no identity, meaning that it does not have a unique identifier or a reference to another object
  • It is self-contained, meaning that it does not depend on external resources or services
  • It is comparable, meaning that it can be compared with other value objects of the same type

Value object base class in C#

After referencing this project or using its Nuget package, you have the option to inherit from the ValueObject class, like:

public sealed class SampleValueObject : ValueObject
{
    public string PropertyOne { get; set; } = "Value1";

    public int PropertyTwo { get; set; } = 2;

    public override IEnumerable<object> GetAtomicValues()
    {
        yield return PropertyOne;
        yield return PropertyTwo;
    }
}

After defining the SampleValueObject class, you can write a sample xUnit unit test for the preceding class:

[Fact]
public void Equals_WhenCalledWithEqualValueObjects_ReturnsTrue()
  {
      // Arrange
      var valueObject1 = new SampleValueObject();
      var valueObject2 = new SampleValueObject();

      // Act
      var result = valueObject1.Equals(valueObject2);

      // Assert
      Assert.True(result);
  }

Contribution

You are encouraged to contribute to this project by forking it or giving it a star if you find it valuable 😃

Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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 Downloads Last updated
1.0.0 129 8/5/2023