<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>CodeProject-Tip</title>
        <link>http://skysanders.net/subtext/category/4.aspx</link>
        <description>CodeProject-Tip</description>
        <language>en-US</language>
        <copyright>Sky Sanders</copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <item>
            <title>C# truncate DateTime</title>
            <link>http://skysanders.net/subtext/archive/2010/04/20/c-truncate-datetime.aspx</link>
            <description>&lt;p&gt;&lt;font face=""&gt;Here is an extension method that will let you truncate a DateTime to any resolution...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Usage:&lt;/p&gt;
&lt;pre class="brush:c#;"&gt;DateTime myDateSansMilliseconds = myDate.Truncate(TimeSpan.TicksPerSecond);
DateTime myDateSansSeconds = myDate.Truncate(TimeSpan.TicksPerMinute)
&lt;/pre&gt;
&lt;p&gt;Class:&lt;/p&gt;
&lt;pre class="brush:c#;"&gt;
public static class DateTimeUtils
{
    /// &amp;lt;summary&amp;gt;
    /// &amp;lt;para&amp;gt;Truncates a DateTime to a specified resolution.&amp;lt;/para&amp;gt;
    /// &amp;lt;para&amp;gt;A convenient source for resolution is TimeSpan.TicksPerXXXX constants.&amp;lt;/para&amp;gt;
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="date"&amp;gt;The DateTime object to truncate&amp;lt;/param&amp;gt;
    /// &amp;lt;param name="resolution"&amp;gt;e.g. to round to nearest second, TimeSpan.TicksPerSecond&amp;lt;/param&amp;gt;
    /// &amp;lt;returns&amp;gt;Truncated DateTime&amp;lt;/returns&amp;gt;
    public static DateTime Truncate(this DateTime date, long resolution)
    {
        return new DateTime(date.Ticks - (date.Ticks % resolution), date.Kind);
    }
}

&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://skysanders.net/subtext/aggbug/118.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/04/20/c-truncate-datetime.aspx</guid>
            <pubDate>Wed, 21 Apr 2010 09:44:12 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/118.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/04/20/c-truncate-datetime.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/118.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using WMI to fetch the command line that started all instances of a process</title>
            <link>http://skysanders.net/subtext/archive/2010/04/11/using-wmi-to-fetch-the-command-line-that-started-all.aspx</link>
            <description>&lt;pre class="brush:c#;"&gt;/// &amp;lt;summary&amp;gt;
/// Using WMI to fetch the command line that started all instances of a process
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="processName"&amp;gt;Image name, e.g. WebDev.WebServer.exe&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
/// adapted from http://stackoverflow.com/questions/504208/how-to-read-command-line-arguments-of-another-process-in-c/504378%23504378
/// original code by http://stackoverflow.com/users/61396/xcud
private static IEnumerable&amp;lt;string&amp;gt; GetCommandLines(string processName)
{
    List&amp;lt;string&amp;gt; results = new List&amp;lt;string&amp;gt;();

    string wmiQuery = string.Format("select CommandLine from Win32_Process where Name='{0}'", processName);

    using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery))
    {
        using (ManagementObjectCollection retObjectCollection = searcher.Get())
        {
            foreach (ManagementObject retObject in retObjectCollection)
            {
                results.Add((string)retObject["CommandLine"]);
            }
        }
    }
    return results;
}

&lt;/pre&gt;
&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/C-Sharp"&gt;C-Sharp&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/WMI"&gt;WMI&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/111.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/04/11/using-wmi-to-fetch-the-command-line-that-started-all.aspx</guid>
            <pubDate>Mon, 12 Apr 2010 02:12:32 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/111.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/04/11/using-wmi-to-fetch-the-command-line-that-started-all.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/111.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Preventing caching of content in ASP.Net Pages and other HttpHandlers</title>
            <link>http://skysanders.net/subtext/archive/2010/03/23/preventing-caching-of-content-in-asp.net-pages-and-other-httphandlers.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Sometimes I forget to squash caching on my JSON handlers and end up with odd runtime behavior, especially when using IE.&lt;/p&gt;
&lt;p&gt;You can ensure that each request actually pulls data instead of hitting the cache by adding this to the top of a handler (.ashx) or in the page_load of a .aspx. Drop 'context.' for use in page_load.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="brush:c#;"&gt;context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;This is what the head of my JSON handlers typically look like:&lt;/p&gt;
&lt;pre class="brush:c#;"&gt;        public void ProcessRequest(HttpContext context)
        {
            context.Response.ClearContent();
            context.Response.ClearHeaders();
            context.Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.Cache.SetNoStore();
            context.Response.ContentType = "text/json";
&lt;/pre&gt;
&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/C-Sharp"&gt;C-Sharp&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/ASP.NET"&gt;ASP.NET&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/106.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/03/23/preventing-caching-of-content-in-asp.net-pages-and-other-httphandlers.aspx</guid>
            <pubDate>Tue, 23 Mar 2010 14:59:47 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/106.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/03/23/preventing-caching-of-content-in-asp.net-pages-and-other-httphandlers.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/106.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Coerce Windows and Internet Explorer (IE) to diplay JSON text inline</title>
            <link>http://skysanders.net/subtext/archive/2010/03/23/coerce-windows-and-internet-explorer-ie-to-diplay-json-text.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Cheeso posted and eventually answered &lt;a target="_blank" href="http://stackoverflow.com/questions/2483771/how-can-i-convince-ie-to-simply-display-application-json-rather-than-offer-to-dow"&gt;this question&lt;/a&gt; on StackOverflow about how to get IE to stop popping a file download dialog when rendering JSON text.&lt;/p&gt;
&lt;p&gt;A few things I noticed about the answer that might help others follow:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;You need to &lt;a target="_blank" href="http://support.microsoft.com/kb/310516"&gt;add the registry editor version&lt;/a&gt; as the first line in the .reg file&lt;/li&gt;
    &lt;li&gt;You might want to also include 'text/json' content type.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="brush:plain;"&gt;Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=dword:00080000


[HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"encoding"=dword:00080000

&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/105.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/03/23/coerce-windows-and-internet-explorer-ie-to-diplay-json-text.aspx</guid>
            <pubDate>Tue, 23 Mar 2010 14:49:07 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/105.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/03/23/coerce-windows-and-internet-explorer-ie-to-diplay-json-text.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/105.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Building Mono C# compiler (MCS) in Visual Studio 2008</title>
            <link>http://skysanders.net/subtext/archive/2010/03/09/building-mono-c-compiler-mcs-in-visual-studio-2008.aspx</link>
            <description>&lt;p&gt;If you are an old hand at building Mono on Windows using cygwin, then this post will not be of interest.&lt;/p&gt;
&lt;p&gt;The target audience for this post are those who just wish to build MCS, GMCS etc in Visual Studio 2008 without the need for MCS.&lt;/p&gt;
&lt;p&gt;Building the Mono C# compiler in Visual Studio 2008 would be as simple as opening gmcs.sln in VS and building if not for the need to generate the cs-parser.cs file.&lt;/p&gt;
&lt;p&gt;Supplied in the MCS package in the latest stable, &lt;a target="_blank" href="http://ftp.novell.com/pub/mono/sources-stable/"&gt;2.6.1&lt;/a&gt;,  is cs-parser.jay, which is an input file for the &lt;font face=""&gt;&lt;a target="_blank" href="http://code.google.com/p/jayc/"&gt;Jay Parser Generator for C#&lt;/a&gt;. The C++ source and gnu makefile for Jay are included but the point of this post is to obviate the need to use cygwin, so you can download a precompiled exe from the previous link.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;The simplest way to generate your cs-parser.cs file is to copy cs-parser.jay to the Jay directory (to make use of the skeleton file) and run the following command line in the Jay directory:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;jay.exe -ctv cs-parser.jay &amp;lt;skeleton.cs &amp;gt;cs-parser.cs&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Now, in the compiler solution, delete the missing cs-parser.cs file and paste the freshly generate cs-parser.cs into the solution.&lt;/p&gt;
&lt;p&gt;Or just &lt;a href="javascript:void(0);/*1268197354938*/"&gt;download cs-parser.cs (2.6.1) here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now clean and rebuild. &lt;/p&gt;
&lt;p&gt;Fini.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/Mono"&gt;Mono&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/98.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/03/09/building-mono-c-compiler-mcs-in-visual-studio-2008.aspx</guid>
            <pubDate>Tue, 09 Mar 2010 13:09:59 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/98.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/03/09/building-mono-c-compiler-mcs-in-visual-studio-2008.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/98.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Generic NullSafe IDataRecord Field Getter</title>
            <link>http://skysanders.net/subtext/archive/2010/03/02/generic-nullsafe-idatarecord-field-getter.aspx</link>
            <description>&lt;pre class="brush:c#;"&gt;// usage
var name = GetValueOrDefault&amp;lt;string&amp;gt;(reader, "Name");
var name = reader.GetValueOrDefault&amp;lt;string&amp;gt;("Name");
var name = reader.GetValueOrDefault&amp;lt;string&amp;gt;(0);


// extension
public static T GetValueOrDefault&amp;lt;T&amp;gt;(this IDataRecord row, string fieldName)
{
    int ordinal = row.GetOrdinal(fieldName);
    return row.GetValueOrDefault&amp;lt;T&amp;gt;(ordinal);
}

public static T GetValueOrDefault&amp;lt;T&amp;gt;(this IDataRecord row, int ordinal)
{
    return (T)(row.IsDBNull(ordinal) ? default(T) : row.GetValue(ordinal));
}

&lt;/pre&gt;
&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/C-Sharp"&gt;C-Sharp&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/ADO.Net"&gt;ADO.Net&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/92.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/03/02/generic-nullsafe-idatarecord-field-getter.aspx</guid>
            <pubDate>Wed, 03 Mar 2010 00:15:55 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/92.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/03/02/generic-nullsafe-idatarecord-field-getter.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/92.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Testing and Parsing an ASP.NET YSOD (Yellow Screen Of Death) from an XMLHttpRequest.responseText</title>
            <link>http://skysanders.net/subtext/archive/2010/02/27/testing-and-parsing-an-asp.net-ysod-yellow-screen-of-death.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p&gt;After a &lt;a target="_blank" href="http://stackoverflow.com/questions/2350874/ysod-yellow-screen-of-death-javascript-regexp-syntax-error"&gt;minor bout of forgetfulness&lt;/a&gt; regarding legal regexp flags in Javascript, I knocked this one out that parses the comment block at the end of an YSOD.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="brush:js;"&gt;var rxYSOD = /&amp;lt;!--\s*\[(.*?)]:(\s*.*\s(.*[\n\r]*)*?)\s*(at(.*[\n\r]*)*)--&amp;gt;/;
if (rxYSOD.test(text)) {
    // looks like one..
    var ysod = rxYSOD.exec(text);
    errObj = { Message: ysod[2], StackTrace: ysod[4], ExceptionType: ysod[1] };
}

&lt;/pre&gt;
&lt;p&gt;will find and parse the comment block shown. I am guessing that is why they put it there....&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="brush:html;"&gt;&amp;lt;html&amp;gt;
&amp;lt;!-- omitted --&amp;gt;
    &amp;lt;body bgcolor="white"&amp;gt;
		&amp;lt;!-- omitted --&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&amp;lt;!-- 
[ArgumentException]: Unknown web method ValidateUser.
Parameter name: methodName
   at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
   at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)
   at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)
   at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
   at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp;amp; completedSynchronously)
--&amp;gt;
&lt;/pre&gt;
s&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/ASP.NET"&gt;ASP.NET&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/JavaScript"&gt;JavaScript&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/88.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/02/27/testing-and-parsing-an-asp.net-ysod-yellow-screen-of-death.aspx</guid>
            <pubDate>Sun, 28 Feb 2010 11:46:56 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/88.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/02/27/testing-and-parsing-an-asp.net-ysod-yellow-screen-of-death.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/88.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Adding a ajax/json endpoint to an existing WCF service</title>
            <link>http://skysanders.net/subtext/archive/2010/02/26/adding-a-json-endpoint-to-an-existing-wcf-service.aspx</link>
            <description>&lt;p&gt;Mixing and matching security to get something like this locked down and providing the desired exposure might be challenging but I didn't offer to solve that in the title, did I?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div goog_docs_charindex="11"&gt;
&lt;div style="FONT-FAMILY: Consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt" goog_docs_charindex="12"&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="13"&gt;&lt;font color="#0000ff" goog_docs_charindex="14"&gt; &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="18"&gt;system.serviceModel&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="39"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="43"&gt;&lt;font color="#0000ff" goog_docs_charindex="44"&gt;    &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="51"&gt;behaviors&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="62"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="66"&gt;&lt;font style="BACKGROUND-COLOR: #ffff00" goog_docs_charindex="67"&gt;&lt;font color="#0000ff" goog_docs_charindex="68"&gt;      &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="77"&gt;endpointBehaviors&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="96"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="101"&gt;&lt;font style="BACKGROUND-COLOR: #ffff00" goog_docs_charindex="102"&gt;&lt;font color="#0000ff" goog_docs_charindex="103"&gt;        &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="114"&gt;behavior&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="125"&gt;name&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="131"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="135"&gt;webScriptBehavior&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="155"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="160"&gt;&lt;font style="BACKGROUND-COLOR: #ffff00" goog_docs_charindex="161"&gt;&lt;font color="#0000ff" goog_docs_charindex="162"&gt;          &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="175"&gt;enableWebScript&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="192"&gt; /&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="199"&gt;&lt;font style="BACKGROUND-COLOR: #ffff00" goog_docs_charindex="200"&gt;&lt;font color="#0000ff" goog_docs_charindex="201"&gt;        &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="213"&gt;behavior&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="223"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="228"&gt;&lt;font style="BACKGROUND-COLOR: #ffff00" goog_docs_charindex="229"&gt;&lt;font color="#0000ff" goog_docs_charindex="230"&gt;      &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="240"&gt;endpointBehaviors&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="259"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="264"&gt;&lt;font color="#0000ff" goog_docs_charindex="265"&gt;      &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="274"&gt;serviceBehaviors&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="292"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="296"&gt;&lt;font color="#0000ff" goog_docs_charindex="297"&gt;        &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="308"&gt;behavior&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="319"&gt;name&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="325"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="329"&gt;Salient.ScriptModel.Services.DualServiceBehavior&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="380"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="384"&gt;&lt;font color="#0000ff" goog_docs_charindex="385"&gt;          &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="398"&gt;serviceMetadata&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="416"&gt;httpGetEnabled&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="432"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="436"&gt;true&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="443"&gt; /&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="449"&gt;&lt;font color="#0000ff" goog_docs_charindex="450"&gt;          &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="463"&gt;serviceDebug&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="478"&gt;includeExceptionDetailInFaults&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="510"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="514"&gt;false&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="522"&gt; /&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="528"&gt;&lt;font color="#0000ff" goog_docs_charindex="529"&gt;        &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="541"&gt;behavior&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="551"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="555"&gt;&lt;font color="#0000ff" goog_docs_charindex="556"&gt;      &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="566"&gt;serviceBehaviors&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="584"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="588"&gt;&lt;font color="#0000ff" goog_docs_charindex="589"&gt;    &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="597"&gt;behaviors&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="608"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="612"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="615"&gt;&lt;font color="#0000ff" goog_docs_charindex="616"&gt;    &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="623"&gt;serviceHostingEnvironment&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="651"&gt;aspNetCompatibilityEnabled&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="679"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="683"&gt;true&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="690"&gt; /&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="696"&gt;&lt;font color="#0000ff" goog_docs_charindex="697"&gt;    &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="704"&gt;services&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="714"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;font color="#0000ff" goog_docs_charindex="718"&gt;
&lt;div style="FONT-FAMILY: Consolas; BACKGROUND: white; COLOR: black; FONT-SIZE: 10pt" goog_docs_charindex="719"&gt;&lt;font color="#0000ff" goog_docs_charindex="720"&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="721"&gt;&lt;font color="#0000ff" goog_docs_charindex="722"&gt;&lt;font color="#0000ff" goog_docs_charindex="723"&gt;      &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="732"&gt;service&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="742"&gt;behaviorConfiguration&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="765"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="769"&gt;Salient.ScriptModel.Services.DualServiceBehavior&lt;/font&gt;" &lt;font color="#ff0000" goog_docs_charindex="821"&gt;name&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="827"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="831"&gt;Salient.ScriptModel.Services.DualService&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="874"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font color="#0000ff" goog_docs_charindex="879"&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="880"&gt;&lt;font color="#0000ff" goog_docs_charindex="881"&gt;&lt;font color="#0000ff" goog_docs_charindex="882"&gt;        &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="893"&gt;endpoint&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="904"&gt;address&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="913"&gt;=&lt;/font&gt;"" &lt;font color="#ff0000" goog_docs_charindex="919"&gt;binding&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="928"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="932"&gt;wsHttpBinding&lt;/font&gt;" &lt;font color="#ff0000" goog_docs_charindex="949"&gt;contract&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="959"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="963"&gt;Salient.ScriptModel.Services.IDualService&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1007"&gt;/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font color="#0000ff" goog_docs_charindex="1013"&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="1014"&gt;&lt;font color="#0000ff" goog_docs_charindex="1015"&gt;&lt;font color="#0000ff" goog_docs_charindex="1016"&gt;        &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="1027"&gt;endpoint&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="1038"&gt;address&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1047"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1051"&gt;mex&lt;/font&gt;" &lt;font color="#ff0000" goog_docs_charindex="1058"&gt;binding&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1067"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1071"&gt;mexHttpBinding&lt;/font&gt;" &lt;font color="#ff0000" goog_docs_charindex="1089"&gt;contract&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1099"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1103"&gt;IMetadataExchange&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1123"&gt; /&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font color="#0000ff" goog_docs_charindex="1130"&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="1131"&gt;&lt;font color="#0000ff" goog_docs_charindex="1132"&gt;&lt;font style="BACKGROUND-COLOR: #ffff00" goog_docs_charindex="1133"&gt;&lt;font color="#0000ff" goog_docs_charindex="1134"&gt;        &amp;lt;&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="1145"&gt;endpoint&lt;/font&gt; &lt;font color="#ff0000" goog_docs_charindex="1156"&gt;address&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1165"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1169"&gt;json&lt;/font&gt;" &lt;font color="#ff0000" goog_docs_charindex="1177"&gt;behaviorConfiguration&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1200"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1204"&gt;webScriptBehavior&lt;/font&gt;" &lt;font color="#ff0000" goog_docs_charindex="1225"&gt;binding&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1234"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1238"&gt;webHttpBinding&lt;/font&gt;" &lt;font color="#ff0000" goog_docs_charindex="1256"&gt;contract&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1266"&gt;=&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1270"&gt;Salient.ScriptModel.Services.IDualService&lt;/font&gt;"&lt;font color="#0000ff" goog_docs_charindex="1314"&gt;/&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font color="#0000ff" goog_docs_charindex="1321"&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="1322"&gt;&lt;font color="#0000ff" goog_docs_charindex="1323"&gt;&lt;font color="#0000ff" goog_docs_charindex="1324"&gt;      &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="1334"&gt;service&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1343"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="1349"&gt;&lt;font color="#0000ff" goog_docs_charindex="1350"&gt;    &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="1358"&gt;services&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1368"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px" goog_docs_charindex="1372"&gt;&lt;font color="#0000ff" goog_docs_charindex="1373"&gt;  &amp;lt;/&lt;/font&gt;&lt;font color="#a31515" goog_docs_charindex="1379"&gt;system.serviceModel&lt;/font&gt;&lt;font color="#0000ff" goog_docs_charindex="1400"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;/font&gt;&lt;/div&gt;
 &lt;/div&gt;
&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/WCF"&gt;WCF&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/Ajax"&gt;Ajax&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/85.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/02/26/adding-a-json-endpoint-to-an-existing-wcf-service.aspx</guid>
            <pubDate>Sat, 27 Feb 2010 07:04:17 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/85.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/02/26/adding-a-json-endpoint-to-an-existing-wcf-service.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/85.aspx</wfw:commentRss>
        </item>
        <item>
            <title>WCF to JSON Dates and back again</title>
            <link>http://skysanders.net/subtext/archive/2010/02/18/wcf-to-json-dates-and-back-again.aspx</link>
            <description>&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I have been struggling with the seemingly unbeatable UTCness of js Date.getTime in respect to dealing with dates going between javascript and wcf. I tried adding the offset/60/1000, munging local times, closing one eye and sticking out my tongue and nothing. nothing. The server was always getting a utc long and treating it as a local.&lt;/p&gt;
&lt;p&gt;I have been following &lt;a target="_blank" href="http://west-wind.com/Weblog/ShowPost.aspx?id=214731"&gt;Rick's saga with wcf dates&lt;/a&gt; r.e. ajax and gave his solutions a go and got pleasant results with the .&lt;font size="2"&gt;parseWithDate() &lt;a target="_blank" href="http://www.west-wind.com/weblog/images/200901/ServiceProxy.zip"&gt;tweak to json2.js&lt;/a&gt; but &lt;/font&gt;could not get results with the .&lt;font size="2"&gt;stringifyWcf(). Got UTC with no offset no matter how much attention I gave it. Maybe I was just not getting something....&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;In any case...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;It turns out that, after reading the source for the server side parser that simply appending '-0000' will force the parser to consider the value as UTC and parse accordingly thus giving the correct local time at the endpoint.&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;js dates to/from wcf&lt;/strong&gt; &lt;/p&gt;
&lt;pre class="brush:js;"&gt;var tmp = {
    dateFromWcf: function (input, throwOnInvalidInput) {
        var pattern = /Date\(([^)]+)\)/;
        var results = pattern.exec(input);
        if (results.length != 2) {
            if (!throwOnInvalidInput) {
                return s;
            }
            throw new Error(s + " is not .net json date.");
        }
        return new Date(parseFloat(results[1]));
    },
    dateToWcf: function (input) {
        var d = new Date(input);
        if (isNaN(d)) {
            throw new Error("input not date");
        }
        // here is how we force wcf to parse as UTC and give correct local time serverside        
        var date = '\/Date(' + d.getTime() + '-0000)\/';
        return date;
    }
};
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Well, having to munge dates is just dirty and smelly so I went into Rick's json2.js mod and simply added the '-0000' to the replacer and bingo. It works great.&lt;/p&gt;
&lt;p&gt;Update: In some roundtripping tests I noticed that stringifyWcf is setting the date field of the object being stringified to the wcf date string. PU! Now that's what I call an undocumented and unexpected side effect. That has been fixed so now you get your object back in the same shape you sent it. ;-)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 2:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now I understand why Rick was modifying the input value, I am not sure he does though, can get no response from several comments left on his blog. In any case, &lt;a target="_blank" href="http://skysanders.net/subtext/archive/2010/02/24/confirmed-bug-in-firefox-3.6-native-json-implementation.aspx"&gt;Firefox 3.6 has a bug in the JSON replacer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So, for FF you need to force json2.js as shown in the post linked above and use this addon:&lt;/p&gt;
&lt;p&gt;&lt;strong /&gt;&lt;/p&gt;
&lt;pre class="brush:js;collapse:true"&gt;(function jsonWcfAddons() {
    // from https://west-wind.com/Weblog/posts/729630.aspx#262650
    // with some fairly significant fixes by sky sanders
    // http://skysanders.net/subtext/archive/2010/02/18/wcf-to-json-dates-and-back-again.aspx
    if (this.JSON &amp;amp;&amp;amp; !this.JSON.parseWithDate) {

        var reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/;
        var reMsAjax = /^\/Date\((d|-|.*)\)[\/|\\]$/;


        JSON.parseWithDate = function(json) {
            /// &amp;lt;summary&amp;gt;
            /// parses a JSON string and turns ISO or MSAJAX date strings
            /// into native JS date objects
            /// &amp;lt;/summary&amp;gt;    
            /// &amp;lt;param name="json" type="var"&amp;gt;json with dates to parse&amp;lt;/param&amp;gt;        
            /// &amp;lt;/param&amp;gt;
            /// &amp;lt;returns type="value, array or object" /&amp;gt;
            try {
                var res = JSON.parse(json,
            function(key, value) {
                if (typeof value === 'string') {
                    var a = reISO.exec(value);
                    if (a)
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]));
                    a = reMsAjax.exec(value);
                    if (a) {
                        var b = a[1].split(/[-+,.]/);
                        return new Date(b[0] ? +b[0] : 0 - +b[1]);
                    }
                }
                return value;
            });
                return res;
            } catch (e) {
                // orignal error thrown has no error message so rethrow with message
                throw new Error("JSON content could not be parsed");
                return null;
            }
        };
        JSON.stringifyWcf = function(json) {
            /// &amp;lt;summary&amp;gt;
            /// Wcf specific stringify that encodes dates in the
            /// a WCF compatible format ("/Date(9991231231)/")
            /// Note: this format works ONLY with WCF. 
            ///       ASMX can use ISO dates as of .NET 3.5 SP1
            /// &amp;lt;/summary&amp;gt;
            /// &amp;lt;param name="key" type="var"&amp;gt;property name&amp;lt;/param&amp;gt;
            /// &amp;lt;param name="value" type="var"&amp;gt;value of the property&amp;lt;/param&amp;gt;

            // choking on FF 3.6 date Wed Feb 24 2010 14:02:17 GMT-0700 (US Mountain Standard Time)
            return JSON.stringify(json, function(key, value) {
                if (typeof value == "string") {
                    var a = reISO.exec(value);
                    if (a) {
                        // SKY: the '-0000' forces the serverside serializer into utc mode resulting in accurate dates.
                        var val = '/Date(' + new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6])).getTime() + '-0000)/';

                        //SKY: rick, I don't think that asking for a JSON representation
                        // of an object should modify the state of the object. my 2 pesos.

                        //this[key] = val;

                        // this is the value that SHOULD be getting serialized but in the
                        // FF native JSON is ignoring this and serializing the member so I am guessing
                        // that is why rick is modifying the input object. gets the serialization job
                        // done properly but is a rather nasty undocumented side effect, in my opinion.
                        // I think it is probably better to overwrite native JSON with json2.js and
                        // get consistant results across platforms with out the need to modify the input
                        // UNLESS of course you are never going to need to use any of the objects that you
                        // serialize... 
                        return val;
                    }
                }
                return value;
            })
        };
        JSON.dateStringToDate = function(dtString) {
            /// &amp;lt;summary&amp;gt;
            /// Converts a JSON ISO or MSAJAX string into a date object
            /// &amp;lt;/summary&amp;gt;    
            /// &amp;lt;param name="" type="var"&amp;gt;Date String&amp;lt;/param&amp;gt;
            /// &amp;lt;returns type="date or null if invalid" /&amp;gt; 
            var a = reISO.exec(dtString);
            if (a)
                return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]));
            a = reMsAjax.exec(dtString);
            if (a) {
                var b = a[1].split(/[-,.]/);
                return new Date(+b[0]);
            }
            return null;
        };
    }
})();

&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;hr style="WIDTH: 100%; HEIGHT: 2px" /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/WCF"&gt;WCF&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/Ajax"&gt;Ajax&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/Javascript"&gt;Javascript&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/75.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/02/18/wcf-to-json-dates-and-back-again.aspx</guid>
            <pubDate>Fri, 19 Feb 2010 05:33:16 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/75.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/02/18/wcf-to-json-dates-and-back-again.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/75.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Get CustomAttributes the easy way....</title>
            <link>http://skysanders.net/subtext/archive/2010/01/20/get-customattributes-the-easy-way.aspx</link>
            <description>A few extension methods to help out.....
&lt;pre class="brush:c#;"&gt;
// Project: Salient.Reflection
// http://salient.codeplex.com

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

public static class AttributeHelpers
{
    /// &amp;lt;summary&amp;gt;
    /// Returns first non-inherited custom attribute of type T
    /// &amp;lt;/summary&amp;gt;
    public static T GetCustomAttribute&amp;lt;T&amp;gt;(this ICustomAttributeProvider provider)
        where T : Attribute
    {
        return GetCustomAttribute&amp;lt;T&amp;gt;(provider, false);
    }

    /// &amp;lt;summary&amp;gt;
    /// Returns first custom attribute of type T in the inheritance chain
    /// &amp;lt;/summary&amp;gt;
    public static T GetCustomAttribute&amp;lt;T&amp;gt;(this ICustomAttributeProvider provider, bool inherited)
        where T : Attribute
    {
        return provider.GetCustomAttributes&amp;lt;T&amp;gt;(inherited).FirstOrDefault();
    }

    /// &amp;lt;summary&amp;gt;
    /// Returns all non-inherited custom attributes of type T
    /// &amp;lt;/summary&amp;gt;
    public static List&amp;lt;T&amp;gt; GetCustomAttributes&amp;lt;T&amp;gt;(this ICustomAttributeProvider provider)
        where T : Attribute
    {
        return GetCustomAttributes&amp;lt;T&amp;gt;(provider, false);
    }

    /// &amp;lt;summary&amp;gt;
    /// Returns all custom attributes of type T in the inheritance chain
    /// &amp;lt;/summary&amp;gt;
    public static List&amp;lt;T&amp;gt; GetCustomAttributes&amp;lt;T&amp;gt;(this ICustomAttributeProvider provider, bool inherited)
        where T : Attribute
    {
        return provider.GetCustomAttributes(typeof (T), inherited).Cast&amp;lt;T&amp;gt;().ToList();
    }
}
&lt;/pre&gt;
&lt;hr /&gt;
Technorati tags: &lt;a rel="tag" href="http://technorati.com/tags/C#"&gt;C#&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/Reflection"&gt;Reflection&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/CodeProject-Tip"&gt;CodeProject-Tip&lt;/a&gt;&lt;img src="http://skysanders.net/subtext/aggbug/57.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sky Sanders</dc:creator>
            <guid>http://skysanders.net/subtext/archive/2010/01/20/get-customattributes-the-easy-way.aspx</guid>
            <pubDate>Thu, 21 Jan 2010 01:50:48 GMT</pubDate>
            <wfw:comment>http://skysanders.net/subtext/comments/57.aspx</wfw:comment>
            <comments>http://skysanders.net/subtext/archive/2010/01/20/get-customattributes-the-easy-way.aspx#feedback</comments>
            <wfw:commentRss>http://skysanders.net/subtext/comments/commentRss/57.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>