Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
SuggestionRe: sockets + Cryptography Pin
AlphaDeltaTheta10-May-13 15:35
AlphaDeltaTheta10-May-13 15:35 
GeneralRe: sockets + Cryptography Pin
Member 997361610-May-13 22:50
Member 997361610-May-13 22:50 
GeneralRe: sockets + Cryptography Pin
AlphaDeltaTheta11-May-13 16:38
AlphaDeltaTheta11-May-13 16:38 
Questionwhats the best practice to save service data? Pin
neodeaths10-May-13 9:18
neodeaths10-May-13 9:18 
AnswerRe: whats the best practice to save service data? Pin
Dave Kreskowiak10-May-13 10:49
mveDave Kreskowiak10-May-13 10:49 
AnswerRe: whats the best practice to save service data? Pin
Eddy Vluggen11-May-13 3:30
professionalEddy Vluggen11-May-13 3:30 
QuestionProperties vs Methods Opinions sought Pin
Keith Barrow10-May-13 4:22
professionalKeith Barrow10-May-13 4:22 
SuggestionRe: Properties vs Methods Opinions sought Pin
Richard Deeming10-May-13 5:16
mveRichard Deeming10-May-13 5:16 
Keith Barrow wrote:
public string RedemptionCode
{
   get
   {
      if(Code.HasValue)
         return BatchCode + RedemptionCode;
      return "";
   }
}

I hope that's a typo, otherwise you've got infinite recursion in your property getter.

I agree with making the setters for Code and BatchCode private, since you need to set them both at once, and you can only set them once. Similarly, you can't use a setter to replace the SetClaimedCode method, since it needs two values.

I'd be inclined to leave the GetClaimedCode as a read-only property, and rename the SetClaimedCode method to something like Claim or Redeem. If the code parameter is required, I'd also make it an int rather than a Nullable<int>. Also, attempting to redeem the voucher twice isn't really a problem with an argument, so an ArgumentException isn't appropriate.
C#
public string RedemptionCode
{
   get
   {
      return Code.HasValue ? BatchCode + Code : string.Empty;
   }
}

public void Claim(string batch, int code)
{
   if (Code.HasValue) throw new InvalidOperationException("Voucher has already been claimed.");
   
   Code = code;
   BatchCode = batch;
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Properties vs Methods Opinions sought Pin
Keith Barrow10-May-13 5:37
professionalKeith Barrow10-May-13 5:37 
GeneralRe: Properties vs Methods Opinions sought Pin
jschell10-May-13 7:58
jschell10-May-13 7:58 
AnswerRe: Properties vs Methods Opinions sought Pin
jschell10-May-13 7:50
jschell10-May-13 7:50 
GeneralRe: Properties vs Methods Opinions sought Pin
Ennis Ray Lynch, Jr.10-May-13 8:41
Ennis Ray Lynch, Jr.10-May-13 8:41 
GeneralRe: Properties vs Methods Opinions sought Pin
jschell13-May-13 7:58
jschell13-May-13 7:58 
AnswerRe: Properties vs Methods Opinions sought Pin
PIEBALDconsult10-May-13 18:32
mvePIEBALDconsult10-May-13 18:32 
GeneralPracticing Code Logic Pin
N8tiv10-May-13 3:24
N8tiv10-May-13 3:24 
GeneralRe: Practicing Code Logic Pin
Richard MacCutchan10-May-13 3:48
mveRichard MacCutchan10-May-13 3:48 
Questionxmpp Pin
Member 1004242210-May-13 2:20
Member 1004242210-May-13 2:20 
AnswerRe: xmpp Pin
Pete O'Hanlon10-May-13 2:34
mvePete O'Hanlon10-May-13 2:34 
AnswerRe: xmpp Pin
Richard MacCutchan10-May-13 3:44
mveRichard MacCutchan10-May-13 3:44 
QuestionAbout xmpp n bosh server Pin
Member 1004242210-May-13 1:46
Member 1004242210-May-13 1:46 
AnswerRe: About xmpp n bosh server Pin
Pete O'Hanlon10-May-13 2:13
mvePete O'Hanlon10-May-13 2:13 
QuestionExport to PST Pin
JD869-May-13 14:29
JD869-May-13 14:29 
QuestionProper Use of a Semaphore Pin
Richard Andrew x649-May-13 14:14
professionalRichard Andrew x649-May-13 14:14 
AnswerRe: Proper Use of a Semaphore Pin
SledgeHammer019-May-13 17:05
SledgeHammer019-May-13 17:05 
GeneralRe: Proper Use of a Semaphore Pin
Richard Andrew x6410-May-13 6:10
professionalRichard Andrew x6410-May-13 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.