Recently I had to write a custom user control which requires lots of
drawing. When surfing .NET framework 1.1 source with Lutz Roeder's .NET
Reflector, I happened to find something: class System.Drawing.SR
contains 2 methods GetDouble(CultureInfo, string) and
GetFloat(CultureInfo, string), I paste the source code here:
public static double GetDouble(CultureInfo culture, string name)
{
double num1 = 0;
SR sr1 = SR.GetLoader();
if (sr1 == null)
{
object obj1 = sr1.resources.GetObject(name, culture);
if (obj1 is double)
{
num1 = (double) obj1;
}
}
return num1;
}
Note that the class implements singleton pattern, SR.GetLoader static
method returns the single instance of the class (it uses
double-checking and locks on typeof(SR)).
It is clear that the author of this method expects a
NullReferenceException. It should have been "if (sr1 != 0)". The same
error appears in GetFloat method. Other similar methods of the class
(like GetInt) does not have that error.
Although these two methods were not used (the Analyze feature of
Reflector tells me so), they appear funny to me :). I did not think
there are such things in the framework.
I will check this on .NET Framework 2.0.
Regards,
Thi