Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to re-factor
Message
De
14/02/2013 11:46:43
Thomas Ganss (En ligne)
Main Trend
Frankfurt, Allemagne
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01565967
Message ID:
01566022
Vues:
43
If you operate on variables, you could
= GetCurrentandClose((parameters, "tcOperator", "CLOSE_OP", cCurrentOperator, cCloseOperator);
= GetCurrentandClose((parameters, "tcSalespoint", "CLOSE_SP", cCurrentSalespoint, cCloseSalespoint);

function GetCurrentandClose(parameters, in string cCurrentTag, in string cCloseTag, out string cCurrent, out string cClose) {
        cCurrent = GetParameterValue(parameters, cValueTag);
        cClose = cDetails.ParseStringFromSqml(cCloseTag);
                        if (String.IsNullOrWhiteSpace(cClose))
                            cClose = cCurrent; 
};
As you have good naming conventions in the part shown, you could use a Dictionay and string functions for all keys, names and so on, but that borders on being script/vfp like and not statically typed and all. Of course the same approach would work with massaging the property names for a class based solution. Signature is MUCH nicer if you are certain that this pattern is always well named, or if you encounter less well named instances, it is a good time for overloading and calling the base functionality.

function GetCurrentandClose(parameters, in string cTag){
return GetCurrentandClose(parameters, cTag, "CLOSE_" + cTag.SubString(cTag.Length - 2))
}
function GetCurrentandClose(parameters, in string cTag, in string cCloseTag){
}

Stuffing Current and Close into a Tuple is another option which is not really off base from the code shown here -
they have each a common trait and separate points of existance...

HTH

thomas

>>>It actually also needed closeSalespoint and closeOperator. I sent both as out parameters but I was thinking I may create the above as a class instead with these properties. Do you think it will be a better solution or 4 out parameters is not bad?
>>
>>
>>Dunno - there are several ways
>>
>>Viv's personal limit is about 5
>>Another option mentioned is to have the method return a Tuple - only inconvenience of a tuple is that the properties do not have meaningful names
>>
>>Another option suggested is to create a class. I would opt for a private nested class in that case
>
>Can you show how the private nested class idea looks like, please?
>
>This is what I currently have (last night did a few re-factoring operations). Thought today to keep re-factoring, but got some other work to do (in VFP).
>
>
>private void ParseDetails(String cDetails, String currentOperator,
>    String currentSalespoint, out String closeOperator, out String closeSalespoint, out DateTime startTime, out DateTime endTime)
>{         
>            closeOperator = cDetails.ParseStringFromSqml("CLOSE_OP");
>            if (String.IsNullOrWhiteSpace(closeOperator))
>                closeOperator = currentOperator;
>            closeSalespoint = cDetails.ParseStringFromSqml("CLOSE_SP");
>            if (String.IsNullOrWhiteSpace(closeSalespoint))
>                closeSalespoint = currentSalespoint;
>
>            startTime = cDetails.ParseDateTimeFromSqml("START_TIME");
>            endTime = cDetails.ParseDateTimeFromSqml("END_TIME");
>}
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform