I am doing some quick type conversions in a project that I am not very familiar with.
They look something like this:
var NewType = new
{
NewTypeId = old.SubType == null ? 0 : old.SubType.SubTypeId ?? 0,
OtherType = old.OtherType ?? "",
Review = old.CustomerComments ?? "",
Country = old.Country == null ? "" : old.Country.Abbreviation ?? "",
Customer = old.SubType == null ? "" :
old.SubType.Customer == null ? "" :
old.SubType.Customer.Name ?? ""
};
The objects that I convert are usually Entity Framework objects. I also do not have the ability to change the classes that I will convert.
Is there an easier way to check for zeros, in particular for situations like this, when any of the sub-objects can be null?
OldType.SubType.AnotherSubType.SomeProperty
source
share