Why is List not IEnumerable?

后端 未结 6 865
北海茫月
北海茫月 2021-01-05 02:01

[Edit: My apologies ... the original question wording was ambiguous and I was not getting the responses I am looking for]

For any class X that inherits from class Y,

6条回答
  •  不知归路
    2021-01-05 02:36

    I think I can see what you are getting at

    bool IsCollectionOfValueTypes(Object argValue)
    {
      Type t = argValue.GetType();
      if(t.IsArray)
      {
        return t.GetElementType().IsValueType;
      }
      else
      {
        if (t.IsGeneric)
        {
          Types[] gt = t.GetGenericArguments();
           return (gt.Length == 1) && gt[0].IsValueType;
        }
      }
      return false;
    }
    

    A start anyway might get a bit more complicated if you pass in a multidimensional array or a contructed type. It's all in the class somewhere though.

提交回复
热议问题