Check if types are castable / subclasses

后端 未结 6 2247
执笔经年
执笔经年 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:00

    How about:

    public bool IsCastable(String type0, String type1)
    {
      return Type.GetType(type1).IsAssignableFrom(Type.GetType(type0));
    }
    

提交回复
热议问题