<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Personal Blog of Sonickat</title>
	<atom:link href="http://sonickat.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sonickat.wordpress.com</link>
	<description>A braindump and historical archive for my own personal use.</description>
	<lastBuildDate>Tue, 13 Dec 2011 21:43:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sonickat.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Personal Blog of Sonickat</title>
		<link>http://sonickat.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sonickat.wordpress.com/osd.xml" title="Personal Blog of Sonickat" />
	<atom:link rel='hub' href='http://sonickat.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Javascript, Script Namespace, and Intellisense</title>
		<link>http://sonickat.wordpress.com/2011/12/13/javascript-script-namespace-and-intellisense/</link>
		<comments>http://sonickat.wordpress.com/2011/12/13/javascript-script-namespace-and-intellisense/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 21:43:08 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=151</guid>
		<description><![CDATA[I work nearly exclusively in Visual Studio on a daily basis and one of the tools that is easy to overlook but blatantly missing when it is absent is IntellSense for certain languages.  I&#8217;ve been working with projects with multiple javascript files which load independently of one another for a few years now and it has always been my frustration [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=151&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I work nearly exclusively in Visual Studio on a daily basis and one of the tools that is easy to overlook but blatantly missing when it is absent is IntellSense for certain languages.  I&#8217;ve been working with projects with multiple javascript files which load independently of one another for a few years now and it has always been my frustration that I don&#8217;t get IntellSense for global variables and functions defined in other files.</p>
<p>Today I did some digging through stack overflow and the web and discovered that this functionality is not actually missing it just requires a bit more work.</p>
<p>Details after the break.</p>
<p><span id="more-151"></span></p>
<p>Getting IntelliSense working in Visual Studio is as simple as adding a single line of code to the top of your java-script file.</p>
<blockquote><p>/// &lt;reference path=&#8221;/core/scripts/tclib.js&#8221; /&gt;</p></blockquote>
<p>This got me thinking even further on how can I namespace all my scripts to prevent collisions between multiple files and also build a core library since I now can rely on IntelliSense in other script files.</p>
<p>I ran across a post on StackOverflow which presented exactly the solution I needed.  Rather than rehash the great explanation there, I am just going to provide the <a href="http://stackoverflow.com/questions/2504568/javascript-namespace-declaration">Link</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/151/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/151/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=151&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/12/13/javascript-script-namespace-and-intellisense/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing a JSONP Webservice in C# .Net</title>
		<link>http://sonickat.wordpress.com/2011/11/19/implementing-a-jsonp-webservice-in-c-net/</link>
		<comments>http://sonickat.wordpress.com/2011/11/19/implementing-a-jsonp-webservice-in-c-net/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 16:36:50 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Asp.net (C#)]]></category>
		<category><![CDATA[C# Generic Methods and Classes]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=147</guid>
		<description><![CDATA[I am working on a project currently where I wished to share non secure data across domains using Javascript and JSON objects. After several hours of tinkering and researching I finally was able to figure out a solution which works in the normal .NET framework. There are several pieces that make this work: First: The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=147&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am working on a project currently where I wished to share non secure data across domains using Javascript and JSON objects.</p>
<p>After several hours of tinkering and researching I finally was able to figure out a solution which works in the normal .NET framework.</p>
<p><span id="more-147"></span></p>
<p>There are several pieces that make this work:</p>
<h2>First: The WebForm</h2>
<p>I wiped out everything no the .aspx page except the declaration that the page existed.</p>
<blockquote><p>&lt;%@ Page Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; CodeFile=&#8221;TokenGenerator.aspx.cs&#8221; Inherits=&#8221;TokenGenerator&#8221; %&gt;</p></blockquote>
<p><strong>Second: The Code Behind</strong></p>
<p>On page load we need to wipe out the request and rewrite it so that we are only returning the desired JSON information.  In order for the cross domain information to work we also need to wrap our json with the desired callback method.  In my example I am not accessing any datasource nor am I passing extra query strings but you could using query strings turn a single page into a web service that handles multiple JSON data calls in theory.</p>
<blockquote><p>using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;</p>
<p>public partial class TokenGenerator : System.Web.UI.Page<br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (Request.QueryString["callback"] != null)<br />
{<br />
string CallBackSignature = Request.QueryString["callBack"];<br />
string json = CallBackSignature + &#8220;({\&#8221;name\&#8221;:\&#8221;Joe\&#8221;})&#8221;;<br />
Response.Clear();<br />
Response.ContentType = &#8220;application/json; charset=utf-8&#8243;;<br />
Response.Write(json);<br />
}<br />
}<br />
}</p></blockquote>
<h2>Lastly &#8211; The Javascript</h2>
<p>Using JQuery to check if the dom is ready we can call our webservice page.</p>
<blockquote><p>$(document).ready(function () {<br />
GetJSONFromURL(&#8220;http://www.somedomain.com/TokenGenerator.aspx?callback=?&#8221;, CallBack);<br />
});</p>
<p>function CallBack(response){<br />
// Do Something with the response &#8211; which should be your data<br />
}</p>
<p>function GetJSONFromURL(url,success) {<br />
var ud = &#8216;_&#8217; + +new Date,<br />
script = document.createElement(&#8216;script&#8217;),<br />
head = document.getElementsByTagName(&#8216;head&#8217;)[0]<br />
|| document.documentElement;</p>
<p>window[ud] = function (data) {<br />
head.removeChild(script);<br />
success &amp;&amp; success(data);<br />
};</p>
<p>script.src = url.replace(&#8216;callback=?&#8217;, &#8216;callback=&#8217; + ud);<br />
head.appendChild(script);<br />
}</p></blockquote>
<p>And whalla you now have a cross domain way to access data via JSON services.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/147/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=147&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/11/19/implementing-a-jsonp-webservice-in-c-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessing Parent DataItems in Nested ASP.Net Repeaters</title>
		<link>http://sonickat.wordpress.com/2011/11/10/accessing-parent-dataitems-in-nested-asp-net-repeaters/</link>
		<comments>http://sonickat.wordpress.com/2011/11/10/accessing-parent-dataitems-in-nested-asp-net-repeaters/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 19:31:21 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Asp.net (C#)]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=144</guid>
		<description><![CDATA[Short and Sweet. I have a project at work right now where I needed to generate a unique id for an object based on the parent repeaters ItemIndex. I found this bit of code which worked beautifully &#60;ItemTemplate&#62; &#60;%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %&#62; &#60;/ItemTemplate&#62;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=144&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Short and Sweet.</p>
<p>I have a project at work right now where I needed to generate a unique id for an object based on the parent repeaters ItemIndex.</p>
<p>I found this bit of code which worked beautifully</p>
<blockquote><p>&lt;ItemTemplate&gt;<br />
&lt;%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %&gt;<br />
&lt;/ItemTemplate&gt;</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/144/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=144&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/11/10/accessing-parent-dataitems-in-nested-asp-net-repeaters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Reflections</title>
		<link>http://sonickat.wordpress.com/2011/11/09/c-reflections/</link>
		<comments>http://sonickat.wordpress.com/2011/11/09/c-reflections/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 07:13:36 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Asp.net (C#)]]></category>
		<category><![CDATA[C# Generic Methods and Classes]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=140</guid>
		<description><![CDATA[I&#8217;m working on a project right now where I have an XML data source that is provided by a third party and I need to import the data into a usable object model which I plan to store in MongoDB. I didn&#8217;t want to have to write a ton of redundant code for each and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=140&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project right now where I have an XML data source that is provided by a third party and I need to import the data into a usable object model which I plan to store in MongoDB.</p>
<p>I didn&#8217;t want to have to write a ton of redundant code for each and every field on the object in a factory pattern. There is literally about 40 to 50 fields on this object.</p>
<p>What I discovered is this cool thing called reflection.</p>
<p>Here is the code snippet:</p>
<blockquote>
<pre>var name = "PropertyName";
var newValue = "This is my value I want to set";

PropertyInfo prop = obj.GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
if (null != prop &amp;&amp; prop.CanWrite)
{
      prop.SetValue(obj, Convert.ChangeType(newValue, prop.PropertyType), null);
}</pre>
</blockquote>
<p>Essentially the first two lines here are ensuring that firstly the property exists on the object and secondly that the property is settable.</p>
<p>Since all the properties on my object match up to fields on my datasource, at least the fields I want to translate over do, this works great.</p>
<p>Here is the method I wrote that allows me to pass an XElement with a Generic and iteratively populate all the fields of the object from values nested within the XElement.</p>
<blockquote>
<pre>private static T BuildByReflection&lt;T&gt;(XElement element) where T : new()
{
   var obj = new T();
   foreach (var subElem in element.Elements())
   {
      var name = subElem.Name.LocalName;
      PropertyInfo prop = obj.GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
      if (null != prop &amp;&amp; prop.CanWrite)
      {
          prop.SetValue(obj, Convert.ChangeType(subElem.Value, prop.PropertyType), null);
      }
   }

   return obj;
}</pre>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/140/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=140&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/11/09/c-reflections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ and OrderBy()</title>
		<link>http://sonickat.wordpress.com/2011/10/28/linq-and-orderby/</link>
		<comments>http://sonickat.wordpress.com/2011/10/28/linq-and-orderby/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 17:55:59 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Asp.net (C#)]]></category>
		<category><![CDATA[C# Generic Methods and Classes]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=137</guid>
		<description><![CDATA[I mentioned this cool little method in my previous post and felt it was worth an explanation. Up until recently when I wanted to sort a generic list of objects I used the methods I outlined back in June of 2011. Recently using LINQ I&#8217;ve discovered a much more compact code method: .OrderBy(); Let&#8217;s assume [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=137&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I mentioned this cool little method in my previous post and felt it was worth an explanation.</p>
<p>Up until recently when I wanted to sort a generic list of objects I used the methods <a href="http://sonickat.wordpress.com/2010/07/20/how-to-sort-a-generic-list/">I outlined back in June of 2011</a>.</p>
<p>Recently using LINQ I&#8217;ve discovered a much more compact code method:</p>
<blockquote><p>
.OrderBy();
</p></blockquote>
<p>Let&#8217;s assume we are using our old CoffeeMaker class&#8230;</p>
<blockquote><p>
class CoffeeMaker<br />
{</p>
<p>[...]</p>
<p>public int ID;<br />
public string Name;<br />
public decimal Price;</p>
<p>}</p></blockquote>
<p>And we have a list of CoffeeMakers that we want to sort on the Name.</p>
<p>We simply do the following:</p>
<blockquote><p>
List cMakers = GetCoffeeMakers();<br />
cMakers.OrderBy(cm =&gt; cm.Name);
</p></blockquote>
<p>Much shorter for scenarios where you wont be reusing the sort routine frequently and the use doesn&#8217;t dictate the neccessity of implementing the full IComparable interface.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/137/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/137/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/137/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=137&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/10/28/linq-and-orderby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>Sorting Anonymous Types</title>
		<link>http://sonickat.wordpress.com/2011/10/28/sorting-anonymous-types/</link>
		<comments>http://sonickat.wordpress.com/2011/10/28/sorting-anonymous-types/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 17:39:50 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=132</guid>
		<description><![CDATA[I have a WebService which I want to return an array of objects. The source of the data is a complex non-JSON compatible object which contains a slew of data which would contribute to the WebService Response size. My solution was to use convert my collection to a list of anonymous objects with just the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=132&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have a WebService which I want to return an array of objects.  The source of the data is a complex non-JSON compatible object which contains a slew of data which would contribute to the WebService Response size.  My solution was to use convert my collection to a list of anonymous objects with just the data I needed.  You may recognize this code from my previous post several months ago.</p>
<blockquote><p>var results = (from fc in product<br />
               select<br />
               new{<br />
                  FriendlyID = fc.FriendlyID,<br />
                  Name = fc.ExtendedValue(&#8220;Name&#8221;),<br />
                  }).ToList();</p></blockquote>
<p>This code chunk essentially creates an object which exposes two string parameters: FriendlyID and Name.</p>
<p>The issue arose later when the project requirements necessitated that the results be sorted.  I obviously could have simply sorted the list called &#8216;product&#8217; but I wanted to figure out how to sort the anonymous objects.<br />
<span id="more-132"></span></p>
<blockquote><p>results.Sort();</p></blockquote>
<p>The code above wouldn&#8217;t work, since this is a collection of anonymous objects.  The compiler simply needs to be told how these objects should be sorted.  It can sort simple types such as doubles, strings, integers, etc.  It doesn&#8217;t know how to sort collections of anonymous types.</p>
<p>C# 3.0 offers a great mechanism for this:</p>
<blockquote><p> .OrderBy();</p></blockquote>
<p>Normally you would pass an argument into this such as&#8230;</p>
<blockquote><p>results.OrderBy(sot =&gt; sot.SortParameter);</p></blockquote>
<p>The problem is that we don&#8217;t have an object type for anonymous type for which to expose any sort of parameter to sort on.</p>
<p>This is where generics comes to the rescue.</p>
<blockquote><p>IEnumerable Cast(IEnumerable collection, T type)<br />
{<br />
    return collection.Cast();<br />
}</p></blockquote>
<p>Implementing the above method i can then sort using:</p>
<blockquote><p>results = Cast(results, new { FriendlyID = &#8220;&#8221;, Name = &#8220;&#8221; }).OrderBy(ob =&gt; ob.FriendlyID).ToList();</p></blockquote>
<p>And like magic my anonymous object list is now sorted on the FriendlyID field.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/132/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=132&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/10/28/sorting-anonymous-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>Binding DropDownList.DataTextField to an Unrepresented Field in Object Collection</title>
		<link>http://sonickat.wordpress.com/2011/03/22/binding-dropdownlist-datatextfield-to-an-unrepresented-field-in-object-collection/</link>
		<comments>http://sonickat.wordpress.com/2011/03/22/binding-dropdownlist-datatextfield-to-an-unrepresented-field-in-object-collection/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 01:32:24 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=130</guid>
		<description><![CDATA[Pretty basic and probably pretty specific need. I&#8217;ve got an object collection and the objects don&#8217;t expose a property which I need to use as a text field.  You have to define these fields by a string so you need to define a custom datasource using your original collection. IQueryable&#60;Place&#62; places = AppVars.ServiceUtility.ALL&#60;Place&#62;(); DropDownList_NPC_Places.DataSource = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=130&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Pretty basic and probably pretty specific need.</p>
<p>I&#8217;ve got an object collection and the objects don&#8217;t expose a property which I need to use as a text field.  You have to define these fields by a string so you need to define a custom datasource using your original collection.</p>
<blockquote><p>IQueryable&lt;Place&gt; places = AppVars.ServiceUtility.ALL&lt;Place&gt;();<br />
DropDownList_NPC_Places.DataSource =<br />
(from Place in places<br />
select new{<br />
Name = Place.Name,<br />
OId = Place.ID.ToString()<br />
}).ToList();<br />
DropDownList_NPC_Places.DataTextField = &#8220;Name&#8221;;<br />
DropDownList_NPC_Places.DataValueField = &#8220;OId&#8221;;<br />
DropDownList_NPC_Places.DataBind();</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/130/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/130/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/130/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=130&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/03/22/binding-dropdownlist-datatextfield-to-an-unrepresented-field-in-object-collection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>JScript Editor Extensions for Visual Studio</title>
		<link>http://sonickat.wordpress.com/2011/02/28/jscript-editor-extensions-for-visual-studio/</link>
		<comments>http://sonickat.wordpress.com/2011/02/28/jscript-editor-extensions-for-visual-studio/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 17:03:08 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=126</guid>
		<description><![CDATA[http://visualstudiogallery.msdn.microsoft.com/872d27ee-38c7-4a97-98dc-0d8a431cc2ed<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=126&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>http://visualstudiogallery.msdn.microsoft.com/872d27ee-38c7-4a97-98dc-0d8a431cc2ed</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=126&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2011/02/28/jscript-editor-extensions-for-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>How to sort a generic List</title>
		<link>http://sonickat.wordpress.com/2010/07/20/how-to-sort-a-generic-list/</link>
		<comments>http://sonickat.wordpress.com/2010/07/20/how-to-sort-a-generic-list/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 02:36:36 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=122</guid>
		<description><![CDATA[It&#8217;s been awhile since I did a brain dump but I promise todays dump will be interesting and exciting. One of the new things that I have been working with at work is the strongly typed generic List&#60;T&#62; this class functions much like an ArrayList except that you&#8217;r not forced to guess what is bundled [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=122&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been awhile since I did a brain dump but I promise todays dump will be interesting and exciting.</p>
<p>One of the new things that I have been working with at work is the strongly typed generic List&lt;T&gt; this class functions much like an ArrayList except that you&#8217;r not forced to guess what is bundled inside.  It wasn&#8217;t long though before I encountered a situation where I wanted to sort this list like you do with an ArrayList.  The only problem was that the same sort methods do not work.</p>
<p>Doing some research on the web I ran across some posts that pointed to a really neat method which when implemented looks like this:</p>
<blockquote><p>List&lt;CoffeeMaker&gt; coffeeMakers = GetCoffeeMakers();<br />
coffeeMakers.Sort(CoffeeMaker.SortByName);</p>
<p><span id="more-122"></span></p></blockquote>
<p>This looks alot like how you sort an arraylist however the way we had been previously doing it at work would result in a sort looking something like this:</p>
<blockquote>
<div id="_mcePaste">ArrayList coffeeMakers= GetCoffeeMakers();</div>
<p>coffeeMakers.Sort(new rootNamespace.subNamespace.Sorts.coffeeMakers());</p></blockquote>
<p>There are two inherent issues with this first we don&#8217;t really know what objects are inside the coffeeMakers ArrayList and secondly our sort is maintained in a separate class file than our actual object.  But really these two objects the sort methods and the class itself are coupled and there is no need to separate them.  It&#8217;s also very easy to remember where your sorts are if you could say put them in the class themselves.</p>
<p>Well the Comparison&lt;T&gt; delegate provides a great way to do this.  Here is how we can get the result posted first above and also keep the code in the file.</p>
<p>Let&#8217;s build the class above&#8230;.</p>
<blockquote><p>class CoffeeMaker<br />
{</p>
<p style="padding-left:30px;">[...]</p>
<p style="padding-left:30px;">public int ID;<br />
public string Name;<br />
public decimal Price;</p>
<p>}</p></blockquote>
<p>The first thing we need to do is make the class inherit from the IComparable&lt;T&gt; baseclass.  While we are doing this we need to implement a CompareTo method otherwise we will get a compiler error form inheriting the IComparable class.  We might as well make this sort on the Name.  This is teh method which will be used by default if you call .Sort() without passing any parameters.</p>
<blockquote><p>class CoffeeMaker : IComparable&lt;CoffeeMaker&gt;<br />
{</p>
<p style="padding-left:30px;">[...]</p>
<p style="padding-left:30px;">public int ID;<br />
public string Name;<br />
public decimal Price;</p>
<p style="padding-left:30px;">[...]</p>
<p style="padding-left:30px;">public int CompareTo(CoffeeMaker other)<br />
{</p>
<p style="padding-left:60px;">return  this.Name.CompareTo(other.Name);</p>
<p style="padding-left:30px;">}</p>
<p>}</p></blockquote>
<p>Okay thats fine and dandy but how do we sort by other properties how do we make that handy dandy looking sorting in the very first code snippet.  We are going to define static Comparison&lt;T&gt; inside our object class.  See Below.</p>
<blockquote><p>class CoffeeMaker : IComparable&lt;CoffeeMaker&gt;<br />
{</p>
<p style="padding-left:30px;">public static Comparison&lt;CoffeeMaker&gt; SortByID =</p>
<p style="padding-left:60px;">delegate(CoffeeMaker cm1, CoffeeMaker c2)<br />
{<br />
return cm1.ID.CompareTo(cm2.ID);<br />
};</p>
<p style="padding-left:30px;">[...]</p>
<p style="padding-left:30px;">public int ID;<br />
public string Name;<br />
public decimal Price;</p>
<p style="padding-left:30px;">[...]</p>
<p style="padding-left:30px;">public int CompareTo(CoffeeMaker other)<br />
{</p>
<p style="padding-left:60px;">return  this.Name.CompareTo(other.Name);</p>
<p style="padding-left:30px;">}</p>
<p>}</p></blockquote>
<p>This is all still kind of new to me so there may be greater complexity to this than first meets the eye but so far it seems simple its clean and it solves the design problem I have encountered of needing to sort a generic List&lt;T&gt;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=122&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2010/07/20/how-to-sort-a-generic-list/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with LUA in .Net</title>
		<link>http://sonickat.wordpress.com/2010/03/09/working-with-lua-in-net/</link>
		<comments>http://sonickat.wordpress.com/2010/03/09/working-with-lua-in-net/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 00:26:31 +0000</pubDate>
		<dc:creator>sonickat</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sonickat.wordpress.com/?p=119</guid>
		<description><![CDATA[So I&#8217;ve attempted several projects in the past few years to work with the .LUA files saved by addons in Worlds of Warcraft.  I&#8217;ve always approached this from a parse using regex approach which was time consuming and often riddled with hokey code. Recently I stumbled across LuaInterface after a fairly steep learning curve I figured [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=119&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve attempted several projects in the past few years to work with the .LUA files saved by addons in Worlds of Warcraft.  I&#8217;ve always approached this from a parse using regex approach which was time consuming and often riddled with hokey code.</p>
<p>Recently I stumbled across <a href="http://luaforge.net/projects/luainterface/">LuaInterface</a> after a fairly steep learning curve I figured out how to work with the data and thought that I would share.</p>
<p>First of all download the files from: <a href="http://luaforge.net/frs/?group_id=50">http://luaforge.net/frs/?group_id=50</a></p>
<p>As of this article the current revision was 2.0.3</p>
<p>In the archive you should find two different DLL files which you will need to put in the &#8216;bin&#8217; folder in your project.</p>
<p>Here is a sample of a class object constructor I used in a recent project using LuaInterface.</p>
<blockquote>
<div id="_mcePaste">// Initialize the Lua Object</div>
<div id="_mcePaste">var result = lua.DoFile(pathToDataStoreLua);</div>
<div></div>
<div id="_mcePaste">// Parse all the characters</div>
<div id="_mcePaste">System.Collections.Specialized.ListDictionary ld = lua.GetTableDict(lua.GetTable(&#8220;DataStore_AuctionsDB.global.Characters&#8221;));</div>
<div></div>
<div id="_mcePaste">foreach (DictionaryEntry de in ld)</div>
<div id="_mcePaste">{</div>
<div id="_mcePaste">// Do Something</div>
<div id="_mcePaste">}</div>
</blockquote>
<div id="_mcePaste">Something I want to point out with this is that every result ends up being a collection of DictionaryEntry objects.  The key is always the key but since LUA can have multidimensional tables you can have a value that is an actual value or is a LuaInterface.LuaTable object which you then can foreach through again to look for another subset of DictionaryEntry objects.</div>
<div></div>
<div>You&#8217;ll also notice that the base table you start with using the lua.GetTable() calls for the LUA table in the file and uses the dot syntax to nest down through layers of records to begin with.</div>
<div>
I ran into a problem I have not figured out yet where one of the DataStore addon&#8217;s LUA table&#8217;s key&#8217;s has periods in it such at: Default.Hellscream.Character</div>
<div></div>
<div>I am not sure how to declare a section of my reference as literal.</div>
<div></div>
<div>Also the pathToDataStoreLua is the mapped server path to the file.  I am saving the lua file to a local temp file and then from there reading it.</div>
<div>
I&#8217;ve only scratched the surface of using this great tool but so far it&#8217;s been a phenomenal tool.</div>
<blockquote>
<div></div>
</blockquote>
<blockquote></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sonickat.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sonickat.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sonickat.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sonickat.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sonickat.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sonickat.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sonickat.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sonickat.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sonickat.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sonickat.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sonickat.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sonickat.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sonickat.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sonickat.wordpress.com/119/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sonickat.wordpress.com&amp;blog=5265715&amp;post=119&amp;subd=sonickat&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sonickat.wordpress.com/2010/03/09/working-with-lua-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3a611aeeb7ff829ce9d573da9b15499a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sonickat</media:title>
		</media:content>
	</item>
	</channel>
</rss>
