如何在运行时检查动态数据类型的类型? [英] How do I check type of dynamic datatype at runtime?
问题描述
在我的ASP.NET网站中,我有一个方法返回类型为 dynamic
的值。然后,根据某些条件和结果,此方法将返回布尔值或SortedList。
In my ASP.NET website, I have a method that returns a value of type dynamic
. This method, depending on certain criteria and results, will then either return a Boolean value or SortedList.
要粘贴的代码太多,但例如:
There is too much code to paste, but for example:
public dynamic ReturnThis(dynamic value)
{
if(someConditionIsMet)
{
value = true;
}
else
{
value = new List<String>().Add(new Person() { Name = "Travis" });
}
return value;
}
我的问题是,我想确定数据类型
的值,在调用此方法之后才对其进行操作或读取其数据。但是我不确定如何检查动态值
是什么类型。我该怎么做?
My problem is, I would like to determine the datatype
of value after calling this method before acting on or reading its data. But I am unsure how to check what type dynamic value
is. How can I do this?
推荐答案
只需在另一个SO问题上阅读此文件……希望它将为您解决问题:
Just read this on another SO question...hopefully it will do the trick for you:
Type unknown = ((ObjectHandle)tmp).Unwrap().GetType();
阅读并支持此问题以获取更多信息:
获取声明为动态的对象的类型
Read and upvote this question for more info: get the Type for a object declared dynamic
这篇关于如何在运行时检查动态数据类型的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!