Skip to content

Latest commit

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ValueObject

ValueObject is a micro library for easily creating C# classes with value semantics. The library provides an abstract base class that overrides Equals, GetHashCode, and the == and != operators. It also implements IEquatable.

Use

To create a value object, simply inherit from ValueObject. By default, two objects will be considered equal if they are the same type and all of their public properties and fields are equal.

To prevent a public property or field from being considered in memberwise comparisons, decorate it with an IgnoreMember attribute.

classCustomer:ValueObject{publicstringName{get;set;}publicintAge;privateintssn;//ignored in comparisons[IgnoreMember]publicstringAddress;//also ignored because of attribute}
varcustomer1=newCustomer{Name="John",Age=13,Address="California"};varcustomer2=newCustomer{Name="John",Age=13,Address="Florida"};Debug.Assert(customer1==customer2);

Use F# Records?

Are you sure you don't want to just create F# records in a F# project, and consume them from C#?

About

A micro library for easily creating C# classes with value semantics. No need to override Equals, GetHashCode, et all.

Resources

Stars

198 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages