In the below two sample code I am trying to instantiate a class named Test by using C# normal method and Object initializer.
DateTime? nullDate = null; //this value will come from somewhere else
DateTime? notNullDate = DateTime.Now;
var test = new Test();
test.Date = nullDate.Value; //exception will throw here
test.Name = "String";
test.AnotherDate = notNullDate.Value;
In the above sample code, I can clearly understand which property is showing exception while debugging.
DateTime? nullDate = null; //this value will come from somewhere else
DateTime? notNullDate = DateTime.Now;
var test = new Test
{
Date = nullDate.Value,
Name = "String",
AnotherDate = notNullDate.Value
};
In this above code, when I use object initializer I couldn't understand which property is thrown exception. Here I couldn't debug line by line. If I have lot of properties initialized it's very difficult to identify.
Here is my question: How can I identify which property is showing exception from exception window? Right now the inner exception is null.