<?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>UH.LEE.KA &#187; C#</title>
	<atom:link href="http://www.uhleeka.com/blog/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.uhleeka.com/blog</link>
	<description>If you think nobody cares about you, try missing a few car payments.</description>
	<lastBuildDate>Wed, 25 Aug 2010 01:35:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generic List&lt;T&gt; to DataTable using Reflection</title>
		<link>http://www.uhleeka.com/blog/2010/01/generic-list-to-datatable-using-reflection/</link>
		<comments>http://www.uhleeka.com/blog/2010/01/generic-list-to-datatable-using-reflection/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 04:31:23 +0000</pubDate>
		<dc:creator>uhleeka</dc:creator>
				<category><![CDATA[Code Snippits]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[snippit]]></category>

		<guid isPermaLink="false">http://www.uhleeka.com/blog/?p=498</guid>
		<description><![CDATA[The following function takes in a System.Collections.Generic.List&#60;T&#62; and returns a System.Data.DataTable with the properties (via reflection) of T as columns. public static System.Data.DataTable ListToDataTable&#60;T&#62;( &#160; &#160; System.Collections.Generic.IList&#60;T&#62; elements) { &#160; &#160; System.Reflection.PropertyInfo[] arrPropInfo = typeof(T).GetProperties(); &#160; &#160; System.Data.DataTable dt = new DataTable(); &#160; &#160; System.Data.DataRow dr; &#160; &#160; foreach (System.Reflection.PropertyInfo pInfo in arrPropInfo) &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<div style="float:left;width:93px;height:93px;margin:8px 8px 0px 0px;border:solid 1px #006;background-color:#fff;background-repeat:no-repeat;background-position:15px center;background-image:url('http://www.uhleeka.com/blog/wp-content/uploads/2009/08/windows-150x150.png');"></div>
<p>The following function takes in a System.Collections.Generic.List&lt;T&gt; and returns a System.Data.DataTable with the properties (via reflection) of T as columns.  <span id="more-498"></span></p>
<div style="overflow:hidden;clear:both;"><!-- --></div>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>public static System.Data.DataTable ListToDataTable&lt;T&gt;(
&nbsp; &nbsp; System.Collections.Generic.IList&lt;T&gt; elements)
{
&nbsp; &nbsp; System.Reflection.PropertyInfo[] arrPropInfo = typeof(T).GetProperties();
&nbsp; &nbsp; System.Data.DataTable dt = new DataTable();
&nbsp; &nbsp; System.Data.DataRow dr;

&nbsp; &nbsp; foreach (System.Reflection.PropertyInfo pInfo in arrPropInfo)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; dt.Columns.Add(pInfo.Name, pInfo.PropertyType);
&nbsp; &nbsp; }
&nbsp; &nbsp; foreach(object elem in elements)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; dr = dt.NewRow();
&nbsp; &nbsp; &nbsp; &nbsp; foreach (System.Reflection.PropertyInfo pInfo in arrPropInfo)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dr[pInfo.Name] = pInfo.GetValue(elem, null);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; dt.Rows.Add(dr);
&nbsp; &nbsp; }

&nbsp; &nbsp; return dt;
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.uhleeka.com/blog/2010/01/generic-list-to-datatable-using-reflection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C# Serialization</title>
		<link>http://www.uhleeka.com/blog/2010/01/c-serialization/</link>
		<comments>http://www.uhleeka.com/blog/2010/01/c-serialization/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 04:15:46 +0000</pubDate>
		<dc:creator>uhleeka</dc:creator>
				<category><![CDATA[Code Snippits]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[snippit]]></category>

		<guid isPermaLink="false">http://www.uhleeka.com/blog/?p=490</guid>
		<description><![CDATA[Xml Serialization and Binary Serialization to a Base64 string Xml Serialization Snippit: Take a serializable object and serialize it into an xml string, stored in a System.Text.StringBuilder System.Xml.Serialization.XmlSerializer serializer = &#160; &#160; new System.Xml.Serialization.XmlSerializer(typeof(ObjectToSerialize)); System.Text.StringBuilder sb = new System.Text.StringBuilder(); using (System.IO.StringWriter stringWriter = new System.IO.StringWriter(sb)) { &#160; &#160; serializer.Serialize(stringWriter, myObject); &#160; &#160; stringWriter.Close(); } Binary [...]]]></description>
			<content:encoded><![CDATA[<div style="float:left;width:93px;height:93px;margin:8px 8px 0px 0px;border:solid 1px #006;background-color:#fff;background-repeat:no-repeat;background-position:15px center;background-image:url('http://www.uhleeka.com/blog/wp-content/uploads/2009/08/windows-150x150.png');"></div>
<p>Xml Serialization and Binary Serialization to a Base64 string<span id="more-490"></span></p>
<h4 style="clear:both;">Xml Serialization</h4>
<p>Snippit: Take a serializable object and serialize it into an xml string, stored in a System.Text.StringBuilder</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>System.Xml.Serialization.XmlSerializer serializer = 
&nbsp; &nbsp; new System.Xml.Serialization.XmlSerializer(typeof(<em>ObjectToSerialize</em>));
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (System.IO.StringWriter stringWriter = new System.IO.StringWriter(sb))
{
&nbsp; &nbsp; serializer.Serialize(stringWriter,  <em>myObject</em>);
&nbsp; &nbsp; stringWriter.Close();
}</pre></div></div>

<h4>Binary Serialization to Base64 string</h4>
<p>Snippit:  Take a serializable object and serialize it into a Base64 string</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>byte[] bResult;
System.Runtime.Serialization.IFormatter formatter =
&nbsp; &nbsp; new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (System.IO.MemoryStream s = new System.IO.MemoryStream())
{
&nbsp; &nbsp; formatter.Serialize(s, <em>myObject</em>);
&nbsp; &nbsp; bResult = s.ToArray();
&nbsp; &nbsp; s.Close();
}
string s = Convert.ToBase64String(bResult);</pre></div></div>

<p>Snippit: Deserialize</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre><em>ObjectToSerialize myObject</em> = null;
byte[] b = Convert.FromBase64String(str);
System.Runtime.Serialization.IFormatter formatter =
&nbsp; &nbsp; new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (System.IO.MemoryStream ms = System.IO.new MemoryStream(b))
{
&nbsp; &nbsp; <em>myObject</em> = (<em>ObjectToSerialize</em>)formatter.Deserialize(ms);
&nbsp; &nbsp; ms.Close();
}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.uhleeka.com/blog/2010/01/c-serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

