Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Re-factoring
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01577083
Message ID:
01577122
Views:
64
This message has been marked as a message which has helped to the initial question of the thread.
>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.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform