Prev | Current Page 357 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

For instance, the Windows Presentation Foundation version of
the Snippy application has Extensible Application Markup Language (XAML) files
that describe the user interface. When the project is built, each XAML file is converted
into a C# file in the obj directory (the filenames end with ???.g.cs??? to show they??™ve been
generated) and compiled along with the partial class providing extra code for that
type (typically event handlers and extra construction code). This completely prevents
developers from tweaking the generated code, at least without going to extreme
lengths of hacking the build file.
I??™ve been careful to use the phrase code generator instead of just designer because
there are plenty of code generators around besides designers. For instance, in Visual
Studio 2005 web service proxies are generated as partial classes, and you may well
have your own tools that generate code based on other data sources. One reasonably
common example of this is Object Relational Mapping (ORM)??”some ORM tools use
database entity descriptions from a configuration file (or straight from the database)
and generate partial classes representing those entities.
This makes it very straightforward to add behavior to the type: overriding virtual
methods of the base class, adding new members with business logic, and so forth. It??™s a
great way of letting the developer and the tool work together, rather than constantly
squabbling about who??™s in charge.


Pages:
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369