views:

774

answers:

5

Today I discovered something that makes me sad: objects of type System.Generic.Collections.List don't have a number of the useful extension methods I've come to love, such as Find, FindAll, FindIndex, Exists, RemoveAll, etc.

The object browser in VS2008 shows that those methods exist in the mscorlib version I'm using, but if I look at the assembly in ildasm they're not there.

Am I missing something obvious here or is there some way to make them available to my Silverlight app?

Also, I wonder if there's a good reference out there for what's different between Silverlight's runtime and the "real" one.

Thanks!

+4  A: 

What's likely happening here is that Object Browser is resolving to the normal 2.0 mscorlib instead of the version that is used for silverlight.

I don't find it suprising that the Find extension method is missing for a SilverLight app. The .Net framework for SilverLight is stripped down pretty far in order to make it small enough to be a speedy download for users. They had to make some hard cuts and many items didn't make it.

If you need the method though, why not just add it yourself? Adding all of them may get tiring after awhile but it can be used to work around this issue.

JaredPar
I likely will just implement the piece I'm missing if there's no alternative. Currently it's only a single method so it's not a lot of work, but it would be nice to not have to do it at all :)
mmacaulay
+1  A: 

Just one quick point: Find isn't an extension method. It's a perfectly normal instance method.

However, it doesn't entirely surprise me that there are bits "missing" from List<T> in Silverlight. It is a cut-down version of the framework. Unfortunately I don't know of any resource to say what's in and what's out.

Jon Skeet
A: 

It's a constant battle, brother. I keep my .Net API and Silverlight API bookmarks right next to each other because I develop a lot of controls that are used in both WPF and Silverlight and it seems like every time I come up with a good idea for implementing a feature, I run into something fundemental not supported in Silverlight.

I can just see the meeting to discuss what got the chop. "What do we need this find() method for? We've got a perfectly good LINQ library. Gone!"

Silverlight Reference

MojoFilter
A: 

just reference the System.Core assembly if you haven't yet and do a

using System.Linq;

and for any IEnumerable, you will have lots of extension methods that can do the stuff you need and more.

Microsoft obviously wants to keep the Silverlight runtime small for download, thus avoiding duplicate implementations.

Lots of stuff in the original framework already became obsolete with Generics and .NET 2.0, with .NET 3.0 and extension methods even more. I guess the stuff you find in Silverlight is a good hint about the future directions. What they left out (like much stuff in the System.ComponentModel) will become kinda deprecated in the original framework too (except for the server/database stuff of course).

herzmeister der welten
A: 

Still the .Exists doesn't exist as extension in the silverlight version

Raymond de Jong