Coder Social home page Coder Social logo

danmgs / valueobject Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jhewlett/valueobject

0.0 1.0 0.0 16 KB

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

License: MIT License

C# 100.00%

valueobject's Introduction

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.

class Customer : ValueObject
{
    public string Name { get; set; }
    public int Age;

    private int ssn;  //ignored in comparisons
    
    [IgnoreMember]
    public string Address;  //also ignored because of attribute
}
var customer1 = new Customer{ Name = "John", Age = 13, Address = "California" };
var customer2 = new Customer{ Name = "John", Age = 13, Address = "Florida" };

Debug.Assert(customer1 == customer2);

valueobject's People

Contributors

jhewlett avatar mbican avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.