|
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 />
<br />
default:<br />
resolvedType = typeof(string);<br />
break;<br />
}<br />
<br />
return resolvedType;<br />
}<br />
|
|
|
|
|
Hi,
you could use a HashTable to map all the DAOColumnDataType values to
their corresponding types. The table needs to be constructed only once.
If the key exists, the value is the type; if not (which corresponds to
the default case in your switch), typeof(string) is what you want.
Furthermore, if all DAOColumnDataType.ad### constants are integers within a
small range, you could even consider an array of types and use dataType
as the index (probably with a try-catch to catch excessive index values);
any intermediate non-existing ad### values should result in typeof(string).
Hope this helps
|
|
|
|
|
That was kind of what I was going for with the generic Dictionary (Dictionary<int, type="">). It just sucks up a bit of memory that I couldn't justify since the method may only be called rarely (the other scenario is that it would be used constantly).
Some of the items are continuous in their values specifically 2-7, 11, 14, 16, 20, 72, 129, 131, 133-135, and 200 are the ones handled. Doesn't seem to be any pattern there to me. Although an array would suck up the memory too. I'd probably do that in a static implementation; but, wouldn't matter anyway since System.Type objects are never garbage collected.
|
|
|
|
|
tgrt wrote: System.Type objects are never garbage collected
I dont know; seems to make sense tho.
If so, an array approach only costs 4 (or 8) B per entry, since the types exist
whatever approach you take. Hence less than 1KB. Way to go !
|
|
|
|
|
Yeah, I guess that might work the Dictionary/Hashtable approach. An array wouldn't work, because of the large spread of values. I'm creating less than 20 System.Type objects. I guess I should factor in the smaller amount of code loaded into memory.
|
|
|
|
|
I would go for the array, something like:
Type[] daTypes=new Type[256];
...
for(int i=0; i<256; i++) daTypes[i]=typeof(string);
daTypes[daConstant]=typeof(something);
...
if ((val & 255)!=val) {
type=typeof(string);
} else {
type=daTypes[val];
}
so there is even no need to try-catch;
only 1KB of data, and much faster than switch or HashTable.
|
|
|
|
|
How can I block a user from accessing a specific drive or directory??
Johnny
|
|
|
|
|
If you use:
System.IO.File.Encrypt("filename.txt")
or
<br />
DirectoryInfo d = new DirectoryInfo("C:\newfolder")<br />
d.SetAccessControl(...<br />
You can ensure that the user account that runs this code is the only one able to access the contents.
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
|
|
|
|
|
Hello,
Have no idea why you got downvoted, got my "5" to bring it back in shape.
I'm always a little pissed if somebody is doing so without any commend! (helps nobody)
All the best,
Martin
|
|
|
|
|
I didn't do it, but it would appear that his solutions didn't address the question asked at all.
They specified encrypting files or setting permissions on folders, but the question asked how to block access to entire drives and folders.
Encryption won't really help at all. Setting permissions will, but is difficult to manage, depending on the requirements of the application.
|
|
|
|
|
Dave Kreskowiak wrote: that his solutions didn't address the question asked at all.
I do recognized that half of his answere would not help sofing the question, but permission is a way to do it (at least he could try it).
Dave Kreskowiak wrote: I didn't do it
I would always expect a statement from you which helps also the one who answered the question.
That's one of the reasons I'm answering questions here (never stop learning!)
All the best,
Martin
|
|
|
|
|
In your code - you don't do anything. This is best left up to Group Policies. Pickup the Resource Kits for Windows XP or Windows Server 2003 and it's explained ad nauseum.
|
|
|
|
|
Hi all,
I created an MDI application, still with .NET Framework 1.1, and a child form has a user control in which is defined a AxWebBrowser control.
I wanted to disable Ctrl+N and Ctrl+P keystrokes, so I implemented the MsHtmlHstInterop.IDocHostUIHandler interface on the user control and changed the TranslateAccelerator method to do so, but it doesn't seem to be called.
Everything's working with no MDI application.
Could you help me, please?
Thanks.
Daniele Camanni.
|
|
|
|
|
Hi,
I am new to sharepoint technology. can anyone give me a sample C# code to access the sharepoint/wss3.0 site from remote machine without using Web Service.
Thanks
Ramamurthi
ramamurthic@gmail.com
|
|
|
|
|
Hi,
I have some textboxes on a tabpage using binding to show data, but it seems that the Text property of my textboxes are empty when they are on a not visible tabpage. (when the textboxes are visible the value of the text property is OK)
After switching to the tabpage, the field data is shown in the textbox and the text property is also OK.
------------------------------
The problem i have now is, that the component to verify the "Text" entered by the users gives a fault because some fields are empty..
and they are not because the dataset has only been set to modify...
(when switching to all tabs without modifying data i can post the row again.)
Has anyone a solution, a suggestion for this or do i need to workaround the problem ...
Thx
Kurt
|
|
|
|
|
hi ,
can any body tell why is the error fail to load view state in grid view in c#.net
|
|
|
|
|
I wasn't to find this in any of the previous posts, so I am adding a new topic. If anyone knows of other websites to check, please let me know. My e-mail address is at the bottom.
I am unable to diff a Designer.cs file (Compare with Previous Version) in the 2005 .NET IDE. Is there a setting that I am missing? I swear this use to work before adding the patch and update. Of course, it could also be a problem with Clear Case. I should post something there instead.
Thanks in advance.
Matt Arthur
SW Engineer
Quality Vision International
mta@qvii.com
-- modified at 8:22 Wednesday 30th May, 2007
|
|
|
|
|
if we create an Graphics object named graph, use it to draw shap or any other thing.
what would happen if i didn't used graph.Flush(),and graph.Dispose() after finish using
the graph object.
thanks in advance
Hussam
|
|
|
|
|
I'm not sure about what Flush does in this context, but if it is like a file then it won't necessariliy complete the rendering until some later stage.
Dispose is easier because it is a well defined interface. If you fail to call Dispose the garbage collector will dispose the object at some later stage. However, if an object has a Dispose method or implements IDisposable then you should be disposing it because it means the object had unmanaged or scarce resources which need to be freed up. Failing to free the resource in a timely manner may cause your application to perform poorly or crash (the resource be become exhausted and the garbage collector won't know anything about it)
|
|
|
|
|
Hello
I want to send single/multiple folders to single/multiple users with in a network. Reply me asap.
Devesh Mishra
|
|
|
|
|
devesh_code wrote: I want to send single/multiple folders to single/multiple users with in a network.
What do you mean by that?
|
|
|
|
|
Heyyy
I want to send folder(s) on another computer in the network to single as well as multiple users.
Devesh Mishra
|
|
|
|
|
devesh_code wrote: I want to send folder(s) on another computer
By send do you mean move or copy?
devesh_code wrote: to single as well as multiple users
Users are not a valid destination for a folder. Other folders are.
Now where do you actually want to send the folders?
|
|
|
|
|
Hi,
Here, If you share the folder at the remote PC and use Copy functions etc. it will work similarly as it works on Local PC.
Manoj
Never Gives up
|
|
|
|
|
Hi
Actually i am able to send file without sharing and i also want to send folder also like that.
One way can be zip it and then send it and at the other end unzip it but it will take more time, this also i am not getting properly.
plz...
Devesh Mishra
|
|
|
|