Prev | Current Page 362 | Next

Jon Skeet

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

You might want to use this instead:
MyEntity entity = LoadAndCache(id);
LogEntity(entity);
That way, the entity is loaded and cached regardless of whether an implementation
has been provided for LogEntity. Of course, if the entity can be loaded equally
Listing 7.2 A partial method called from a constructor
190 CHAPTER 7 Concluding C# 2: the final features
cheaply later on, and may not even be required, you should leave the statement in the
first form and avoid an unnecessary load in some cases.
To be honest, unless you??™re writing your own code generators, you??™re more likely to
be implementing partial methods than declaring and calling them. If you??™re only implementing
them, you don??™t need to worry about the argument evaluation side of things.
In summary, partial methods in C# 3 allow generated code to interact with handwritten
code in a rich manner without any performance penalties for situations where the
interaction is unnecessary. This is a natural continuation of the C# 2 partial types feature,
which enables a much more productive relationship between code-generation
tools and developers.
Our next feature is entirely different, and is just a way of telling the compiler more
about the intended nature of a type so that it can perform more checking on both the
type itself and any code using it.
7.2 Static classes
Our second new feature is in some ways completely unnecessary??”it just makes things
tidier and a bit more elegant when you write utility classes.


Pages:
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374