jeudi 26 février 2015

c# Ternary operator

I am working on a an application that has no documentation (although the code is quite clear and well-written) and I am trying to write some useful technical documentation for the next guy who comes along after I am in a mental hospital.


In the web-service method, if the call to the web-service returns an error, then the Catch code runs to increment the number of retries for the message and set the MessageStatus to "New" (so that it is retried if less than 5) or "Error" (for unknown errors), but there is one line I am not completely sure of and I need to document this process properly:



catch (Exception ex)
{
int NoRetries = (int)dRow[(int)Common.OutboundSQLFields.Message_Retries];
string messageStatus = (NoRetries < 5) ? Common.MessageStatus(ex) : "Expired";
...


Does this mean that if the NoRetries is greater than 4, then the MessageStatus will be set to Expired, else the method Common.MessageStatus will be called to reset the string MessageStatus based on the value of (ex) ?


So to make it more self-describing, could I rewrite that Ternary operator code as:



string MessageStatus="";
If (NoRetries > 4)
{
MessageStatus = "Expired";
}
else
{
MessageStatus = Common.MessageStatus(ex);
}

Aucun commentaire:

Enregistrer un commentaire