Check if types are castable / subclasses

后端 未结 6 2248
执笔经年
执笔经年 2020-12-07 00:32

I have they type of two members as strings - and not as a Type instance. How can I check if the two types are castable? Let\'s say string one is \"System.Windows.Forms.Label

6条回答
  •  没有蜡笔的小新
    2020-12-07 01:09

    If you can convert these strings to Type objects then your best bet is Type.IsAssignableFrom.

    Beware though, this only tells you if two Type instances are compatible at a CLR level. This will not take into account such things as user defined conversions or other C# semantics.

提交回复
热议问题