我正在为 WPF 编写一个通用的 IValueConverter,但我在将值与特定类型进行比较时遇到了困难。
我的对象的构成看起来像这样
public interface IAwesome
{
int AwesomeAmount { get; set; }
}
public class MyAwesomeClass : IAwesome
{
public int AwesomeAmount { get; set; }
}
我的方法看起来像这样
public bool CompareToType(object value, Type type);
如果我有...
var mac = new MyAwesomeClass();
bool isAwesome = CompareToType(mac, typeof(IAwesome));
同样我可以写
var stream = new FileStream();
bool isStream = CompareToType(stream, typeof(Stream));
如何编写我的 CompareToType 方法来确定该类是实现接口(interface)还是继承自基础对象?
如果我遗漏了一些非常明显的东西,我深表歉意,但无论如何我都会很感激你的帮助:)
最佳答案
关于c# - 如何确定 System.Object 是否为 System.Type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5728474/