public class Emp :Classes.Repository<Emp> { private int srl; public int Srl { set { srl = value; } get { return srl; } } private string name; public string Name { set { name = value; } get { return name; } } }
public class Repository<T> : IRepository<T> where T : class { public SDataAccess Conn { get; private set; } public void Save(T entity) { if (entity == null) { throw new ArgumentNullException("entity", "Add to DB null entity"); } //extention Methods var res = Conn.Save(entity); } public IEnumerable<T> GetAll() { throw new NotImplementedException(); } }
public void Save() { if (this == null) { throw new NullReferenceException("Add to DB null entity"); } else { Console.WriteLine("save action!"); } }
Emp m = null; m.Save(); //here - NullReferenceException!
Repository
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)