Information Technology Reference
In-Depth Information
// elided
}
Can be called using named parameters to avoid any confusion on the
order:
SetName(lastName:
"Wagner"
, firstName:
"Bill"
);
Annotating the names of the parameters ensures that people reading this
code later won't wonder if the parameters are in the right order or not.
Developers will use named parameters whenever adding the names will
increase the clarity of the code someone is trying to read. Anytime you use
methods that contain multiple parameters of the same type, naming the
parameters at the callsite will make your code more readable.
Changing parameter names manifests itself in an interesting way as a
breaking change. The parameter names are stored in the MSIL only at the
callsite, not at the calling site. You can change parameter names and release
the component without breaking any users of your component in the field.
The developers who use your component will see a breaking change when
they go to compile against the updated version, but any earlier client
assemblies will continue to run correctly. So at least you won't break exist-
ing applications in the field. The developers who use your work will still be
upset, but they won't blame you for problems in the field. For example,
suppose you modify SetName() by changing the parameter names:
public void
SetName(
string
Last,
string
First)
Yo u c o u l d c o m p i l e a n d r e l e a s e t h i s a s s e m b l y a s a p a t c h i n t o t h e fi e l d . A n y
assemblies that called this method would continue to run, even if they
contain calls to SetName that specify named parameters. However, when
client developers went to build updates to their assemblies, any code like
this would no longer compile:
SetName(lastName:
"Wagner"
, firstName:
"Bill"
);
The parameter names have changed.
Changing the default value also requires callers to recompile in order to
pick up those changes. If you compile your assembly and release it as a
patch, all existing callers would continue to use the previous default
parameter.
Of course, you don't want to upset the developers who use your components
either. For that reason, you must consider the names of your parameters