Visual Studio Plugin?

  • Thread starter Thread starter alunharford
  • Start date Start date
A

alunharford

I've just written the following code 'by hand', and there has to be an
easier way...
Any ideas?

class GameStarted
{
public int gameNumber;
public string whiteName;
public string blackName;
public Wild wildType;
public RatingType ratingType;
public bool rated;
public int whiteInitialTime;
public int whiteIncTime;
public int blackInitialTime;
public int blackIncTime;
public bool notExamining;
public int whiteRating;
public int blackRating;
public long gameID;
public bool irregularLegality;
public bool irregularSemantics;
public bool usesPlunkers;
public string fancyTimeControl;

public GameStarted(int gameNumber, string whiteName, string
blackName, Wild wildType,
RatingType ratingType, bool rated, int whiteInitialTime,
int whiteIncTime,
int blackInitialTime, int blackIncTime, bool notExamining,
int whiteRating,
int blackRating, long gameID, bool irregularLegality, bool
irregularSemantics,
bool usesPlunkers, string fancyTimeControl)
{
this.gameNumber = gameNumber;
this.whiteName = whiteName;
this.blackName = blackName;
this.wildType = wildType;
this.ratingType = ratingType;
this.rated = rated;
this.whiteInitialTime = whiteInitialTime;
this.whiteIncTime = whiteIncTime;
this.blackInitialTime = blackInitialTime;
this.blackIncTime = blackIncTime;
this.notExamining = notExamining;
this.whiteRating = whiteRating;
this.blackRating = blackRating;
this.gameID = gameID;
this.irregularLegality = irregularLegality;
this.irregularSemantics = irregularSemantics;
this.usesPlunkers = usesPlunkers;
this.fancyTimeControl = fancyTimeControl;
}
}
 
<shameless_plug>
Check out CodeRush at http://www.devexpress.com/Products/NET/IDETools/CodeRush/Index.xml.
It has a rich template language for generating code. And one of those template
("cc") will generate a constructor with parameters and assignments from the
existing fields of a class. So, once you have the class defined, that template
will fill out the rest for you. You could define the class with a handful
of templates:

"c" -- define a new class.
"vi" -- define a field of type "int".
"vs" -- define a field of type "string".
"v." -- define a field that allows you to specify a type (for the "Wild"
and "RatingType" fields).
"vb" -- define a field of type "bool"
"cc" -- define a constructor.

If you're looking to generate code quickly -- CodeRush is the way to go.

I recommend checking out some of the training videos here: http://www.devexpress.com/Products/NET/IDETools/CodeRush/Training.xml.
</shameless_plug>

Best Regards,
Dustin Campbell
Developer Express Inc.
 
Yes, it is called OO and refactoring!

Try to antropomorphisize what you are trying to do. For example I can
immediatly see that there is a Game with 2 players, one white and one with a
black colour and I see timers.

class Game
{
int _gameNumber;
List<Player> _players;
...

public Game(List<Player> players)
{
_players = players;
...
}

DateTime Start()
{
...
}
...
}

class Player
{
string _name;
...

public Player(string name)
{
_name = name;
...
}
....
}


Gabriel Lozano-Morán
The .NET Aficionado
http://www.pointerx.net
 
Gabriel said:
Yes, it is called OO and refactoring!

Try to antropomorphisize what you are trying to do. For example I can
immediatly see that there is a Game with 2 players, one white and one with a
black colour and I see timers.

Alas, life isn't so simple! :-)
It's actually the argument for a multicast event. While I could declare
a struct to hold the name, rating, time and inc for each player, it
doesn't gain me much because I can't reuse them. :-(

Alun Harford
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top