I am using Jon Skeet's very clever SmartEnumerable. I recommend checking it out if you haven't already seen it.
The class is defined :
public class SmartEnumerable<T> : IEnumerable<SmartEnumerable<T>.Entry>
The constructor is :
public SmartEnumerable(IEnumerable<T> enumerable)
and you use it by saying :
new SmartEnumerable<Cat>(myCats); // where myCats is IEnumerable<Cat>
Now I'd really like to have the compiler infer I've got an array of cats and be able to just say :
new SmartEnumerable(myCats);
However this gives me a compiler error :
The type arguments for method 'MiscUtil.Collections.SmartEnumerable.SmartEnumerable(System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
I'm not clear exactly why this is. is there any way around it. Why can't it see I'm using IEnumerable<Cat>
and infer from that. Can i change anythin to make it recognize the type I'm using?
I'd really like some way to construct a SmartEnumerable without having to specify the type - because I'm primarily using it for UI in ASP.NET MVC where I don't always have includes
for the types and rely on var
to get me a reference. I end up having to include types just to be able to use SmartEnumerable - which reduces its elegance.
Oh and I would have just emailed John directly but he'll probably reply faster here anyway :-)
<font color=white>skeet skeet skeet, jon, jon, jon, jon skeet, skeet jon, skeetster, skeetmeister</font>