dynamic-keyword

Test if a property is available on a dynamic variable

你。 提交于 2019-11-26 12:57:55
My situation is very simple. Somewhere in my code I have this: dynamic myVariable = GetDataThatLooksVerySimilarButNotTheSame(); //How to do this? if (myVariable.MyProperty.Exists) //Do stuff So, basically my question is how to check (without throwing an exception) that a certain property is available on my dynamic variable. I could do GetType() but I'd rather avoid that since I don't really need to know the type of the object. All that I really want to know is whether a property (or method, if that makes life easier) is available. Any pointers? I think there is no way to find out whether a

Test if a property is available on a dynamic variable

此生再无相见时 提交于 2019-11-26 03:09:22
问题 My situation is very simple. Somewhere in my code I have this: dynamic myVariable = GetDataThatLooksVerySimilarButNotTheSame(); //How to do this? if (myVariable.MyProperty.Exists) //Do stuff So, basically my question is how to check (without throwing an exception) that a certain property is available on my dynamic variable. I could do GetType() but I\'d rather avoid that since I don\'t really need to know the type of the object. All that I really want to know is whether a property (or method,