<?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>Naresh.Jois &#187; .net Programming</title>
	<atom:link href="http://www.nareshjois.com/category/blog/net-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nareshjois.com</link>
	<description>Home of a professional developer &#38; a aspiring photographer</description>
	<lastBuildDate>Fri, 03 Feb 2012 16:57:10 +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>Find Control of a Type in WPF</title>
		<link>http://www.nareshjois.com/2012/01/find-control-of-a-type-in-wpf/</link>
		<comments>http://www.nareshjois.com/2012/01/find-control-of-a-type-in-wpf/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 13:37:40 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Find Control]]></category>
		<category><![CDATA[VisualTreeHelper]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=973</guid>
		<description><![CDATA[I had previously written a piece of Code to retrieve a control of a single type in ASP.net, now working on WPF I had to do basically the same thing, and VisualTreeHelper came to the rescue. In this process I discovered that if the content of the user control/window is a scroll panel you have [...]]]></description>
			<content:encoded><![CDATA[<p>I had previously written a piece of Code to retrieve a control of a single type in ASP.net, now working on WPF I had to do basically the same thing, and VisualTreeHelper came to the rescue.</p>
<p>In this process I discovered that if the content of the user control/window is a scroll panel you have to reference the scroll panel. so without further blabber , here is the code. (Please Note that this also works with controls inside a groupbox)</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">   <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> VisualEnumerable
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets the Visual Tree filtered by Type for a DependencyObject with that DependencyObject as the root.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>t<span style="color: #008000;">&gt;</span> GetVisualOfType<span style="color: #008000;">&lt;/</span>t<span style="color: #008000;">&gt;&lt;</span>t<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> DependencyObject element<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var temp <span style="color: #008000;">=</span> GetVisualTree<span style="color: #008000;">&#40;</span>element<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> temp<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>t <span style="color: #008000;">=&gt;</span> t<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cast</span><span style="color: #008000;">&lt;/</span>t<span style="color: #008000;">&gt;&lt;</span>t<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets the Visual Tree for a DependencyObject with that DependencyObject as the root.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>dependencyobject<span style="color: #008000;">&gt;</span> GetVisualTree<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> DependencyObject element<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> childrenCount <span style="color: #008000;">=</span> VisualTreeHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChildrenCount</span><span style="color: #008000;">&#40;</span>element<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> childrenCount<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                var visualChild <span style="color: #008000;">=</span> VisualTreeHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChild</span><span style="color: #008000;">&#40;</span>element, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>visualChild <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> visualChild<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>visualChild <span style="color: #008000;">is</span> GroupBox<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    var gb <span style="color: #008000;">=</span> visualChild <span style="color: #0600FF; font-weight: bold;">as</span> GroupBox<span style="color: #008000;">;</span>
                    <span style="color: #6666cc; font-weight: bold;">object</span> gpChild <span style="color: #008000;">=</span> gb<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> visualChild<span style="color: #008000;">;</span>
                    visualChild <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>DependencyObject<span style="color: #008000;">&#41;</span>gpChild<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var visualChildren <span style="color: #0600FF; font-weight: bold;">in</span> GetVisualTree<span style="color: #008000;">&#40;</span>visualChild<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> visualChildren<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>To Use this you can simply do</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">var textboxes <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MainPanel</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetVisualOfType</span><span style="color: #008000;">&lt;</span>textbox<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&lt;/</span>textbox<span style="color: #008000;">&gt;</span></pre></div></div>

<p></dependencyobject></t></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2012/01/find-control-of-a-type-in-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recover Jobs from a crashed SQL Server</title>
		<link>http://www.nareshjois.com/2011/10/recover-jobs-from-a-crashed-sql-server/</link>
		<comments>http://www.nareshjois.com/2011/10/recover-jobs-from-a-crashed-sql-server/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 10:28:00 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Crashed]]></category>
		<category><![CDATA[Jobs]]></category>
		<category><![CDATA[Recover]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/2011/10/recover-jobs-from-a-crashed-sql-server/</guid>
		<description><![CDATA[I recently came across the scenario where a SQL server had crashed (with Windows) but the file system was intact, so we started restore of databases which was straight forward as easy as attaching to the new instance on different server. But we also had lot of jobs scheduled on the old server, and wanted [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across the scenario where a SQL server had crashed (with Windows) but the file system was intact, so we started restore of databases which was straight forward as easy as attaching to the new instance on different server. But we also had lot of jobs scheduled on the old server, and wanted to recover them as well, so after a doing a bit of search figured out that the jobs are saved in &#8220;msdb&#8221; system database.
<div>So to restore</div>
<div>
<ol>
<li><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="line-height: 13px;">Create a dummy instance of SQL Server.</span></font></li>
<li><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="line-height: 13px;">Stop the instance.</span></font></li>
<li><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="line-height: 13px;">Replace the .mdf &amp; .ldf files from the crashed server of the msdb database.</span></font></li>
<li><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="line-height: 13px;">Start the Server Instance as well as agent.</span></font></li>
<li><font class="Apple-style-span" size="2"><span class="Apple-style-span" style="line-height: 13px;">voila, you have your jobs, now script those jobs and execute on new server</span></font></li>
</ol>
</div>
<p>and you are good to go..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/10/recover-jobs-from-a-crashed-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nifty Little script to check identity columns</title>
		<link>http://www.nareshjois.com/2011/10/nifty-little-script-to-check-identity-columns/</link>
		<comments>http://www.nareshjois.com/2011/10/nifty-little-script-to-check-identity-columns/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 10:28:00 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[identity]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/2011/10/nifty-little-script-to-check-identity-columns/</guid>
		<description><![CDATA[I had to recently check for identity specification on all the tables in a database and this nifty little script helped me in doing this. Thanks Akshay for writing this for me. CREATE PROC dbo.CheckIdentities AS BEGIN SET NOCOUNT ON &#160; SELECT QUOTENAME&#40;SCHEMA_NAME&#40;t.schema_id&#41;&#41; + '.' + QUOTENAME&#40;t.name&#41; AS TableName, c.name AS ColumnName, CASE c.system_type_id WHEN [...]]]></description>
			<content:encoded><![CDATA[<p>I had to recently check for identity specification on all the tables in a database and this nifty little script helped me in doing this.
<div>Thanks Akshay for writing this for me.</div>
<div></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:consolas, monaco;"><span style="color: #993333; font-weight: bold;">CREATE</span> PROC dbo<span style="color: #66cc66;">.</span>CheckIdentities  
<span style="color: #993333; font-weight: bold;">AS</span>  
<span style="color: #993333; font-weight: bold;">BEGIN</span>  
 <span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>  
&nbsp;
 <span style="color: #993333; font-weight: bold;">SELECT</span> QUOTENAME<span style="color: #66cc66;">&#40;</span>SCHEMA_NAME<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">.</span>schema_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span>  QUOTENAME<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TableName<span style="color: #66cc66;">,</span>   
  c<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> ColumnName<span style="color: #66cc66;">,</span>  
  <span style="color: #993333; font-weight: bold;">CASE</span> c<span style="color: #66cc66;">.</span>system_type_id  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">127</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'bigint'</span>  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">56</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'int'</span>  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">52</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'smallint'</span>  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">48</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'tinyint'</span>  
  <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'DataType'</span><span style="color: #66cc66;">,</span>  
  IDENT_CURRENT<span style="color: #66cc66;">&#40;</span>SCHEMA_NAME<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">.</span>schema_id<span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span> t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> CurrentIdentityValue<span style="color: #66cc66;">,</span>  
  <span style="color: #993333; font-weight: bold;">CASE</span> c<span style="color: #66cc66;">.</span>system_type_id  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">127</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #66cc66;">&#40;</span>IDENT_CURRENT<span style="color: #66cc66;">&#40;</span>SCHEMA_NAME<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">.</span>schema_id<span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span> t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">9223372036854775807</span>  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">56</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #66cc66;">&#40;</span>IDENT_CURRENT<span style="color: #66cc66;">&#40;</span>SCHEMA_NAME<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">.</span>schema_id<span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span> t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2147483647</span>  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">52</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #66cc66;">&#40;</span>IDENT_CURRENT<span style="color: #66cc66;">&#40;</span>SCHEMA_NAME<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">.</span>schema_id<span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span> t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">32767</span>  
   <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">48</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #66cc66;">&#40;</span>IDENT_CURRENT<span style="color: #66cc66;">&#40;</span>SCHEMA_NAME<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">.</span>schema_id<span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span> t<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">255</span>  
  <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'PercentageUsed'</span>   
 <span style="color: #993333; font-weight: bold;">FROM</span> sys<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">COLUMNS</span> <span style="color: #993333; font-weight: bold;">AS</span> c   
  <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span>  
  sys<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLES</span> <span style="color: #993333; font-weight: bold;">AS</span> t   
  <span style="color: #993333; font-weight: bold;">ON</span> t<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>object_id<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>object_id<span style="color: #66cc66;">&#93;</span>  
 <span style="color: #993333; font-weight: bold;">WHERE</span> c<span style="color: #66cc66;">.</span>is_identity <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>  
 <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> PercentageUsed <span style="color: #993333; font-weight: bold;">DESC</span>  
<span style="color: #993333; font-weight: bold;">END</span></pre></div></div>

</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/10/nifty-little-script-to-check-identity-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asp.net ReportViewer : Access Remote Server Report with Credentials</title>
		<link>http://www.nareshjois.com/2011/09/asp-net-reportviewer-access-remote-server-report-with-credentials/</link>
		<comments>http://www.nareshjois.com/2011/09/asp-net-reportviewer-access-remote-server-report-with-credentials/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 07:38:30 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[credentials]]></category>
		<category><![CDATA[networkcredentials]]></category>
		<category><![CDATA[report server]]></category>
		<category><![CDATA[ssrs]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=913</guid>
		<description><![CDATA[If you want to work with remote SSRS report while debugging your asp.net application you would want to authenticate with the remote server, you cannot use asp.net impersonation as this would actually make the entire application run under impersonation so to solve this we can use impersonation for the report viewer only to do this [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to work with remote SSRS report while debugging your asp.net application you would want to authenticate with the remote server, you cannot use asp.net impersonation as this would actually make the entire application run under impersonation so to solve this we can use impersonation for the report viewer only to do this :</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"><span style="color: #008080;">#if (DEBUG)</span>
<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ReportViewer1</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServerReport</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ReportServerCredentials</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ReportServerCredentials<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;username&quot;</span>, <span style="color: #666666;">&quot;password&quot;</span>,<span style="color: #666666;">&quot;domain&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endif</span></pre></div></div>

<p>and a <b>ReportServerCredentials</b> class</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ReportServerCredentials <span style="color: #008000;">:</span> IReportServerCredentials
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> _userName<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> _password<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> _domain<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> ReportServerCredentials<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> userName, <span style="color: #6666cc; font-weight: bold;">string</span> password, <span style="color: #6666cc; font-weight: bold;">string</span> domain<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            _userName <span style="color: #008000;">=</span> userName<span style="color: #008000;">;</span>
            _password <span style="color: #008000;">=</span> password<span style="color: #008000;">;</span>
            _domain <span style="color: #008000;">=</span> domain<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Security</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Principal</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">WindowsIdentity</span> ImpersonationUser
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ICredentials</span> NetworkCredentials
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Net</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">NetworkCredential</span><span style="color: #008000;">&#40;</span>_userName, _password, _domain<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #6666cc; font-weight: bold;">bool</span> IReportServerCredentials<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFormsCredentials</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">out</span> Cookie authCookie, <span style="color: #0600FF; font-weight: bold;">out</span> <span style="color: #6666cc; font-weight: bold;">string</span> userName, <span style="color: #0600FF; font-weight: bold;">out</span> <span style="color: #6666cc; font-weight: bold;">string</span> password, <span style="color: #0600FF; font-weight: bold;">out</span> <span style="color: #6666cc; font-weight: bold;">string</span> authority<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            authCookie <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
            userName <span style="color: #008000;">=</span> _userName<span style="color: #008000;">;</span>
            password <span style="color: #008000;">=</span> _password
            authority <span style="color: #008000;">=</span> _domain<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/09/asp-net-reportviewer-access-remote-server-report-with-credentials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reset your SQL Server login</title>
		<link>http://www.nareshjois.com/2011/08/reset-your-sql-server-login/</link>
		<comments>http://www.nareshjois.com/2011/08/reset-your-sql-server-login/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 16:46:50 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[Reset]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=897</guid>
		<description><![CDATA[Recently I faced a situation where the SQL Server was setup but no one knew the login, and the SQL server was not configured in Mixed Mode Authentication, so how do you recover from this situation other than re installing the instance, Stop the running instance and then open up command prompt in Binn directory [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I faced a situation where the SQL Server was setup but no one knew the login, and the SQL server was not configured in Mixed Mode Authentication, so how do you recover from this situation other than re installing the instance,<br />
Stop the running instance and then open up command prompt in Binn directory on the instance which would be something like</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:consolas, monaco;">c:\Program Files\Microsoft SQL Server\MSSQL...\Binn</pre></div></div>

<p>Run the following command</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:consolas, monaco;">sqlservr.exe <span style="color: #660033;">-m</span><span style="color: #ff0000;">&quot;SQLCMD&quot;</span></pre></div></div>

<p>This would start the instance in single user mode, now open up another command prompt in the same directory<br />
and then run &#8220;SQLCMD&#8221;<br />
and execute the following statements based on requirement</p>
<p>If you want to add a windows user use</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:consolas, monaco;"><span style="color: #993333; font-weight: bold;">CREATE</span> login <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">DOMAIN</span>\USERNAME<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">FROM</span> windows;
<span style="color: #993333; font-weight: bold;">EXEC</span> sys<span style="color: #66cc66;">.</span>sp_addsrvrolemember @loginame <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">'DOMAIN<span style="color: #000099; font-weight: bold;">\U</span>SERNAME'</span><span style="color: #66cc66;">,</span> @rolename <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">'sysadmin'</span>;
<span style="color: #993333; font-weight: bold;">GO</span>;</pre></div></div>

<p>To add a SQL Server Login use (remember this works only if mixed mode authentication is enabled)</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:consolas, monaco;"><span style="color: #993333; font-weight: bold;">CREATE</span> LOGIN <span style="color: #66cc66;">&#91;</span>testAdmin<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">WITH</span> PASSWORD<span style="color: #66cc66;">=</span>N<span style="color: #ff0000;">'test@1234'</span><span style="color: #66cc66;">,</span> DEFAULT_DATABASE<span style="color: #66cc66;">=</span><span style="color: #66cc66;">&#91;</span>master<span style="color: #66cc66;">&#93;</span>;
<span style="color: #993333; font-weight: bold;">EXEC</span> sys<span style="color: #66cc66;">.</span>sp_addsrvrolemember @loginame <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">'testAdmin'</span><span style="color: #66cc66;">,</span> @rolename <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">'sysadmin'</span>;
<span style="color: #993333; font-weight: bold;">GO</span>;</pre></div></div>

<p>now exit SQLCMD and also do CTRL+C on first window to stop instance and restart the instance in regular mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/08/reset-your-sql-server-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zune Window in WPF</title>
		<link>http://www.nareshjois.com/2011/07/zune-window-in-wpf/</link>
		<comments>http://www.nareshjois.com/2011/07/zune-window-in-wpf/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 10:30:53 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[zune]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=892</guid>
		<description><![CDATA[I have become a huge fan of Metro UI design and i really like the Zune interface and the starting point would be the custom chrome so i searched a bit and found this neat little thing , thought I would share /// &#60;summary&#62; /// Borderless Window Behavior /// &#60;/summary&#62; public class BorderlessWindowBehavior : Behavior&#60;window&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I have become a huge fan of Metro UI design and i really like the Zune interface and the starting point would be the custom chrome so i searched a bit and found this neat little thing , thought I would share</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"> <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Borderless Window Behavior</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BorderlessWindowBehavior <span style="color: #008000;">:</span> Behavior<span style="color: #008000;">&lt;</span>window<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080;">#region Native Methods</span>
&nbsp;
        <span style="color: #008000;">&#91;</span>StructLayout<span style="color: #008000;">&#40;</span>LayoutKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequential</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">struct</span> MARGINS
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> leftWidth<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> rightWidth<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> topHeight<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> bottomHeight<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;dwmapi.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">int</span> DwmExtendFrameIntoClientArea<span style="color: #008000;">&#40;</span>IntPtr hWnd, <span style="color: #0600FF; font-weight: bold;">ref</span> MARGINS pMarInset<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// POINT aka POINTAPI</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008000;">&#91;</span>StructLayout<span style="color: #008000;">&#40;</span>LayoutKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequential</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">struct</span> POINT
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// x coordinate of point.</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> x<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// y coordinate of point.</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> y<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Construct a point of coordinates (x,y).</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> POINT<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> x, <span style="color: #6666cc; font-weight: bold;">int</span> y<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> x<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> y<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008000;">&#91;</span>StructLayout<span style="color: #008000;">&#40;</span>LayoutKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequential</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">struct</span> MINMAXINFO
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> POINT ptReserved<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> POINT ptMaxSize<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> POINT ptMaxPosition<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> POINT ptMinTrackSize<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> POINT ptMaxTrackSize<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008000;">&#91;</span>StructLayout<span style="color: #008000;">&#40;</span>LayoutKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequential</span>, CharSet <span style="color: #008000;">=</span> CharSet<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Auto</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MONITORINFO
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> cbSize <span style="color: #008000;">=</span> Marshal<span style="color: #008000;">.</span><span style="color: #008000;">SizeOf</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>MONITORINFO<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">public</span> RECT rcMonitor <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RECT<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">public</span> RECT rcWork <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RECT<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> dwFlags <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt; Win32 &lt;/summary&gt;</span>
        <span style="color: #008000;">&#91;</span>StructLayout<span style="color: #008000;">&#40;</span>LayoutKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Sequential</span>, Pack <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">struct</span> RECT
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> left<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> top<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> right<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> bottom<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> RECT Empty <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RECT<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Width
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Abs needed for BIDI OS</span>
                get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>right <span style="color: #008000;">-</span> left<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>  
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Height
            <span style="color: #008000;">&#123;</span>
                get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> bottom <span style="color: #008000;">-</span> top<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;left&quot;&gt;The left.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;top&quot;&gt;The top.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;right&quot;&gt;The right.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;bottom&quot;&gt;The bottom.&lt;/param&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> RECT<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> left, <span style="color: #6666cc; font-weight: bold;">int</span> top, <span style="color: #6666cc; font-weight: bold;">int</span> right, <span style="color: #6666cc; font-weight: bold;">int</span> bottom<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">left</span> <span style="color: #008000;">=</span> left<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">top</span> <span style="color: #008000;">=</span> top<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">right</span> <span style="color: #008000;">=</span> right<span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">bottom</span> <span style="color: #008000;">=</span> bottom<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;rcSrc&quot;&gt;The rc SRC.&lt;/param&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> RECT<span style="color: #008000;">&#40;</span>RECT rcSrc<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">left</span> <span style="color: #008000;">=</span> rcSrc<span style="color: #008000;">.</span><span style="color: #0000FF;">left</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">top</span> <span style="color: #008000;">=</span> rcSrc<span style="color: #008000;">.</span><span style="color: #0000FF;">top</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">right</span> <span style="color: #008000;">=</span> rcSrc<span style="color: #008000;">.</span><span style="color: #0000FF;">right</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">bottom</span> <span style="color: #008000;">=</span> rcSrc<span style="color: #008000;">.</span><span style="color: #0000FF;">bottom</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Win32</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;value&gt;</span>
            <span style="color: #008080; font-style: italic;">///   &lt;c&gt;true&lt;/c&gt; if this instance is empty; otherwise, &lt;c&gt;false&lt;/c&gt;.</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/value&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsEmpty
            <span style="color: #008000;">&#123;</span>
                get
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// BUGBUG : On Bidi OS (hebrew arabic) left &gt; right</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> left <span style="color: #008000;">&gt;=</span> right <span style="color: #008000;">||</span> top <span style="color: #008000;">&gt;=</span> bottom<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Return a user friendly representation of this struct</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;</span>
            <span style="color: #008080; font-style: italic;">/// A &lt;see cref=&quot;System.String&quot;/&gt; that represents this instance.</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/returns&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">string</span> ToString<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #008000;">==</span> RECT<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span> 
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;RECT {Empty}&quot;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;RECT {{ left : {0} / top : {1} / right : {2} / bottom : {3} }}&quot;</span>, left, top, right, bottom<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Determine if 2 RECT are equal (deep compare)</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;obj&quot;&gt;The &lt;see cref=&quot;System.Object&quot;/&gt; to compare with this instance.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;</span>
            <span style="color: #008080; font-style: italic;">///   &lt;c&gt;true&lt;/c&gt; if the specified &lt;see cref=&quot;System.Object&quot;/&gt; is equal to this instance; otherwise, &lt;c&gt;false&lt;/c&gt;.</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/returns&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Equals<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> obj<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #008000;">&#40;</span>obj <span style="color: #008000;">is</span> Rect<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #008000;">==</span> <span style="color: #008000;">&#40;</span>RECT<span style="color: #008000;">&#41;</span>obj<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Return the HashCode for this struct (not guaranteed to be unique)</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;</span>
            <span style="color: #008080; font-style: italic;">/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. </span>
            <span style="color: #008080; font-style: italic;">/// &lt;/returns&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">int</span> GetHashCode<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> left<span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> top<span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> right<span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> bottom<span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Determine if 2 RECT are equal (deep compare)</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;rect1&quot;&gt;The rect1.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;rect2&quot;&gt;The rect2.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The result of the operator.</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/returns&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> <span style="color: #0600FF; font-weight: bold;">operator</span> <span style="color: #008000;">==</span><span style="color: #008000;">&#40;</span>RECT rect1, RECT rect2<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>rect1<span style="color: #008000;">.</span><span style="color: #0000FF;">left</span> <span style="color: #008000;">==</span> rect2<span style="color: #008000;">.</span><span style="color: #0000FF;">left</span> <span style="color: #008000;">&amp;&amp;</span> rect1<span style="color: #008000;">.</span><span style="color: #0000FF;">top</span> <span style="color: #008000;">==</span> rect2<span style="color: #008000;">.</span><span style="color: #0000FF;">top</span> <span style="color: #008000;">&amp;&amp;</span> rect1<span style="color: #008000;">.</span><span style="color: #0000FF;">right</span> <span style="color: #008000;">==</span> rect2<span style="color: #008000;">.</span><span style="color: #0000FF;">right</span> <span style="color: #008000;">&amp;&amp;</span> rect1<span style="color: #008000;">.</span><span style="color: #0000FF;">bottom</span> <span style="color: #008000;">==</span> rect2<span style="color: #008000;">.</span><span style="color: #0000FF;">bottom</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// Determine if 2 RECT are different (deep compare)</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;rect1&quot;&gt;The rect1.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;rect2&quot;&gt;The rect2.&lt;/param&gt;</span>
            <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;</span>
            <span style="color: #008080; font-style: italic;">/// The result of the operator.</span>
            <span style="color: #008080; font-style: italic;">/// &lt;/returns&gt;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> <span style="color: #0600FF; font-weight: bold;">operator</span> <span style="color: #008000;">!=</span><span style="color: #008000;">&#40;</span>RECT rect1, RECT rect2<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">!</span><span style="color: #008000;">&#40;</span>rect1 <span style="color: #008000;">==</span> rect2<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets the monitor info.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;hMonitor&quot;&gt;The h monitor.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;lpmi&quot;&gt;The lpmi.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;user32&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> <span style="color: #6666cc; font-weight: bold;">bool</span> GetMonitorInfo<span style="color: #008000;">&#40;</span>IntPtr hMonitor, MONITORINFO lpmi<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Monitors from window.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;handle&quot;&gt;The handle.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;flags&quot;&gt;The flags.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;User32&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> IntPtr MonitorFromWindow<span style="color: #008000;">&#40;</span>IntPtr handle, <span style="color: #6666cc; font-weight: bold;">int</span> flags<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Wms the get min max info.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;hwnd&quot;&gt;The HWND.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;lParam&quot;&gt;The l param.&lt;/param&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> WmGetMinMaxInfo<span style="color: #008000;">&#40;</span><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IntPtr</span> hwnd, <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IntPtr</span> lParam<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            MINMAXINFO mmi <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>MINMAXINFO<span style="color: #008000;">&#41;</span>Marshal<span style="color: #008000;">.</span><span style="color: #0000FF;">PtrToStructure</span><span style="color: #008000;">&#40;</span>lParam, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>MINMAXINFO<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Adjust the maximized size and position to fit the work area of the correct monitor</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> MONITOR_DEFAULTTONEAREST <span style="color: #008000;">=</span> 0x00000002<span style="color: #008000;">;</span>
            <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IntPtr</span> monitor <span style="color: #008000;">=</span> MonitorFromWindow<span style="color: #008000;">&#40;</span>hwnd, MONITOR_DEFAULTTONEAREST<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>monitor <span style="color: #008000;">!=</span> <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IntPtr</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                MONITORINFO monitorInfo <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MONITORINFO<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                GetMonitorInfo<span style="color: #008000;">&#40;</span>monitor, monitorInfo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                RECT rcWorkArea <span style="color: #008000;">=</span> monitorInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">rcWork</span><span style="color: #008000;">;</span>
                RECT rcMonitorArea <span style="color: #008000;">=</span> monitorInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">rcMonitor</span><span style="color: #008000;">;</span>
                mmi<span style="color: #008000;">.</span><span style="color: #0000FF;">ptMaxPosition</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>rcWorkArea<span style="color: #008000;">.</span><span style="color: #0000FF;">left</span> <span style="color: #008000;">-</span> rcMonitorArea<span style="color: #008000;">.</span><span style="color: #0000FF;">left</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                mmi<span style="color: #008000;">.</span><span style="color: #0000FF;">ptMaxPosition</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>rcWorkArea<span style="color: #008000;">.</span><span style="color: #0000FF;">top</span> <span style="color: #008000;">-</span> rcMonitorArea<span style="color: #008000;">.</span><span style="color: #0000FF;">top</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                mmi<span style="color: #008000;">.</span><span style="color: #0000FF;">ptMaxSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">x</span> <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>rcWorkArea<span style="color: #008000;">.</span><span style="color: #0000FF;">right</span> <span style="color: #008000;">-</span> rcWorkArea<span style="color: #008000;">.</span><span style="color: #0000FF;">left</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                mmi<span style="color: #008000;">.</span><span style="color: #0000FF;">ptMaxSize</span><span style="color: #008000;">.</span><span style="color: #0000FF;">y</span> <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Abs</span><span style="color: #008000;">&#40;</span>rcWorkArea<span style="color: #008000;">.</span><span style="color: #0000FF;">bottom</span> <span style="color: #008000;">-</span> rcWorkArea<span style="color: #008000;">.</span><span style="color: #0000FF;">top</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            Marshal<span style="color: #008000;">.</span><span style="color: #0000FF;">StructureToPtr</span><span style="color: #008000;">&#40;</span>mmi, lParam, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Defs the window proc.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;hwnd&quot;&gt;The HWND.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;msg&quot;&gt;The MSG.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;wParam&quot;&gt;The w param.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;lParam&quot;&gt;The l param.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #008000;">&#91;</span>DllImport<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;user32.dll&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">extern</span> IntPtr DefWindowProc<span style="color: #008000;">&#40;</span>IntPtr hwnd, <span style="color: #6666cc; font-weight: bold;">int</span> msg, IntPtr wParam, IntPtr lParam<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> WM_NCCALCSIZE <span style="color: #008000;">=</span> 0x83<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> WM_NCPAINT <span style="color: #008000;">=</span> 0x85<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> WM_NCACTIVATE <span style="color: #008000;">=</span> 0x86<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">int</span> WM_GETMINMAXINFO <span style="color: #008000;">=</span> 0x24<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> HwndSource m_hwndSource<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> IntPtr m_hwnd<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> DependencyProperty ResizeWithGripProperty <span style="color: #008000;">=</span> DependencyProperty<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ResizeWithGrip&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>BorderlessWindowBehavior<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">new</span> PropertyMetadata<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or sets a value indicating whether [resize with grip].</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;value&gt;</span>
        <span style="color: #008080; font-style: italic;">///   &lt;c&gt;true&lt;/c&gt; if [resize with grip]; otherwise, &lt;c&gt;false&lt;/c&gt;.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/value&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> ResizeWithGrip
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&#41;</span>GetValue<span style="color: #008000;">&#40;</span>ResizeWithGripProperty<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetValue<span style="color: #008000;">&#40;</span>ResizeWithGripProperty, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Called after the behavior is attached to an AssociatedObject.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnAttached<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>AssociatedObject<span style="color: #008000;">.</span><span style="color: #0000FF;">IsInitialized</span><span style="color: #008000;">&#41;</span>
                AddHwndHook<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
                AssociatedObject<span style="color: #008000;">.</span><span style="color: #0000FF;">SourceInitialized</span> <span style="color: #008000;">+=</span> AssociatedObject_SourceInitialized<span style="color: #008000;">;</span>
&nbsp;
            AssociatedObject<span style="color: #008000;">.</span><span style="color: #0000FF;">WindowStyle</span> <span style="color: #008000;">=</span> WindowStyle<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
            AssociatedObject<span style="color: #008000;">.</span><span style="color: #0000FF;">ResizeMode</span> <span style="color: #008000;">=</span> ResizeWithGrip <span style="color: #008000;">?</span> ResizeMode<span style="color: #008000;">.</span><span style="color: #0000FF;">CanResizeWithGrip</span> <span style="color: #008000;">:</span> ResizeMode<span style="color: #008000;">.</span><span style="color: #0000FF;">CanResize</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnAttached</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnDetaching<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            RemoveHwndHook<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnDetaching</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Adds the HWND hook.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddHwndHook<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            m_hwndSource <span style="color: #008000;">=</span> HwndSource<span style="color: #008000;">.</span><span style="color: #0000FF;">FromVisual</span><span style="color: #008000;">&#40;</span>AssociatedObject<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> HwndSource<span style="color: #008000;">;</span>
            m_hwndSource<span style="color: #008000;">.</span><span style="color: #0000FF;">AddHook</span><span style="color: #008000;">&#40;</span>HwndHook<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            m_hwnd <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WindowInteropHelper<span style="color: #008000;">&#40;</span>AssociatedObject<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Handle</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Removes the HWND hook.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> RemoveHwndHook<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            AssociatedObject<span style="color: #008000;">.</span><span style="color: #0000FF;">SourceInitialized</span> <span style="color: #008000;">-=</span> AssociatedObject_SourceInitialized<span style="color: #008000;">;</span>
            m_hwndSource<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveHook</span><span style="color: #008000;">&#40;</span>HwndHook<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Handles the SourceInitialized event of the AssociatedObject control.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;sender&quot;&gt;The source of the event.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;e&quot;&gt;The &lt;see cref=&quot;System.EventArgs&quot;/&gt; instance containing the event data.&lt;/param&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AssociatedObject_SourceInitialized<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            AddHwndHook<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// HWNDs the hook.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;hWnd&quot;&gt;The h WND.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;message&quot;&gt;The message.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;wParam&quot;&gt;The w param.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;lParam&quot;&gt;The l param.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;handled&quot;&gt;if set to &lt;c&gt;true&lt;/c&gt; [handled].&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> IntPtr HwndHook<span style="color: #008000;">&#40;</span>IntPtr hWnd, <span style="color: #6666cc; font-weight: bold;">int</span> message, IntPtr wParam, IntPtr lParam, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">bool</span> handled<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            IntPtr returnval <span style="color: #008000;">=</span> IntPtr<span style="color: #008000;">.</span><span style="color: #0000FF;">Zero</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>message<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> WM_NCCALCSIZE<span style="color: #008000;">:</span>
                    <span style="color: #008080; font-style: italic;">/* Hides the border */</span>
                    handled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> WM_NCPAINT<span style="color: #008000;">:</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">OSVersion</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Version</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Major</span> <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">6</span><span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            var m <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MARGINS <span style="color: #008000;">&#123;</span> bottomHeight <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, leftWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, rightWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, topHeight <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
                            DwmExtendFrameIntoClientArea<span style="color: #008000;">&#40;</span>m_hwnd, <span style="color: #0600FF; font-weight: bold;">ref</span> m<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                        handled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> WM_NCACTIVATE<span style="color: #008000;">:</span>
                    <span style="color: #008000;">&#123;</span>
                        <span style="color: #008080; font-style: italic;">/* As per http://msdn.microsoft.com/en-us/library/ms632633(VS.85).aspx , &quot;-1&quot; lParam
                         * &quot;does not repaint the nonclient area to reflect the state change.&quot; */</span>
                        returnval <span style="color: #008000;">=</span> DefWindowProc<span style="color: #008000;">&#40;</span>hWnd, message, wParam, <span style="color: #008000;">new</span> IntPtr<span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        handled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #008000;">&#125;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> WM_GETMINMAXINFO<span style="color: #008000;">:</span>
                    <span style="color: #008080; font-style: italic;">/* From Lester's Blog (thanks @aeoth):  
                     * http://blogs.msdn.com/b/llobo/archive/2006/08/01/maximizing-window-_2800_with-windowstyle_3d00_none_2900_-considering-taskbar.aspx */</span>
                    WmGetMinMaxInfo<span style="color: #008000;">&#40;</span>hWnd, lParam<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    handled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> returnval<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&lt;/</span>window<span style="color: #008000;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/07/zune-window-in-wpf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Reading Metadata of the Buddy Class</title>
		<link>http://www.nareshjois.com/2011/07/reading-metadata-of-the-buddy-class/</link>
		<comments>http://www.nareshjois.com/2011/07/reading-metadata-of-the-buddy-class/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 06:56:31 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=889</guid>
		<description><![CDATA[Most of the time we would be using buddy classes for putting metadata for auto generated classes, for example: Say if this is the autogenerated class public partial class Person &#123; public string FirstName &#123; ..... &#125; public string LastName &#123;..... &#125; public int Age &#123; ..... &#125; &#125; Our buddy class would be public [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the time we would be using buddy classes for putting metadata for auto generated classes, for example:<br />
Say if this is the autogenerated class</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Person
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FirstName <span style="color: #008000;">&#123;</span> <span style="color: #008000;">.....</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> LastName <span style="color: #008000;">&#123;</span><span style="color: #008000;">.....</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Age <span style="color: #008000;">&#123;</span> <span style="color: #008000;">.....</span>  <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Our buddy class would be</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> PersonMetaData
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;First Name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> FirstName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Last Name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> LastName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Age&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Age <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>This is fine but what if we want to read this data back, if we use the Class.GetProperties() we do not get this data back so basically we would have to go through a hoop, but its fairly simple</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">PropertyInfo<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> headerInfo <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Person<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            var attributesofclass <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Person<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> n <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> n <span style="color: #008000;">&lt;</span> headerInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> n<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>   
                var attributesofbase <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataAnnotations</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayAttribute</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>headerInfo<span style="color: #008000;">&#91;</span>n<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataAnnotations</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayAttribute</span><span style="color: #008000;">&#41;</span>,<span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>attributesofbase<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
                    var medatadataofclass <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataAnnotations</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MetadataTypeAttribute</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataAnnotations</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MetadataTypeAttribute</span><span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>medatadataofclass<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        var metadatatypeofclass <span style="color: #008000;">=</span> medatadataofclass<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MetadataClassType</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperty</span><span style="color: #008000;">&#40;</span>headerInfo<span style="color: #008000;">&#91;</span>n<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>metadatatypeofclass <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
                            var metadataofproperty <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataAnnotations</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayAttribute</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>metadatatypeofclass<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataAnnotations</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayAttribute</span><span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                        <span style="color: #008000;">&#125;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/07/reading-metadata-of-the-buddy-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asp.net Dyanamic Data : A leap for RAD</title>
		<link>http://www.nareshjois.com/2011/06/asp-net-dyanamic-data-a-leap-for-rad/</link>
		<comments>http://www.nareshjois.com/2011/06/asp-net-dyanamic-data-a-leap-for-rad/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 06:29:41 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Dynamic Data]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=878</guid>
		<description><![CDATA[I have always basically forms over data for the longest period of time (LOB Apps) and most of the time its the same thing over and over again, Setup Database, create scaffolding forms for all the master tables and then move to the next steps, but wait there should be an easy way to this, [...]]]></description>
			<content:encoded><![CDATA[<p>I have always basically forms over data for the longest period of time (LOB Apps) and most of the time its the same thing over and over again, Setup Database, create scaffolding forms for all the master tables and then move to the next steps, but wait there should be an easy way to this, In the MVC framework you can generate pages based on the model, but there are still a few things that you should wire up manually, enter dynamic data template and this feels like a magical unicorn at the beginning and once you dig deep into into it, its just beautiful, and will save a lot of steps for you.<br />
So lets begin</p>
<div id="attachment_879" class="wp-caption alignnone" style="width: 310px"><a href="http://www.nareshjois.com/wp-content/uploads/2011/06/newddproject.png" rel="lightbox[878]"><img class="size-medium wp-image-879" title="New Dynamic Data WebApplication" src="http://www.nareshjois.com/wp-content/uploads/2011/06/newddproject-300x182.png" alt="New Dynamic Data WebApplication" width="300" height="182" /></a><p class="wp-caption-text">New Dynamic Data WebApplication</p></div>
<p>You have 2 options a Linq2SQL based Application or Entity Framework based application and its just a matter of your preference, Then just create a data Context, This is what i did just to go through and this is not a perfect data model but you can get the point, just create your data context you are almost good to go</p>
<div id="attachment_880" class="wp-caption alignnone" style="width: 522px"><a href="http://www.nareshjois.com/wp-content/uploads/2011/06/ddmodel.png" rel="lightbox[878]"><img class="size-full wp-image-880" title="Dynamic Data : A Test Model" src="http://www.nareshjois.com/wp-content/uploads/2011/06/ddmodel.png" alt="Dynamic Data : A Test Model" width="512" height="258" /></a><p class="wp-caption-text">Dynamic Data : A Test Model</p></div>
<p>then you ll have to uncomment a single line in global.asax</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">DefaultModel<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterContext</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>DataModel<span style="color: #008000;">&#41;</span>, <span style="color: #008000;">new</span> ContextConfiguration<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> ScaffoldAllTables <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Here the default property for ScaffoldAllTables is false, change it to true if you want scaffolding on all tables, (for now)<br />
and you are done<br />
And this is what you get , Projects and Tasks along with filter and foreign key correctly linked</p>
<div id="attachment_882" class="wp-caption alignnone" style="width: 487px"><a href="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep1.png" rel="lightbox[878]"><img class="size-full wp-image-882" title="Tables Listing" src="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep1.png" alt="" width="477" height="403" /></a><p class="wp-caption-text">Tables Listing</p></div>
<div id="attachment_883" class="wp-caption alignnone" style="width: 500px"><a href="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep2.png" rel="lightbox[878]"><img class="size-full wp-image-883" title="Projects Listing" src="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep2.png" alt="" width="490" height="465" /></a><p class="wp-caption-text">Projects Listing</p></div>
<div id="attachment_884" class="wp-caption alignnone" style="width: 500px"><a href="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep3.png" rel="lightbox[878]"><img class="size-full wp-image-884" title="Task Listing" src="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep3.png" alt="" width="490" height="465" /></a><p class="wp-caption-text">Task Listing</p></div>
<div id="attachment_885" class="wp-caption alignnone" style="width: 580px"><a href="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep4.png" rel="lightbox[878]"><img class="size-full wp-image-885" title="Task Insertion" src="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep4.png" alt="" width="570" height="541" /></a><p class="wp-caption-text">Task Insertion</p></div>
<p>Now lets customize this a little bit, we would never want all the scaffold all tables and also we would need some validation and hearer names to be changed a bit.<br />
To Scaffold specific tables we will have to mark the tables with [ScaffoldTable(true)] property, and as the Datacontext generated classes are partials we can extend the classes in a seperate file also to provide metadata we will use data annotations and mark all the necessary fields with the required information</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"><span style="color: #0600FF; font-weight: bold;">namespace</span> TestApplication
<span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#91;</span>ScaffoldTable<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>MetadataType<span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Attributes<span style="color: #008000;">.</span><span style="color: #0000FF;">Project</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Project
    <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008000;">&#91;</span>ScaffoldTable<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #008000;">&#91;</span>MetadataType<span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Attributes<span style="color: #008000;">.</span><span style="color: #0000FF;">Task</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Task
    <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">namespace</span> Attributes
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Project
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
            <span style="color: #008000;">&#91;</span>StringLength<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">50</span>, MinimumLength <span style="color: #008000;">=</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Project Name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> ProjectName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Task
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
            <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Project&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> Project Project <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
            <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Employee Code&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, GroupName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Employee&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> EmployeeCode <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
            <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Track Date&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>, GroupName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Date &amp; Time&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> DateTime TrackDate <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
            <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Hours&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>, GroupName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Date &amp; Time&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">decimal</span> TaskHours <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#93;</span>
            <span style="color: #008000;">&#91;</span>Display<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Task Descriprion&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>, GroupName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Information&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
            <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> TaskDescriprion <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The modified task screen would look like</p>
<div id="attachment_886" class="wp-caption alignnone" style="width: 580px"><a href="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep5.png" rel="lightbox[878]"><img src="http://www.nareshjois.com/wp-content/uploads/2011/06/ddstep5.png" alt="" title="Task Entry Screen Modified" width="570" height="541" class="size-full wp-image-886" /></a><p class="wp-caption-text">Task Entry Screen Modified</p></div>
<p>And this is just the beginning we can do a lot more stuff as all the controls can be customized,  I will post about grouping and also customizing display and edit controls in a subsequent blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/06/asp-net-dyanamic-data-a-leap-for-rad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Play with Clay</title>
		<link>http://www.nareshjois.com/2011/06/play-with-clay/</link>
		<comments>http://www.nareshjois.com/2011/06/play-with-clay/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 08:13:10 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[clay]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[expando]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=868</guid>
		<description><![CDATA[I have been a big fan of ExpandoObject ever since it was introduced with .net 4.0, and I have been using the Expando Object object ever since, but I always felt that it was not enough, ExpandoObject was fun and all but it was just not enough, and me being really lazy remember coying and [...]]]></description>
			<content:encoded><![CDATA[<p>I have been a big fan of ExpandoObject ever since it was introduced with .net 4.0, and I have been using the Expando Object object ever since, but I always felt that it was not enough, ExpandoObject was fun and all but it was just not enough, and me being really lazy remember coying and pasting code just to loop through properties of a class using reflection and all that headache.</p>
<p>Enter Clay : The moment I have laid my eyes on this beautiful piece of code, I have become a huge fan, and it has all the things the expando should have been.</p>
<p>So How do you begin , Its really simple and also follows unique naming convention you begin with a clay object with New (emphasis on uppercase &#8216;N&#8217;)</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">dynamic <span style="color: #008000;">New</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ClayFactory<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var cUser <span style="color: #008000;">=</span> <span style="color: #008000;">New</span><span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>and thats it,<br />
In Clay Indexer Syntax and Property Accessors are the same so</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">cUser<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> cUser<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Name&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></pre></div></div>

<p>you can pass anonymous objects and also accepts named arguments, you can also use jQuery style chain able setters or put use them as an array</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">var cUser <span style="color: #008000;">=</span> <span style="color: #008000;">New</span><span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #008000;">&#123;</span> Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Naresh&quot;</span>, Mail <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;something@mail.com&quot;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var cUser <span style="color: #008000;">=</span> <span style="color: #008000;">New</span><span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">&#40;</span> Name <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;Naresh&quot;</span>, Mail <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;something@mail.com&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var cUser <span style="color: #008000;">=</span> <span style="color: #008000;">New</span><span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Naresh&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Mail</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;something@mail.com&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
var Users <span style="color: #008000;">=</span> <span style="color: #008000;">New</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Array</span><span style="color: #008000;">&#40;</span>
           <span style="color: #008000;">New</span><span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Naresh&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Mail</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;something@mail.com&quot;</span><span style="color: #008000;">&#41;</span>,
           <span style="color: #008000;">New</span><span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Rakesh&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Mail</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;something@mail.com&quot;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>So What are you waiting for get started at<br />
<a href="http://clay.codeplex.com/">clay.codeplex.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2011/06/play-with-clay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight RIA: Validate Entity Server Side</title>
		<link>http://www.nareshjois.com/2010/11/validate-entity-server-side/</link>
		<comments>http://www.nareshjois.com/2010/11/validate-entity-server-side/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 12:00:36 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=842</guid>
		<description><![CDATA[If you are working with Validating a Entity , Simple Meta Data Validation is not always enough , you might have to do a server side validation, and it is really simple Along with regular metadata add a Custom Validation Attribute which has type of class where your validation logic resides and String name of [...]]]></description>
			<content:encoded><![CDATA[<p>If you are working with Validating a Entity , Simple Meta Data Validation is not always enough , you might have to do a server side validation, and it is really simple<br />
Along with regular metadata add a Custom Validation Attribute which has type of class where your validation logic resides and String name of the Validation Function</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"><span style="color: #008000;">&#91;</span>Required<span style="color: #008000;">&#40;</span>ErrorMessage<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Client Name is Required&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #008000;">&#91;</span>StringLength<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">256</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #008000;">&#91;</span>DisplayName<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Client Name&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #008000;">&#91;</span>CustomValidation<span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>ClientValidations<span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;ValidateClientName&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> ClientName <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span></pre></div></div>

<p>and a sample function for validation would be</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> ValidationResult ValidateClientName<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> ClientName, ValidationContext context<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Models<span style="color: #008000;">.</span><span style="color: #0000FF;">DB</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Client</span> client <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>Models<span style="color: #008000;">.</span><span style="color: #0000FF;">DB</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Client</span><span style="color: #008000;">&#41;</span>context<span style="color: #008000;">.</span><span style="color: #0000FF;">ObjectInstance</span><span style="color: #008000;">;</span>
            Web<span style="color: #008000;">.</span><span style="color: #0000FF;">Models</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DB</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PortalDataContext</span> pc <span style="color: #008000;">=</span><span style="color: #008000;">new</span> Models<span style="color: #008000;">.</span><span style="color: #0000FF;">DB</span><span style="color: #008000;">.</span><span style="color: #0000FF;">PortalDataContext</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            var existing <span style="color: #008000;">=</span> pc<span style="color: #008000;">.</span><span style="color: #0000FF;">Clients</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">ClientName</span> <span style="color: #008000;">==</span> ClientName <span style="color: #008000;">&amp;&amp;</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">!=</span> client<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">&amp;&amp;</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">Status</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>existing<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> ValidationResult<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Invalid Client Name as the Client Name already Exists&quot;</span>, <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #666666;">&quot;ClientName&quot;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> ValidationResult<span style="color: #008000;">.</span><span style="color: #0000FF;">Success</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2010/11/validate-entity-server-side/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

