<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tony Williams &#187; Extension Methods</title>
	<atom:link href="http://blog.tonywilliams.me.uk/tag/extension-methods/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tonywilliams.me.uk</link>
	<description></description>
	<lastBuildDate>Tue, 10 Jan 2012 12:31:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Minify CSS &amp; JS With MVCContrib</title>
		<link>http://blog.tonywilliams.me.uk/minify-css-js-with-mvccontrib/</link>
		<comments>http://blog.tonywilliams.me.uk/minify-css-js-with-mvccontrib/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 15:49:49 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Asp.Net MVC]]></category>
		<category><![CDATA[Asp.Net MVC2]]></category>
		<category><![CDATA[Css]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Minify]]></category>

		<guid isPermaLink="false">http://blog.tonywilliams.me.uk/?p=83</guid>
		<description><![CDATA[Combine/compress and minify css and js]]></description>
			<content:encoded><![CDATA[<p>I was doing a bit of research recently trying to find a way to compress, combine and minify css and js in Asp.Net MVC 2 and found a few ideas on the subject. The one that caught my eye was the <a href="http://mvccontrib.codeplex.com/">MvcContrib</a> <a href="http://blog.neverrunwithscissors.com/2009/09/27/includecombiner-merged-into-mvccontrib-as-mvccontrib-includehandling/">IncludeHandling</a>; a little hidden gem.</p>
<p>Getting it up a running however wasn&#8217;t so straight forward (there isn&#8217;t much documentation about it, or at least not much I could find.). The first problem I stumbled upon was the <a href="http://mvccontrib.codeplex.com/SourceControl/changeset/view/49cb4d10ec95#src%2fMvcContrib.IncludeHandling%2fIncludeCombinerHtmlExtensions.cs">HtmlExtensions</a> (RenderIncludes function) required a dependency resolver which the project I was on didn&#8217;t use. To get round this I simply copied the source (from the HtmlExtensions link) and replaced the dependency resolver with the projects IoC framework (in this case we&#8217;re using <a href="http://mvcturbine.codeplex.com/">MvcTurbine</a> with <a href="http://ninject.org/">Ninject</a>)</p>
<p>Next you need to register the dependency with your IoC of choice, like I said previously we&#8217;re using MvcTurbine so this is how I did with with a service registration.</p>
<pre class="brush:c#">
namespace YourProject.MvcSite.Registration
{
  using System.Web;
  using MvcContrib;
  using MvcContrib.IncludeHandling;
  using MvcContrib.IncludeHandling.Configuration;
  using MvcTurbine.ComponentModel;

  /// &lt;summary&gt;
  /// Regisers the minify interfaces
  /// &lt;/summary&gt;
  public class MinifyRegistration  : IServiceRegistration
  {
    /// &lt;summary&gt;
    /// Registers the components with the specified &lt;see cref=&quot;T:MvcTurbine.ComponentModel.IServiceLocator&quot;/&gt; instance.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;locator&quot;&gt;Instance of &lt;see cref=&quot;T:MvcTurbine.ComponentModel.IServiceLocator&quot;/&gt; to use.&lt;/param&gt;
    public void Register(IServiceLocator locator)
    {
      var httpContext = new HttpContextProvider(HttpContext.Current);
      var handler = new IncludeHandlingSectionHandler();
      var reader = new IncludeReader(httpContext);
      var storage = new StaticIncludeStorage(new KeyGenerator());

      locator.Register&lt;IIncludeHandlingSettings&gt;(handler);
      locator.Register&lt;IIncludeCombiner&gt;(new IncludeCombiner(handler, reader, storage, httpContext));
    }
  }
}
</pre>
<p>The final step is to select the js/css files you want and then combine them. In the example below we&#8217;re using the T4MVC template to generate the static file links which and the code is used in a view (in our example it&#8217;s the site master view).</p>
<pre class="brush:c#">
    &lt;%
      var scripts = new List&lt;string&gt;
                      {
                        &quot;~&quot; + Links.Scripts.jquery_1_4_2_min_js,
                        &quot;~&quot; + Links.Scripts.jquery_ui_1_8_2_custom_min_js,
                        &quot;~&quot; + Links.Scripts.jquery_localscroll_1_2_7_min_js,
                        &quot;~&quot; + Links.Scripts.jquery_scrollTo_1_4_2_min_js,
                        &quot;~&quot; + Links.Scripts.jquery_serialScroll_1_2_2_min_js,
                        &quot;~&quot; + Links.Scripts.Ajax_js,
                        &quot;~&quot; + Links.Scripts.Custom_js,
                        &quot;~&quot; + Links.Scripts.json2_js,
                        &quot;~&quot; + Links.Scripts.flowplayer_3_2_3_min_js,
                        &quot;~&quot; + Links.Scripts.DragDrop_js,
                        &quot;~&quot; + Links.Scripts.Slider_js
                      };
    %&gt;

    &lt;%=Html.RenderJs(scripts)%&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonywilliams.me.uk/minify-css-js-with-mvccontrib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serialising / Deserialising objects to Xml in .Net</title>
		<link>http://blog.tonywilliams.me.uk/serialising-deserialising-objects-to-xml-in-net/</link>
		<comments>http://blog.tonywilliams.me.uk/serialising-deserialising-objects-to-xml-in-net/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 08:26:14 +0000</pubDate>
		<dc:creator>Tony</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Serialisation]]></category>

		<guid isPermaLink="false">http://blog.tonywilliams.me.uk/?p=34</guid>
		<description><![CDATA[Extension method for serialisation of classes to xml]]></description>
			<content:encoded><![CDATA[<p>Serialising / Deserialising objects to Xml: from my <a href="http://stackoverflow.com/questions/271398/what-are-your-favorite-extension-methods-for-c-codeplex-com-extensionoverflow/271423#271423">StackOverFlow</a></p>
<pre class="brush:c#">private static readonly Dictionary&lt;Type, XmlSerializer&gt; serialisers = new Dictionary&lt;Type, XmlSerializer&gt;();

/// &lt;summary&gt;Serialises an object of type T in to an xml string&lt;/summary&gt;
/// &lt;typeparam name="T"&gt;Any class type&lt;/typeparam&gt;
/// &lt;param name="objectToSerialise"&gt;Object to serialise&lt;/param&gt;
/// &lt;returns&gt;A string that represents Xml, empty oterwise&lt;/returns&gt;
public static string XmlSerialise&lt;T&gt;(this T objectToSerialise) where T : class, new()
{
  XmlSerializer serialiser;

  var type = typeof(T);
  if (!serialisers.ContainsKey(type))
  {
    serialiser = new XmlSerializer(type);
    serialisers.Add(type, serialiser);
  }
  else
  {
    serialiser = serialisers[type];
  }

  string xml;
  using (var writer = new StringWriter())
  {
    serialiser.Serialize(writer, objectToSerialise);
    xml = writer.ToString();
  }

  return xml;
}

/// &lt;summary&gt;Deserialises an xml string in to an object of Type T&lt;/summary&gt;
/// &lt;typeparam name="T"&gt;Any class type&lt;/typeparam&gt;
/// &lt;param name="xml"&gt;Xml as string to deserialise from&lt;/param&gt;
/// &lt;returns&gt;A new object of type T is successful, null if failed&lt;/returns&gt;
public static T XmlDeserialise&lt;T&gt;(this string xml) where T : class, new()
{
  XmlSerializer serialiser;

  var type = typeof(T);
  if (!serialisers.ContainsKey(type))
  {
    serialiser = new XmlSerializer(type);
    serialisers.Add(type, serialiser);
  }
  else
  {
    serialiser = serialisers[type];
  }

  T newObject;

  using (var reader = new StringReader(xml))
  {
    try { newObject = (T)serialiser.Deserialize(reader); }
    catch { return null; } // Could not be deserialized to this type.
  }

  return newObject;
}</pre>
<p>When building the serialisation I had a help from an online example &#8211; but cannot remeber where it is&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tonywilliams.me.uk/serialising-deserialising-objects-to-xml-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

