Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to re-factor
Message
 
 
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:
01565975
Vues:
51
Check out ReSharper. It seems to be in every .NET developer's toolkit. You can download a free 30 day trial here.

http://www.jetbrains.com/resharper/

>Hi everybody,
>
>Recently I decided to use one exit point from my methods even though it leads to complicated code (sometimes) with multiple if else statements.
>
>I need to re-factor this code:
>
>
>SqlCommand sqlCommand = new SqlCommand();
>
>                    sqlCommand.CommandType = CommandType.Text;
>                    sqlCommand.CommandText = "select closedrwrs from dbo.prefs_sl;";
>
>                    if (database.ExecuteSqlCommand(sqlCommand, ref messageText, ref statusCode))
>                    {
>                        Int16 closeDrawers;
>                        if (Int16.TryParse(messageText, out closeDrawers))
>                        {
>                            if (closeDrawers < 2)
>                            {
>                                statusCode = 610;
>                                messageText = "System is not set up to close cash drawers";
>                            }
>                            // Ok to close a drawer
>                            else
>                            {
>                                sqlCommand.Parameters.Clear();
>                                String currentOperator, currentSalespoint, closeOperator, closeSalespoint, cDetails;
>                                currentOperator = GetParameterValue(parameters, "tcOperator");
>                                currentSalespoint = GetParameterValue(parameters, "tcSalespoint");
>                                cDetails = GetParameterValue(parameters, "tcDetails");
>                                closeOperator = cDetails.ParseStringFromSqml("CLOSE_OP");
>                                if (String.IsNullOrWhiteSpace(closeOperator))
>                                    closeOperator = currentOperator;
>                                closeSalespoint = cDetails.ParseStringFromSqml("CLOSE_SP");
>                                if (String.IsNullOrWhiteSpace(closeSalespoint))
>                                    closeSalespoint = currentSalespoint;
>                                DateTime startTime, endTime;
>                                startTime = cDetails.ParseDateTimeFromSqml("START_TIME");
>                                endTime = cDetails.ParseDateTimeFromSqml("END_TIME");
>                                String closeType;
>
>
>There are many lines of code below, but that first part is what is common between two different methods in VFP (where it's repeated as is in both methods).
>
>So, my question is - how can I make the above a separate method, but be able to re-use all these variables such as startTime, etc.
>?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform