1

I am calling an SAP web service that returns a crazy object like 5-10 levels deep to get anything meaningful. I hate all the code I have to write to do all the null checking, and I really don't want to wrap it in a try/catch to deal with a NullReferenceException. Does anyone have a good solution for this?

1 Answers1

2

There is a relatively new feature in C# called a "null-conditional operator" that sounds like a good fit for what you want. Instead of doing blah.blah.blah you do blah?.blah?.blah. Like I said this feature is pretty new. I know it is there in Visual Studio 2015 and C# 6.0, but you may not have it back in VS2010 or 2012. Here is a link to the msdn article:

https://msdn.microsoft.com/en-us/library/dn986595.aspx

Justin Pavatte
  • 1,198
  • 2
  • 12
  • 18