an I prevent a specific type using generic restrictions

后端 未结 4 606
悲&欢浪女
悲&欢浪女 2021-01-18 13:03

I have an overload method - the first implementation always returns a single object, the second implementation always returns an enumeration.

I\'d like to make the m

4条回答
  •  再見小時候
    2021-01-18 13:59

    Use only one method and have it detect the IEnumerable case dynamically rather than attempting the impossible via generic constraints. It would be "code smell" to have to deal with two different cache methods depending on if the object to store/retrieve is something enumerable or not. Also, just because it implements IEnumerable does not mean it is necessarily a collection.

提交回复
热议问题