dynamic, How to test if a property is available
Posted
by Miau
on Stack Overflow
See other posts from Stack Overflow
or by Miau
Published on 2010-06-08T15:49:10Z
Indexed on
2010/06/08
15:52 UTC
Read the original article
Hit count: 261
dynamic
|dynamic-keyword
Scenario is very simple somewhere in the code I have this
dynamic myVariable = GetDataThatLooksVerySimilarButNotTheSame();
//how to do this?
if (myVariable.MyProperty.Exists)
//Do stuff
So basically the question is how to check (avoiding exceptions) that a certain property is available in my dynamic variable. I could do GetType() but I d rather avoid that, I dont actually want to know the type of the object I want to know if a property (or method if that makes life easier) is available Any pointers?
Cheers
© Stack Overflow or respective owner