Imagine that you have a NuGet package containing a bunch of static strings. These fields are intended to be used instead of magic strings, making it so anything that takes a dependency on this NuGet package will all be on the same page about these unique keys.
Now suppose that these keys also represent the name of something on a server somewhere. A database name, for example. Or a queue name for an AMQP instance.
NOW suppose you want to write some integration tests to make sure that everything is working properly (to get teh warm and fuzzy feels), but you DON’T want to use the pre-configured strings, because you don’t want to mess up your local environment (or, worse, if you run it on a build server, the actual environment). So you want to just generate some garbage names to be unique for testing. Also because you want to run multiple tests in parallel (because who has time to wait for tests to run individually??) and you don’t want the tests to step on themselves?
Reflection
The super hero for smudging and blurring the lines. Of course, with great power comes great responsibility, blah blah blah. We can just magically change the value of the field, and the rest of our code is none the wiser.
The key here is in the SetValue. Normally the first parameter of SetValue is the object of which you want to alter the field… However, because the field is static, there is no instance object to set, so we pass null instead.