|
Even an experienced programmer makes mistakes, and it's said that the average programmer makes an error in every 10 lines of code. Static code-analysis doesn't cost much, just some CPU-time.
John Simmons / outlaw programmer wrote: and often does more harm than good in its recommendations.
It's not meant to be followed blindly; it's an analysis, and could help in identifying potential problems. I do like to argue about the recommendations, and fortunatly Microsoft provides a rationale for every rule - meaning one can disable the entire rule if the rationale doesn't apply.
..I might be a 'bit' biased though; made it a part of the daily-build proces
Bastard Programmer from Hell
|
|
|
|
|
Sure but I like to make sure my code and other team members meet a standard.
Also I worked on a very old slow system a while ago and ran FxCop over it. Something like 2,000 performance issues were highlighted, most you wouldn't pick up by just reading the code. Fixed them all and got a 12% performance boost! Ok, it's not a profiler but still worth using periodically.
"You get that on the big jobs."
|
|
|
|
|
Integrating FXCop into Visual Studio will do no good because you want to use it (FXCop) *before* building, but not as part of the build process. Just add it to your external tools menu and be done with it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Some IDE's have something similar integrated; Code Analysis[^] from the IDE, seems to return the same information. Isn't available in my IDE at home - different version probably.
Bastard Programmer from Hell
|
|
|
|
|
No.I got some tools likes Fxcop runner and Fxcop integrator.Its doing a nice job.
|
|
|
|
|
Cool, FxCop Runner[^] provides an integration that's comparable to the built-in code-analysis. Going to try it tonight
Bastard Programmer from Hell
|
|
|
|
|
Hello,
There namespace Company.Service01, which contains classes and interfaces.
There namespace Company.Service02, which contains classes and interfaces.
Both spaces have the same structure of, contain the same classes and interfaces.
I need to somehow ensure that I could work with class (for example: Eso9PortClient) from this namespace,
depending on the input parameters of the program.
It's possible there is some technique to it?
The goal is that I did not have to repeat the same code n times the number of namespaces.
Example:
file01.cs
namespace Company.Service0X
{
public interface Eso9Port {...}
public partial class FaultInfo {...}
public interface Eso9PortChannel {...}
public partial class Eso9PortClient {...}
}
file02.cs
namespace Company
{
class Program
{
static void Main (string [] args)
{
if (args [0] == "01")
{
MultiService MultiService m = new ();
m.CreateOrder ();
}
else if (args [0] == "02")
{
MultiService MultiService m = new ();
m.CreateOrder ();
}
else if (args [0] == "03")
{
MultiService MultiService m = new ();
m.CreateOrder ();
}
}
}
public class MultiService
{
public void CreateOrder ()
{
// Work with the instance Company.Service0X.Eso9PortClient
// depending on the parameter in class Program
Company.Service0X.Eso9PortClient Company.Service0X.Eso9PortClient x = new ();
string xx = x.orders
...
}
}
}
Thank you in advance for your reply
|
|
|
|
|
Use an Abstract Factory pattern
|
|
|
|
|
Firstly, take out common code and put that in base classes in a base interface, and make sure that each implementation implements a common namespace. The main driver code shouldn't have to store references to any of the specific company namespaces. Then the problem simply comes down to creating an instance of the main object within one of the namespaces.
Depending on how flexible you want your system to be, and whether you permit runtime plugins, you either want a hard-coded factory:
class MultiServiceFactory {
IMultiService Create(string name){
if(name == "01") return new Company.Service01.MultiService();
else if(name == "02") return new Company.Service02.MultiService();
else throw new ArgumentException("Can't make a service for "+name);
}
}
... or you need to use reflection to look up the requested name ("Company.Service"+name+".ClassName") in either the current assemblies or loaded runtime plugin assemblies. I won't go into the entirety of plugin architecture in a Q&A reply, there are plenty of articles on CP about it.
|
|
|
|
|
Hello Experts,
I have assign work for creating add in for PowerPoint. In which i want toolbar in Powerpoint slide. So can any one pls help me for this issue.
I have no deep knowledge for Powerpoint Addins.
Thanks
If you can think then I Can.
|
|
|
|
|
|
I have a table, Models, in a database. It contains the following fields: ID (auto-generated; unique ID), Model Name (Text), Division (Text). I have a class, AuditRecord, which stores information about each record in another table, Audit Entry. It contains a field which looks values up from the Models table. How should I store a Models record in the AuditRecord class?
I am currently using:
<br />
Dictionary<int, Tuple<string, string>><br />
However, I am not sure this is the most efficient way to go about storing the data. Should I create a class with three properties corresponding to the three fields in the Models table? Or is my current method okay?
|
|
|
|
|
Matt U. wrote: Should I create a class with three properties corresponding to the three fields
in the Models table?
Yes.
|
|
|
|
|
Is the reason about maintainability/readability/encapsulation? Or is there more to it?
|
|
|
|
|
All of that and more.
Plus, not doing so is just lazy; there's no reason not to.
|
|
|
|
|
I figured as much. I'm not entirely sure as to why I didn't create a class to begin with. Thank you for the answer.
One more question: this means I should create classes for similar database objects as well, correct?
|
|
|
|
|
Probably. It depends on what you do with it. Most of the time a DataTable suffices for what I need to do.
|
|
|
|
|
Those and, particularly, extensibility. If you add another field to the table, it's easy to add another one to the class, but it would break all the existing code if it couldn't fit in a Tuple<string,string> any more.
|
|
|
|
|
I need to have one of my properties in a custom control to open the "open file dialogue" window when selected.
I have googled around but it keeps throwing me .net controls!
At present I have a property and when "set" opens the dialogue, but this forces me to enter some text and open it only when deselected...
Just to clarify:
1: Click on the property name in visual studio designer property area
2: it opens the open file dialogue
Thanks
|
|
|
|
|
What you're looking for is a custom PropertyEditor. Read up on it here[^].
|
|
|
|
|
Thanks
|
|
|
|
|
There is a built-in FileNameEditor which you can use as well.
<br />
[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]<br />
public string FileName<br />
{<br />
get<br />
{<br />
return _FileName;<br />
}<br />
set<br />
{<br />
_FileName = value;<br />
}<br />
}<br />
|
|
|
|
|
Hey guys,
I have a Form1 with a text box in it. When user clicks inside the text box it will pop up Form2 which has a MonthCalendar in it.
Now after the user selects a date and click OK on Form2, i want that selected date string to be displayed in the Form1 text box.
How can i get the Form2 date string to be displayed in Form1 text box?
Thanks in advance.
|
|
|
|
|
The way I do it :
On Form1 I listen for the Form2.FormClosed event like this
Form2 myForm2;
private void textBox1_TextChanged(object sender, EventArgs e)
{
myForm2 = new Form2();
myForm2.FormClosed += new FormClosedEventHandler(myForm2_FormClosed);
myForm2.Show();
}
Then when the event happens :
void myForm2_FormClosed(object sender, FormClosedEventArgs e)
{
this.TextBox1.Text = myForm2.TheDate;
}
On Form2 you need to have a Public property TheDate which you set when they click on your calendar
OnOkClick you just close the form.
hope that makes sense.
|
|
|
|
|