Click here to Skip to main content
15,914,010 members
Home / Discussions / C#
   

C#

 
QuestionTimer Pin
MicealG29-May-07 6:06
MicealG29-May-07 6:06 
AnswerRe: Timer Pin
kubben29-May-07 6:30
kubben29-May-07 6:30 
AnswerRe: Timer Pin
Martin#29-May-07 6:31
Martin#29-May-07 6:31 
AnswerRe: Timer Pin
Dave Kreskowiak29-May-07 6:36
mveDave Kreskowiak29-May-07 6:36 
GeneralRe: Timer Pin
Martin#29-May-07 6:40
Martin#29-May-07 6:40 
GeneralRe: Timer Pin
Dave Kreskowiak29-May-07 7:02
mveDave Kreskowiak29-May-07 7:02 
AnswerRe: Timer Pin
Luc Pattyn29-May-07 9:37
sitebuilderLuc Pattyn29-May-07 9:37 
Questiondesign for a method with cyclomatic complexity issue Pin
tgrt29-May-07 5:58
tgrt29-May-07 5:58 
I have a conceptually simple method that gets a compiler warning (CA1502) regarding its cyclomatic complexity. The error tells me that the method has a complexity of 31 and I should reduce that to 25.

The problem is that the method isn't doing much, and the complexity is due to a switch block that maps an old DAO data type enumeration to a .NET type. For example, int for adInteger. The only thing else the code does is parse the input string into an integer. Overall, this method is part of a builder pattern based class that is responsible for taking a formatted string and converting it into a DataSet. The data comes through TCP from a legacy application that's output is based on a DAO Recordset.

At this point, I'm settling on ignoring the compiler warning, because the other options I've considered have consequences that outway the benefits. For example, implementing a look-up such as Dictionary<int, type=""> takes up memory unnecessarily. This method will either be called very rarely or very often.

Before I walk away from this, does anyone have any ideas for alternatives to this? I appreciate any advice.

Here is the code in question (I've removed some of the data types for brevity):

            private static Type GetColumnDataType(string data)<br />
            {<br />
              int typeValue;<br />
                   bool parsed = int.TryParse(data, out typeValue);<br />
<br />
                   if (!parsed)<br />
                          throw new FormatException(Properties.Resources.BuilderColumnFormatMismatch);<br />
<br />
                   DAOColumnDataType dataType = (DAOColumnDataType)typeValue;<br />
                   Type resolvedType;<br />
<br />
                   switch (dataType)<br />
                   {<br />
                          case DAOColumnDataType.adVarChar:<br />
                                 resolvedType = typeof(string);<br />
                                 break;<br />
<br />
                          case DAOColumnDataType.adBoolean:<br />
                                 resolvedType = typeof(bool);<br />
                                 break;<br />
<br />
                          case DAOColumnDataType.adInteger:<br />
                                 resolvedType = typeof(int);<br />
                                 break;<br />
<br />
                          case DAOColumnDataType.adDouble:<br />
                                 resolvedType = typeof(double);<br />
                                 break;<br />
<br />
                          case DAOColumnDataType.adDate:<br />
                         case DAOColumnDataType.adDBDate:<br />
                         case DAOColumnDataType.adDBTime:<br />
                         case DAOColumnDataType.adDBTimeStamp:<br />
                                 resolvedType = typeof(DateTime);<br />
                                 break;<br />
<br />
                          // removed some case statements for brevity<br />
<br />
                          default:<br />
                                 resolvedType = typeof(string);<br />
                                 break;<br />
                   }<br />
<br />
                   return resolvedType;<br />
            }<br />

AnswerRe: design for a method with cyclomatic complexity issue Pin
Luc Pattyn29-May-07 9:46
sitebuilderLuc Pattyn29-May-07 9:46 
GeneralRe: design for a method with cyclomatic complexity issue Pin
tgrt29-May-07 10:29
tgrt29-May-07 10:29 
GeneralRe: design for a method with cyclomatic complexity issue Pin
Luc Pattyn29-May-07 10:52
sitebuilderLuc Pattyn29-May-07 10:52 
GeneralRe: design for a method with cyclomatic complexity issue Pin
tgrt29-May-07 11:13
tgrt29-May-07 11:13 
GeneralRe: design for a method with cyclomatic complexity issue Pin
Luc Pattyn29-May-07 12:21
sitebuilderLuc Pattyn29-May-07 12:21 
QuestionBlock Access Pin
Saiyed Alam29-May-07 5:57
Saiyed Alam29-May-07 5:57 
AnswerRe: Block Access Pin
MicealG29-May-07 6:31
MicealG29-May-07 6:31 
GeneralRe: Block Access Pin
Martin#29-May-07 6:47
Martin#29-May-07 6:47 
GeneralRe: Block Access Pin
Dave Kreskowiak29-May-07 7:08
mveDave Kreskowiak29-May-07 7:08 
GeneralRe: Block Access Pin
Martin#29-May-07 7:14
Martin#29-May-07 7:14 
AnswerRe: Block Access Pin
Dave Kreskowiak29-May-07 7:05
mveDave Kreskowiak29-May-07 7:05 
QuestionAxWebBrowser in a user control, in a MDI application Pin
dcamanni29-May-07 5:41
dcamanni29-May-07 5:41 
QuestionSharepoint/WSS 3.0 Pin
Ramamurthi29-May-07 4:35
Ramamurthi29-May-07 4:35 
QuestionBinding : Text property empty when control invisible Pin
topcatalpha29-May-07 3:25
topcatalpha29-May-07 3:25 
Questionfail to load view state Pin
tauras8129-May-07 3:17
tauras8129-May-07 3:17 
QuestionDesigner.cs files and Clear Case [modified] Pin
mtaNY29-May-07 2:58
mtaNY29-May-07 2:58 
QuestionUsing Flush and Dispose on grapichs object ! Pin
Hussam Fattahi29-May-07 2:41
Hussam Fattahi29-May-07 2:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.