c# Reflection - Find the Generic Type of a Collection

前端 未结 3 1140
说谎
说谎 2021-02-18 14:43

I\'m reflecting a property \'Blah\' its Type is ICollection

    public ICollection Blah { get; set; }

    private void button1_Click(object sender         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-18 15:13

    You're looking for the GetGenericTypeDefinition method:

    MessageBox.Show(pi.PropertyType.GetGenericTypeDefinition().ToString());
    

提交回复
热议问题