view Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs @ 254:478656b70afb

Tag deploy 2011-10-07 v1.0.3 para conjunto de cambios 7cf64cd790ab añadido
author Administrador@DESA-WIN-002.cpe.telecentro.net.ar
date Mon, 17 Oct 2011 07:41:32 -0300
parents 2d1adbaf0373
children
line wrap: on
line source

using System;
using System.Collections.Generic;
using AltNetHispano.Agendas.Domain;

namespace AltNetHispano.Agendas.Repositories.Memory
{
	public class RepositoryBase<T> where T : Identificable
	{
		protected static readonly IDictionary<Guid, T> Objects = new Dictionary<Guid, T>();

		public T Get(Guid id)
		{
			T value;
			return Objects.TryGetValue(id, out value) ? value : null;
		}

		public void Save(T obj)
		{
			if (obj.Id==Guid.Empty)
			{
				var setter = typeof (Identificable).GetProperty("Id");
				setter.SetValue(obj, Guid.NewGuid(), null);
			}

			if (!Objects.Keys.Contains(obj.Id))
				Objects.Add(obj.Id, obj);
		}

		public void Delete(T obj)
		{
			Objects.Remove(obj.Id);
		}


	}
}