Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Re-factoring
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01577083
Message ID:
01577123
Vues:
54
>>Hi everybody,
>>
>>I have a code that is done in a loop and it has continue statements (VFP loop analogue). Now, I want to take this inner logic of the loop and somehow made it another method which I am going to return as part of different procedure.
>>
>
>One of the biggest things you can do to start cleaning up that code is to wrap all of your data row stuff into its own class with nicer property names. Then have the constructor take a DataRow as a parameter and let it pull out all of the values, ex.
>
>
>public class LessonRow
>{
>   public string LessonCat { get; set; }
>   public int LessonType { get; set; }
>   public DateTime? StartTime { get; set; }
>   public DateTime? EndTime { get; set; }
>   // Repeat for the rest of the fields
>
>   public LessonRow(DataRow row)
>   { 
>      LessonType = row.Field<int>("lessontype");
>      // Repeat for the rest of the fields
>   }
>}
>
>
>Once you have that, call this with your row and replace all of your references (you'll find that you suddenly don't need a bunch of local variables and you eliminate all of the casts):
>
>
>   var dciInfo = dsDCI.Tables["csrDCIInfo"];
>   var lessonRow = new LessonRow(dciInfo.Rows[0]);
>
>
>From there, I'd extract out the different queries against the dtMax4SaleLimits DataTable into maybe 2 methods.
>
>Also, as a general rule, try to avoid creating methods with lots of "ref" or "out" parameters. If you have more than one seriously consider introducing a simple class with the properties you need and return that instead. You'll then find that instead of having 5 local vars that you have to set-up, you just get back one object (and that helps to clean up the code).
>
>Introduce a few constants, defines, or enums for that Logging class so you don't have those #s.

This sounds like a great idea, I am going to take another pass on that method.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform