내가 구현처럼이 질문 :C# 4.0 선택적 매개 변수는
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")
{
//..
}
//..
}
내가 지정하고 때마다 keyPropertyName = (하드 코딩) "이드"그렇지 좋은 찾고 있습니다.
어떤 사람이 단지 한 곳에서 값 const string defaultKeyPropertyName = "Id"
을 선언 할 수있는 아이디어가 있습니다. 그런 다음 모든 곳에서 그런 식으로 사용하십시오.
//...
void Update<T>(T entity, string keyPropertyName = defaultKeyPropertyName) where T : class;
void Delete<T>(T entity, string keyPropertyName = defaultKeyPropertyName) where T : class;
//..
또는 다른 방법으로 처리 할 수 있습니까?
어떤 아이디어가 있습니까?
진술의 전반부는 정확하지만 상수는 (거의) 어디에서나 선언 할 수 있습니다. – grenade