Silverlight 3类库

aqu*_*uio 3 silverlight

我目前正在开发一个UI开发项目,并决定在Silvelight中实现它.我了解Microsoft开发人员尝试最小化分发的大小,这就是为什么不包括常规.NET Framework中的一些(很多)类的原因.是否可以看到Silverlight 3库中包含更多类?

cha*_*rit 6

顺便说一句,您总是可以在核心.NET Framework库上使用Reflector来获取代码形式中缺少的"好东西".

这是redgate的反射器:http://www.red-gate.com/products/reflector/

这里是我提取的代码和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;
}
Run Code Online (Sandbox Code Playgroud)

这只是一个例子,但正如你所看到的,如果你真正需要的东西已经在.NET BCL中...那么为什么要重新实现呢?只需反编译并在Silverlight中重新实现它.

IMO大部分你反编译的内容可能都是基本的vanilla东西,"很高兴有钱",无论如何都缺少Silverlight,所以我认为这不会引起任何法律问题.

当然,您可以自己重新实现查询字符串解析逻辑,但正如您所看到的那样,您可能错过的所有细节都不会提及性能问题.