Been looking at a lot of post/articles about using Iif(). All of this started when I tried to use IIf() like a conditional operator much in the likes of C/C#/C++ etc.
What I tried to do exactly was exactly in the lines of this of the following post:
Using VB.NET IIF I get NullReferenceException
However, the solution I had implemented was borrowed from the following msdn site:
http://msdn.microsoft.com/en-us/library/27ydhh0d%28v=vs.80%29.aspx
Its only after that I learned about the If() method in vb.net.
So in the end I had written a function which returns the appropriate value (which used reflection) to achieve the purpose. But that method (which I wrote) didn't throw any exception. In fact I was able to check for nullability of the type inside the function.
Function ReturnValue(ByVal MyType As SomeType, ByVal PropertyName as String) As Object
If MyType Is Nothing Then Return String.Empty
Dim arrPropInfo As PropertyInfo() = MyType.GetType().GetProperties()
Return arrPropInfo.Where(Function(x) x.Name = PropertyName).Item(0).GetValue(MyType, Nothing)
End Function
My question is, is there something written inside Iif() to throw an error like that? - a NullReferenceException
If MyType Is Nothing Then Throw New NullReferenceException()
Or is there something much bigger at work here? So suppose if I wanted to write function like iif, which will throw an error if something in the argument list is null is the above way the only way of doing it?