tagged [refactoring]

What keyboard shortcut is there to organize C# usings in Visual Studio?

What keyboard shortcut is there to organize C# usings in Visual Studio? Is there a way to organize C# usings (remove and sort, in separate or together) via a shortcut in Visual Studio for one or more ...

Ctrl+R, Ctrl+R command not working

Ctrl+R, Ctrl+R command not working I'm attempting to use the +, + command within Visual Studio 2008 to rename a variable. I get an error message at the bottom saying that "The key combination (+, +) i...

Catching specific exception

Catching specific exception How can I catch specific exception using c# ? In my database there is unique index on some columns. when user inserts duplicate record this exception has been throw : > Can...

25 May at 06:42

How can I implement my own type of extern?

How can I implement my own type of extern? In our product, we have things called "services" which are the basic means of communication between different parts of the product (and especially between la...

When does IDE0063 dispose?

When does IDE0063 dispose? I'm trying to understand this C# 8 simplification feature: > IDE0063 'using' statement can be simplified For example, I have: IDE tells me I can simplify this `usin

12 Aug at 14:24

Starting a new job focused on brownfield application refactoring & Agile

Starting a new job focused on brownfield application refactoring & Agile I am starting a new job on Monday. The company has a home grown enterprise case management application written in `ASP.NET/VB.N...

4 Jul at 10:3

How do you test/change untested and untestable code?

How do you test/change untested and untestable code? Lately I had to change some code on older systems where not all of the code has unit tests. Before making the changes I want to write tests, but ea...

7 Mar at 16:52

FluentValidation NotEmpty and EmailAddress example

FluentValidation NotEmpty and EmailAddress example I am using FluentValidation with a login form. The email address field is and . I want to display a custom error message in both cases. The code I h...

Why use decimal(int [ ]) constructor?

Why use decimal(int [ ]) constructor? I am maintaining a C# desktop application, on windows 7, using Visual Studio 2013. And somewhere in the code there is the following line, that tries to create a 0...

15 Apr at 14:14

Using Action dictionaries instead of switch statements

Using Action dictionaries instead of switch statements I'm just reviewing some of my old code (have some spare time), and I noticed a rather lengthy switch statement. Due to gaining new knowledge, I h...

Any way to surround code block with Curly Braces {} in VS2008?

Any way to surround code block with Curly Braces {} in VS2008? I always find myself needing to enclose a block of code in curly braces , but unfortunately that isn't included in the C# surround code s...

Is it better to create methods with a long list of parameters or wrap the parameters into an object?

Is it better to create methods with a long list of parameters or wrap the parameters into an object? Is it better(what is the best practice) to create methods with a long list of parameters or wrap th...

8 Apr at 09:23

Automatic way to put all classes in separate files

Automatic way to put all classes in separate files I've started to refactor/clean up big project. Some of files contains few small classes or few enums (yeah, it is very messy;/ ). Is there some metho...

1 Mar at 16:15

Tool to refactor C# var to explicit type

Tool to refactor C# var to explicit type Our coding standards ask that we minimise the use of C# var (suggests limiting it's use to being in conjunction with Linq). However there are times when using ...

14 Nov at 10:44

How to determine if a type is a type of collection?

How to determine if a type is a type of collection? I am trying to determine if a runtime type is some sort of collection type. What I have below works, but it seems strange that I have to name the ty...

2 Jun at 17:50

How to find unused/dead code in java projects

How to find unused/dead code in java projects What tools do you use to find unused/dead code in large java projects? Our product has been in development for some years, and it is getting very hard to ...

4 Aug at 05:44

How to avoid duplicate interface code?

How to avoid duplicate interface code? Since interfaces cannot contain implementation, that seems to me to lead to code duplication in the classes that inherit from the interface. In the example below...

21 Aug at 21:32

Replace Multiple String Elements in C#

Replace Multiple String Elements in C# Is there a better way of doing this... I've extended the string class to keep it down to one job but is there a quicker way? ``` public static class StringExtens...

10 Jun at 15:34

Refactoring if-else if - else

Refactoring if-else if - else I have the following code example My question is what design pattern can I use to make this better? Edit: Just to clarify a little better, the code you see here is someth

In C# how many lines before a class should be consider to be refactored?

In C# how many lines before a class should be consider to be refactored? A good rule of thumb by is that I intelligently refactor any method over 50 lines. The count does not include comments and whit...

11 May at 19:6

How would you refactor this smelly code? (Logging, Copy and Paste, .Net 3.5)

How would you refactor this smelly code? (Logging, Copy and Paste, .Net 3.5) I've got code like this: ``` Logger logger = new Logger(); System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics....

8 May at 16:29

Refactoring Code: When to do what?

Refactoring Code: When to do what? Ever since I started using .NET, I've just been creating Helper classes or Partial classes to keep code located and contained in their own little containers, etc. Wh...

23 May at 11:54

Automatic regenerate designer files

Automatic regenerate designer files Recently I've been making some improvements to a lot of the controls we use, for example give properties default values and making buttons private instead of protec...

Etiquette for refactoring other people's sourcecode?

Etiquette for refactoring other people's sourcecode? Our team of software developers consists of a bunch of experienced programmers with a variety of programming styles and preferences. We do not have...

5 Apr at 16:24

Python: avoiding Pylint warnings about too many arguments

Python: avoiding Pylint warnings about too many arguments I want to refactor a big Python function into smaller ones. For example, consider this following code snippet: Of course, this is a trivial ex...

4 Oct at 19:15