I have an implementation like that:
public interface IGenericRepository
{
//...
void Update<T>(T entity, string keyPropertyName = "Id") where T : class;
void Delete<T>(T entity, string keyPropertyName = "Id") where T : class;
//...
}
public abstract class GenericRepositoryBase : IGenericRepository
{
//...
void Update<T>(T entity, string keyPropertyName = "Id") where T : class;
void Delete<T>(T entity, string keyPropertyName = "Id") where T : class;
//..
}
public class GenericRepository : GenericRepositoryBase
{
//..
public override void Update<T>(T entity, string keyPropertyName = "Id")
{
//..
}
public override void Delete<T>(T entity, string keyPropertyName = "Id")
{
//..
}
//..
}
Each time i am specifying(hard coding) keyPropertyName = “Id” it is looking not good.
May be some one has an idea how i may declare value const string defaultKeyPropertyName = "Id" just in one place and then everywhere just use like that.
//...
void Update<T>(T entity, string keyPropertyName = defaultKeyPropertyName) where T : class;
void Delete<T>(T entity, string keyPropertyName = defaultKeyPropertyName) where T : class;
//..
or it can be done somehow else?
any ideas?
You can use a
constif you want, and make a class that holds it. C# has no concept of a global variable, so this is as close as it will get: