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?
Asked
Active
Viewed 94 times
1
-
1on C# 6 you can do, obj?.prop1?.prop2?.... – Arsen Mkrtchyan Feb 04 '16 at 13:13
1 Answers
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:

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