Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight 3 class library

Tags:

silverlight

I'm currently working on a UI development project and it was decided to implement it in Silvelight. I understand that Microsoft developers try to minimize size of the distribution and that's why some (lots) of the classes in regular .NET Framework are not included. Is it expected to see more classes included in Silverlight 3 library?

like image 205
aquio Avatar asked Feb 25 '26 08:02

aquio


2 Answers

As an aside, you can always use Reflector over the core .NET Framework libraries to obtain some of the missing "nice to haves" in code form.

Here's redgate's reflector: http://www.red-gate.com/products/reflector/

And here is the code I extracted and modified version of HttpUtility.ParseQueryString:

public IDictionary<string, string> ParseParams(string paramsString)
{
    if (string.IsNullOrEmpty(paramsString))
        throw new ArgumentNullException("paramsString");

    // convert to dictionary
    var dict = new Dictionary<string, string>();

    // remove the leading ?
    if (paramsString.StartsWith("?"))
        paramsString = paramsString.Substring(1);

    var length = paramsString.Length;

    for (var i = 0; i < length; i++) {
        var startIndex = i;
        var pivotIndex = -1;

        while (i < length) {
            char ch = paramsString[i];
            if (ch == '=') {
                if (pivotIndex < 0) {
                    pivotIndex = i;
                }
            } else if (ch == '&') {
                break;
            }
            i++;
        }

        string name;
        string value;
        if (pivotIndex >= 0) {
            name = paramsString.Substring(startIndex, pivotIndex - startIndex);
            value = paramsString.Substring(pivotIndex + 1, (i - pivotIndex) - 1);
        } else {
            name = paramsString.Substring(startIndex, i - startIndex);
            value = null;
        }

        dict.Add(UrlDecode(name), UrlDecode(value));

        // if string ends with ampersand, add another empty token
        if ((i == (length - 1)) && (paramsString[i] == '&'))
            dict.Add(null, string.Empty);
    }

    return dict;
}

It's just an example, but as you can see, .. if what you really need is already inside the .NET BCL... then why re-implement it? Just decompile the thing and re-implement it in Silverlight.

IMO most of what you'll be decompiling will probably be basic vanilla stuff "nice to haves" thats missing in Silverlight anyway so I don't think this'll raise any legal concerns.

Of course, you could re-implement the querystring parsing logic yourself but as you can see there're all the little details in there that you could have missed not to mention performance concerns.

like image 111
chakrit Avatar answered Feb 26 '26 22:02

chakrit


I hope not, and I doubt it.

Scott Guthrie who apparently runs the project for Microsoft is on the record as saying that he doesn't want to put "nice to haves" in, in case there's no room left for any future "must haves".

I think they've got the balance right - there's not much they've left out which you can't write yourself.

like image 23
Phil Bachmann Avatar answered Feb 26 '26 21:02

Phil Bachmann