2012-03-21 3 views
-2

아래 그림과 같이 CN_에 항상 상수를 접두사로 사용하고 있지만 현재이 사이트에서 링크 된 것으로 인정되는 표준을 코딩하려고합니다. 표준은 내 상수에 대한 CN_을 삭제해야한다고 말합니다. 따라서 아래 예에서 CN_NetPrice를 NetPrice로 변경하면 같은 이름의 method 속성과 충돌이 발생합니다. 분명히 나는 ​​그것을 할 수 없기 때문에 나는 질문이 남아있다. 명명 규칙 문제가 있거나 일반적으로 내 코드에 문제가 있습니까? 열 이름의 변함없는 문자열이 나타내는 실제 속성을 다르게 지정해야합니다 -명명 규칙 문제 또는 코드 문제가 있습니까?

public class TicketInformation 
{ 
    private const string CN_StartDate = "StartDate"; 
    private const string CN_EndDate = "EndDate"; 
    private const string CN_NetPrice = "NetPrice"; 
    private const string CN_NetTotalPrice = "NetTotalPrice"; 
    private const string CN_Tickets = "Tickets"; 

    public decimal NetPrice { get; set; } 
    public decimal NetTotalPrice { get; set; } 
    public decimal Tickets { get; set; } 

    public static TicketInformation Create(DateTime startDate, DateTime endDate) 
    { 
     try 
     { 
      TicketInformation ti = new TicketInformation(); 
      using (DataTable dt = DAC.ExecuteDataTable(
       "GetAllTicketInformationSelect", 
       DAC.Parameter(CN_StartDate, startDate), 
       DAC.Parameter(CN_EndDate, endDate))) 
      { 
       ti.NetTotalPrice = Convert.ToDecimal(dt.Rows[0][CN_NetTotalPrice]); 
       ti.NetPrice = Convert.ToDecimal(dt.Rows[0][CN_NetPrice]); 
       ti.Tickets = Convert.ToDecimal(dt.Rows[0][CN_Tickets]); 
      } 
      return ti; 
     } 
     catch (Exception ex) 

     { 
      throw new Exception(Convert.ToString(ex)); 
     } 
    } 

} 

}

+0

저는 'NetPriceColumn'과 같은 상수를 부릅니다. –

+0

실제 문제가 무엇인지에 대한 정보를 제공하지 않았습니다. 당신은 솔루션 (2)이 무엇이라고 생각하는지에 대해서만 우리에게주었습니다. –

+0

제 문제는 명명 규칙을 따르는 경우 내 코드가 컴파일되지 않아 관습이나 코드를 이해하지 못하는 결과인지 확실하지 않습니다. –

답변

4

귀하의 상수는 이 아니며 실제로은 순 가격을 나타 냅니까? 그것은 순 가격 열의 이름을 나타냅니다.

private static class Columns 
{ 
    internal const string StartDate = "StartDate"; 
    internal const string EndDate = "EndDate"; 
    internal const string NetPrice = "NetPrice"; 
    internal const string NetTotalPrice = "NetTotalPrice"; 
    internal const string Tickets = "Tickets"; 
} 

또는 열거 사용 :

private const string StartDateColumn = "StartDate"; 
private const string EndDateColumn = "EndDate"; 
private const string NetPriceColumn = "NetPrice"; 
private const string NetTotalPriceColumn = "NetTotalPrice"; 
private const string TicketsColumn = "Tickets"; 

또는를 : 그래서 나도 제안의 이름을 줄 것이다 그 열거 형 값 중 하나에 ToString를 호출 ...

private enum Column 
{ 
    StartDate, EndDate, NetPrice, NetTotalPrice, Tickets; 
} 

합니다.

0

당신은 이름 지정 규칙에 문제가 있습니다.

5

여기 문제는 단순히 이름 선택이라고 생각합니다. 예를 들어 당신이 나쁜 이름이 될 것이 제출 한 사람에게 다음과 같은

private const string StartDate = "StartDate"; 

내 의견을 CN_을 제거하는 제안 된 변경을 가져 가라. 이것은 시작일이 아닙니다. 대신 정보를 표시 할 때 시작 날짜를 식별하거나 레이블을 지정하는 방식입니다. 당신은 문제가 사라질 것이다 상수 모두에이 논리를 적용하면 내가 대신 StartDateName

private const string StartDateName = "StartDate"; 

을 제안합니다.