Skip to content

Instantly share code, notes, and snippets.

@DerAlbertCom
Created August 3, 2010 11:34
Show Gist options
  • Save DerAlbertCom/506213 to your computer and use it in GitHub Desktop.
Save DerAlbertCom/506213 to your computer and use it in GitHub Desktop.
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