All Questions
14 questions
1
vote
1
answer
79
views
simple LINQ refactoring / style
As LINQ Select() wants a FUNC<int,T> as argument, I have to define an unused variable.
I think query syntax makes that clearer in this case.
How do I get rid of any clutter to make that simple ...
0
votes
1
answer
67
views
How do I add to string, neatly, based on 2 fields if null
I have some code which works totally fine but it looks a little bit messy/smelly.
Is there a way I can do this in a much cleaner way?
ViewBag.PageName = "Search Results for ";
if (searchViewModel....
-2
votes
2
answers
110
views
Good pattern for multiphase algorithm?
Is there a pattern (refactoring) to improve this piece of code?
int phase = 0;
foreach (var some in arrayOfSome)
{
if (phase == 0)
{
bool result = ...
5
votes
2
answers
2k
views
Refactoring: Replace Method with Method Object explanation
I was looking for refactoring a too length method. Searching I found this technique: Replace Method with Method Object but I don't understand at all.
If the method to refactor is:
public class ...
0
votes
2
answers
60
views
C# tidy way to set long list of class values?
I have a class with 60 different strings in it. I need to fetch the strings from an API where they have one name, save them and then insert them into to a database where they have another name.
So my ...
0
votes
1
answer
66
views
C# right way implement generic method
I have some repeated pieces of code. This contradicts with DRY principe. But i don't know how replace this with generic method.
class Foo
{
public bool isFirstAttribHasRightValue;
public bool ...
0
votes
1
answer
76
views
Function that update his own variables
I want to know how should it be tested, because if I want to test one of them, it force me to put two assertions in each test (and it may grow up).
internal class Foo
{
public int A { get; set; }
...
0
votes
3
answers
249
views
Is it OK to change values of optional parameters
Changing parameter values is considered an anti-pattern, but I find it useful sometimes with optional parameters in C#:
public void Foo(int p1, MyClass fooObj = null)
{
if (fooObj == null)
{ ...
1
vote
0
answers
241
views
Nesting anonymous delegates in C# - how to make code maintainable and readable?
I'm making a game, and it may have modal UI windows, like popover windows.
I encapsulated all the fiddling into my class and I just call one method to show such window on screen, for example a method ...
0
votes
1
answer
416
views
Eliminating Ifs
I would like to eliminate ifs in my application, but i have hit a brick wall. Here is my code. The problem i am facing is that i bought into the idea of using a dictionary to do the switching, however,...
1
vote
4
answers
1k
views
Using Partial Classes to manage code, good solution?
Books usually say that if the classes get too big to manage, rethink the implementation because it is quite possible that the design needs correction since classes have not been defined properly.
But ...
2
votes
3
answers
175
views
Remove duplication from this snippet of code
Looking for advice in removing duplication from this snippet:
foreach (Car car in carList) {
DataRow row = NewRow();
StringBuilder sbConfigurations = new StringBuilder();
foreach (...
22
votes
10
answers
16k
views
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.
What I'm looking to know is the ...
4
votes
7
answers
577
views
In C# (or any language) what is/are your favourite way of removing repetition?
I've just coded a 700 line class. Awful. I hang my head in shame. It's as opposite to DRY as a British summer.
It's full of cut and paste with minor tweaks here and there. This makes it's a prime ...