If you use log4net you have probably noticed that this logger does not write information from exception's "Data" property. Here is the renderer which does:
Sample output for NullReferenceException with Data["configPath"] = "myconfig.config":
2009-06-12 22:22:04,038 INFO [LoggerTest.Program] - Exception during init
System.NullReferenceException: Something was null
at LoggerTest.Program.Main(String[] args) in G:\C#\Temp\LoggerTest\Program.cs:line 26
Exception Data:
configPath = myconfig.config
Then he would like to find there a first mood type which is a part of "good mood" group and pass the result to another layer of an application. He wrote the code:
Now he realized that it cannot work because Find method of a List(T) class returns default(T) when a list does not contain desired item. In this case he would get Mood.Awesome because it is the default value of the enum. I do not need to add that the Mood.Awesome is not even the part of the list.
We can solve this problem by several different approaches.
Create different enum where the default element will be "Unknown = 0"
Use FindIndex method of List(T) class so we will be able to handle the situation of not found element
I believe that other approaches could work as well
The question to discuss - which programmer made a mistake? The first one who created "unfortunate" enum or the second one who used wrong structure / wrong searching method?
and a question is - which Assert fails? All of them o_O
I could not find an explanation why implemented Equals method is not called. Framework always calls default Equals(object)