Questions tagged «dynamic-keyword»

14
测试动态变量上的属性是否可用
我的情况很简单。在我的代码中,我有这个地方: dynamic myVariable = GetDataThatLooksVerySimilarButNotTheSame(); //How to do this? if (myVariable.MyProperty.Exists) //Do stuff 因此,基本上我的问题是如何检查(不引发异常)动态变量上是否有某个属性可用。我可以,GetType()但是我宁愿避免这种情况,因为我真的不需要知道对象的类型。我真正想知道的只是一个属性(或方法,如果使生活更轻松)是否可用。有指针吗?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.