I am using a lot of database data in my project that is exported in different classes. For example, I have
transaction.Layout.Multimedia.Images.first();
The problem is that these properties are not necessarily available.
So, it is possible that transaction.Layout
is null, it is possible that transaction.Layout.Multimedia
is null, and so on.
I currently use this for every property:
if (transaction.Layout != null)
{
if (transaction.Layout.Multimedia != null)
{
if (transaction.Layout.Multimedia.Images != null)
{
if (transaction.Layout.Multimedia.Images.count > 0)
{
var img = transaction.Layout.Multimedia.Images.first();
}
}
}
}
I was wondering if there is a better way that I can check all parent classes to make sure that the property I need is available. These aren't the only objects I use, there are others as well with totally different names.
Thanks in advance