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

C#

 
AnswerRe: win32 dll is not working for c# application. Pin
Thomas Krojer5-Jul-11 22:03
Thomas Krojer5-Jul-11 22:03 
GeneralRe: win32 dll is not working for c# application. Pin
Le@rner5-Jul-11 22:09
Le@rner5-Jul-11 22:09 
GeneralRe: win32 dll is not working for c# application. Pin
Thomas Krojer5-Jul-11 23:31
Thomas Krojer5-Jul-11 23:31 
QuestionDataGridView Cell Color Pin
Miwin Solutions5-Jul-11 6:31
Miwin Solutions5-Jul-11 6:31 
AnswerRe: DataGridView Cell Color Pin
Abhinav S5-Jul-11 7:05
Abhinav S5-Jul-11 7:05 
AnswerRe: DataGridView Cell Color Pin
GenJerDan5-Jul-11 8:22
GenJerDan5-Jul-11 8:22 
GeneralRe: DataGridView Cell Color Pin
Miwin Solutions5-Jul-11 11:59
Miwin Solutions5-Jul-11 11:59 
QuestionDatagridview data entry Pin
bugindia5-Jul-11 2:33
bugindia5-Jul-11 2:33 
AnswerRe: Datagridview data entry Pin
Carmelo La Monica5-Jul-11 11:04
professionalCarmelo La Monica5-Jul-11 11:04 
QuestionCoding style II - O(n) checks instead O(1) or doubling code? [modified] Pin
Lutosław5-Jul-11 1:06
Lutosław5-Jul-11 1:06 
AnswerRe: Coding style II - O(n) checks instead O(1) or doubling code? Pin
Pete O'Hanlon5-Jul-11 1:21
mvePete O'Hanlon5-Jul-11 1:21 
GeneralRe: Coding style II - O(n) checks instead O(1) or doubling code? Pin
Lutosław5-Jul-11 1:38
Lutosław5-Jul-11 1:38 
AnswerRe: Coding style II - O(n) checks instead O(1) or doubling code? Pin
Pete O'Hanlon5-Jul-11 2:48
mvePete O'Hanlon5-Jul-11 2:48 
GeneralRe: Coding style II - O(n) checks instead O(1) or doubling code? Pin
kevinnicol5-Jul-11 10:10
kevinnicol5-Jul-11 10:10 
GeneralRe: Coding style II - O(n) checks instead O(1) or doubling code? Pin
Pete O'Hanlon5-Jul-11 10:15
mvePete O'Hanlon5-Jul-11 10:15 
AnswerRe: Coding style II - O(n) checks instead O(1) or doubling code? Pin
PIEBALDconsult5-Jul-11 3:13
mvePIEBALDconsult5-Jul-11 3:13 
AnswerRe: Coding style II - O(n) checks instead O(1) or doubling code? Pin
BobJanova5-Jul-11 3:30
BobJanova5-Jul-11 3:30 
The two loops set off my code style alarms. But having reviewed it, and worked out the domain here, it really is two separate operations, and there's not much there that is common enough to pull out. When it comes down to it you're duplicating four lines:
for(int i = 0; i < symbolCount; i++) {
 staff.AddVisual(something);
 staff.AddVisual(PlaceHolderVisual.ThinPlaceholder);
}


So I think I would leave it, but with a note (mental or explicit) to watch this space because if you add more key signature related stuff it could get messy and need refactoring.


Now you could take the duplication out like this:
void AddSharpsAndFlats(StaffVisual staff, Clef clef)
{
  int symbolCount = _context.GetSharpCount();

  if(symbolCount != 0){
    // I guess this is List<Position> or Position[]
    var Positions = symbolCount > 0 ? clef.SharpPositions : clef.FlatPositions;
    var Order = symbol.Count > 0 ? MusicContext.SharpOrder : MusicContext.FlatOrder;
    VisualCreator creator = symbolCount > 0 ? (p => new SharpVisual(p)) : (p => new FlatVisual(p));
    
    symbolCount = symbolCount > 0 ? symbolCount : -symbolCount; // abs for ints
    
    for (int i = 0; i < symbolCount; i++)
    {
      staff.AddVisual(creator( {
        Position = Positions[(int)Order[i]]
      });
      staff.AddVisual(PlaceHolderVisual.ThinPlaceholder);
    }
  }
}


... where
delegate VisualCreator(Position position);


(You could also have a VisualFactory that hides that selection away from you.)

I'm not convinced that for such a small duplication this is worthwhile.
QuestionWork with Web cam Pin
Abbath13495-Jul-11 0:31
Abbath13495-Jul-11 0:31 
AnswerRe: Work with Web cam Pin
Richard MacCutchan5-Jul-11 6:28
mveRichard MacCutchan5-Jul-11 6:28 
AnswerRe: Work with Web cam Pin
GuyThiebaut5-Jul-11 10:21
professionalGuyThiebaut5-Jul-11 10:21 
QuestionString value in C# Pin
Pierre besquent5-Jul-11 0:13
Pierre besquent5-Jul-11 0:13 
AnswerRe: String value in C# Pin
Richard MacCutchan5-Jul-11 0:22
mveRichard MacCutchan5-Jul-11 0:22 
GeneralRe: String value in C# Pin
Pierre besquent5-Jul-11 0:26
Pierre besquent5-Jul-11 0:26 
AnswerRe: String value in C# Pin
Rhuros5-Jul-11 0:46
professionalRhuros5-Jul-11 0:46 
GeneralRe: String value in C# Pin
Richard MacCutchan5-Jul-11 0:59
mveRichard MacCutchan5-Jul-11 0:59 

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.