Created
August 3, 2010 11:34
-
-
Save DerAlbertCom/506213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel.DataAnnotations; | |
namespace Regularly.DomainObjects | |
{ | |
public abstract class DomainObject | |
{ | |
protected DomainObject() | |
{ | |
} | |
public virtual void Initialize() | |
{ | |
Created = DateTime.UtcNow; | |
Updated = Created; | |
} | |
public int Id { get; private set; } | |
public DateTime Created { get; private set; } | |
public DateTime Updated { get; private set; } | |
protected void Modified() | |
{ | |
Updated = DateTime.UtcNow; | |
} | |
private bool Equals(DomainObject other) | |
{ | |
return other.Id == Id; | |
} | |
public override bool Equals(object obj) | |
{ | |
if (ReferenceEquals(null, obj)) | |
{ | |
return false; | |
} | |
if (ReferenceEquals(this, obj)) | |
{ | |
return true; | |
} | |
if (GetType()!= obj.GetType()) | |
{ | |
return false; | |
} | |
return Equals((DomainObject) obj); | |
} | |
public override int GetHashCode() { | |
return string.Format("{0}({1})", GetType().Name, Id).GetHashCode(); | |
} | |
public static bool operator ==(DomainObject left, DomainObject right) | |
{ | |
return Equals(left, right); | |
} | |
public static bool operator !=(DomainObject left, DomainObject right) | |
{ | |
return !Equals(left, right); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment