【Dflying Chen 】.NET Framework源代码发布

Scott在Blog中声称微软公司将部分公开.NET Framework的源代码,为避免曲解,这里引用他的原文,如下:

We'll begin by offering the source code (with source file comments included) for the .NET Base Class Libraries (System, System.IO, System.Collections, System.Configuration, System.Threading, System.Net, System.Security, System.Runtime, System.Text, etc), ASP.NET (System.Web), Windows Forms (System.Windows.Forms), ADO.NET (System.Data), XML (System.Xml), and WPF (System.Windows).  We'll then be adding more libraries in the months ahead (including WCF, Workflow, and LINQ).  The source code will be released under the Microsoft Reference License (MS-RL).

源代码发放的许可是MS-RL,这是一个非常严格的许可,通俗来讲就是让你看看而已,别的就别想干了……不过确实能够在调试的时候方便不少,例如:

更多相关介绍以及使用方法也可以参考这篇文章:http://blogs.msdn.com/sburke/archive/2007/10/04/channel-9-video-more-details-on-reference-source.aspx

 

[2] Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5 (Tip/Trick:在.NET 3.5中编写ToJSON扩展方法)

.NET 3.5中的扩展方法非常有意思,似乎让框架本身有了那么一些“动态语言”的特性。Scott这里给出了一个ToJSON扩展方法,让我们能够将一个对象转化为JSON表示的字符串。该ToJSON()方法的定义很简单:

使用起来则更加直观:

 

[3] Tracking Silverlight-enabled Browsers via Analytics (在Google Analytics中统计访客浏览器的Silverlight启用状况)

Google Analytics功能非常强大,不过尚不能统计访客浏览器的Silverlight启用状况。Nikhil Kothari因此写了这样一段JavaScript,让Google Analytics也能够把这部分信息收入囊中:

function onLoad() {
    var version = getSilverlightVersion();
    if (version) { __utmSetVar(version); }
}
 
function getSilverlightVersion() {
    var version = '';
    var container = null;
    try {
        var control = null;
        if (window.navigator.userAgent.indexOf('MSIE') >= 0) {
            control = new ActiveXObject('AgControl.AgControl');
        }
        else {
            if (navigator.plugins['Silverlight Plug-In']) {
                container = document.createElement('div');
                document.body.appendChild(container);
                container.innerHTML= '';
                control = container.childNodes[0];
            }
        }
        if (control) {
            if (control.isVersionSupported('1.1')) { version = 'Silverlight/1.1'; }
            else if (control.isVersionSupported('1.0')) { version = 'Silverlight/1.0'; }
        }
    }
    catch (e) { }
    if (container) {
        document.body.removeChild(container);
    }
    return version;
}
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  

 

请使用浏览器的分享功能分享到微信等