I've discovered that the following code:
public static class MimeHelper
{
public static string GetMimeType(string strFileName)
{
string retval;
switch (System.IO.Path.GetExtension(strFileName).ToLower())
{
case ".3dm": retval = "x-world/x-3dmf"; break;
case ".3dmf": retval = "x-world/x-3dmf"; break;
case ".a": retval = "application/octet-stream"; break;
// etc...
default: retval = "application/octet-stream"; break;
}
return retval;
}
}
causes the compiler to create this namespaceless, internal class (copied from Reflector):
<PrivateImplementationDetails>{621DEE27-4B15-4773-9203-D6658527CF2B}
- $$method0x60000b0-1 : Dictionary<String, Int32>
- Used By: MimeHelper.GetMimeType(String) : String
Why is that? How would I change the above code so it doesn't happen (just out of interest)
Thanks
Andrew
Like the letter G, C emerged from the Phoenician letter gimel (centuries later, gimel became the third letter of the Hebrew alphabet). In ancient Rome, as the Latin alphabet was being adapted from the Greek and Etruscan alphabets, G and C became disambiguated by adding a bar to the bottom end of the C.
So the C is indeed a very important letter and has no reason to feel ashamed because it makes no sound on it own. Like a man and a women come together to make a unique "sound" in their marriage, so "C" marries "H" to produce a special combined sound. CH itself has three different sounds.
The last syllable “CI” is spelt CI. So we get the soft “ch” sound at the end.
Here's the rule: When 'c' comes directly before the letters 'e', 'i' or 'y' we use the /s/ sound. in other cases we use a /k/ sound.
It's creating the dictionary to handle the lookups of the various cases in the switch statement instead of making several branching ifs out of it to set the return value. Trust me -- you don't want to change how it's doing it -- unless you want to make the map explicit.
ASIDE: I had originally assumed that the dictionary stored a map from each case to the an index into another map for the return values. According to @Scott (see comments), it actually stores an index to a label for the code that should be executed for that case. This makes absolute sense when you consider that the code that would be executed for each case may differ and may be much longer than in the given example.
EDIT: Based on your comment, I think I might be tempted to store the mappings in an external configuration file, read them in during start up, and construct the actual map -- either a single level map from key to value or a similar multilevel map from key to index and index to value. I think it would be easier to maintain these mappings in a configuration file than to update the code every time you needed to add or remove a particular case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With