<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1970206442337038620</id><updated>2024-09-11T23:19:23.800+05:30</updated><title type='text'>Dhanushka&#39;s Web Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>29</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-5554697256705463009</id><published>2012-01-12T00:04:00.003+05:30</published><updated>2012-01-12T00:09:15.453+05:30</updated><title type='text'>Only encode URL special characters in a string</title><content type='html'>&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;When it comes to encoding special characters with reference
to URLs, we can easily make use of the functions that have been defined inside
System.Web.dll assembly.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Although this is the most straight forward hassle free way
to encode a string to make it compatible in a HTTP context, in some scenarios
we don’t get that privilege automatically (e.g. non web applications).&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;I ran into such scenario when I was developing a SQL Server
user defined function from VS 2010.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The special problem in that occasion was that when you add an assembly reference in a SQL
CLR project the reference is fetched from the GAC in data base server. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Microsoft have added a set of assemblies which they have
identified as safe assemblies to be referenced by a T-SQL function to the
GAC giving us the ability to use the&amp;nbsp;functionality&amp;nbsp;defined in those classes.
But unfortunately System.Web.dll is not one of them.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;So what will be the work around, an another function we can use
for URL encoding can be found inside System.Uri name space, which fortunately resides
inside System.dll.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;OK, so how to use it to only encode URL special characters!!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Simple just use the power of “Regular Expressions”.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Here is the function I wrote.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&amp;nbsp;&lt;/span&gt;EncodeUrl(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;nbsp;toEncode)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;nbsp;pattern =&amp;nbsp;&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;[$&amp;amp;+,/:;=?@]&quot;&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;&amp;nbsp;match =&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Regex&lt;/span&gt;.Match(toEncode, pattern);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt;(match.Success)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; toEncode = toEncode.Replace(match.Value,&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Uri&lt;/span&gt;.EscapeDataString(match.Value));&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; match =&amp;nbsp;&lt;span style=&quot;color: #2b91af;&quot;&gt;Regex&lt;/span&gt;.Match(toEncode, pattern);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&amp;nbsp;toEncode;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The
function checks the passed string repeatedly until all &amp;nbsp;special characters
are replaced with their respective encoded values.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The combination of Regex.Match and string Replace functions make sure that only the characters that are defined in the regular expression pattern are replaced.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Calibri, sans-serif; font-size: 11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/5554697256705463009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2012/01/only-encode-url-special-characters-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/5554697256705463009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/5554697256705463009'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2012/01/only-encode-url-special-characters-in.html' title='Only encode URL special characters in a string'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-7645783136024066586</id><published>2011-12-06T13:05:00.001+05:30</published><updated>2011-12-06T13:21:26.608+05:30</updated><title type='text'>Tackling Invariance using Covariance and Contra variance in C#</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Invariance is a concept that can be seen in almost all the programming
languages that have a type system. And before we delve in to more language
specific constructs, let’s see what all this big words mean when it comes to a
language.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Covariance &lt;/b&gt;is the
ability to convert data from wider to narrow data types. (E.g. long to int).&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Contra variance &lt;/b&gt;is
the ability to convert data from narrow to wider data types. (E.g. int to
float).&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;Invariance &lt;/b&gt;is the
inability to do conversion between data types.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
In other words if we read closely in between the lines you’ll
see that &lt;b&gt;covariance preserves assignment
compatibility while contra variance reverses it, and when both covariance and
contra variance work together in tandem they make sure that invariance is avoided
when needed&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Ok, with that theory part covered let’s look at an example,
where which can expose the invariant behavior of C#&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
And the example I’ll be using will be a scenario where we
will implement a generic interface for an imaginary inventory. &lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
Let’s have a look at the code first&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPDfnMpP9PuMrxcl4S2lSAPxMOOTtLUrXqMlxl7qdl9q9MxBNugZsFgMoNzLX65OXDegboA9-XHOujUKU649z_ApCb1GivCLzZdpgffuhvvt8prqy5mYqO1K9tZOFr8lNeYcxLhihyphenhyphen/s1600/invariant.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPDfnMpP9PuMrxcl4S2lSAPxMOOTtLUrXqMlxl7qdl9q9MxBNugZsFgMoNzLX65OXDegboA9-XHOujUKU649z_ApCb1GivCLzZdpgffuhvvt8prqy5mYqO1K9tZOFr8lNeYcxLhihyphenhyphen/s1600/invariant.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
The &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;IStorage&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;t&gt;
&lt;/t&gt;&lt;/span&gt;interface defines two generic methods that facilitate storing and retrieving
items from a generic List, and as you can see since there are no restrictions
applied for type “T” in the implementing class &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;BasicStorage&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;t&gt;&lt;/t&gt;&lt;/span&gt; or in the interface, any kind of
data can be stored in our List repository. Let’s write some code to use this
inventory of ours.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgetK23FPssp29UyyQem014EJGxM_KF_RHDbcq9NumyUvF35mFmRevo07Mjhd_5EWsLImUsb9XLW6mIxVi587oGaoj_-FDHO_S-iEGndDWir6vP5VxOpc5HZtFiBGcRn4yWQHD0URL1/s1600/invarianceUse.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgetK23FPssp29UyyQem014EJGxM_KF_RHDbcq9NumyUvF35mFmRevo07Mjhd_5EWsLImUsb9XLW6mIxVi587oGaoj_-FDHO_S-iEGndDWir6vP5VxOpc5HZtFiBGcRn4yWQHD0URL1/s1600/invarianceUse.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
In the above code I’m using the generic interface as
the base type to access the implemented functionality because the class has
implemented the methods explicitly in its code.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
And when the above code is written all will work fine
just the way we planned.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Ok, now what will happen if we try to store data of
type &lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;object &lt;/span&gt;in
our repository, to do that we will have to convert our &lt;b&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;inventory01&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;variable to an instance of
type &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;IStorage&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
And since all strings are objects and object is the
base type for all types we should be able to do just that in our code. So let’s
write some code to do that.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ9yZWsJLH3M-UXa_R4dJhFnh4xogGF7zLFBNWtdNi6ps1o9p-6cQOaOWfiFXJncvlJJpGioVVOQbGmgERUyVI1VhPjXQZ9NrxrHpZ3ja_4MIR6h7BB8dlK3POX1jMwI6nrXJH9Xc7/s1600/invariance+error.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZ9yZWsJLH3M-UXa_R4dJhFnh4xogGF7zLFBNWtdNi6ps1o9p-6cQOaOWfiFXJncvlJJpGioVVOQbGmgERUyVI1VhPjXQZ9NrxrHpZ3ja_4MIR6h7BB8dlK3POX1jMwI6nrXJH9Xc7/s1600/invariance+error.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Hmm…&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Although it makes sense to convert a string to an
object the .net framework is throwing an error when we try to do that, but why?&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
If you look at it closely you will see that &lt;b&gt;although all strings are objects, the
converse is not true, all objects are not strings.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
If the above restriction was not applied by the
framework you would have been able to does something like this.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1o5e9oXC3bBIhkjFN0hTHw0jtIHeIMz6D3qtM-eVBiG0pEfMN0g51_FkiFiN4NZj4tDCLVEBANkywid7iTyjIzmkHXdBsB7G8mvL0eqyTgwMdd5FJVTeNWke8t3PJWbauiL07D7PA/s1600/objectinvariance.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1o5e9oXC3bBIhkjFN0hTHw0jtIHeIMz6D3qtM-eVBiG0pEfMN0g51_FkiFiN4NZj4tDCLVEBANkywid7iTyjIzmkHXdBsB7G8mvL0eqyTgwMdd5FJVTeNWke8t3PJWbauiL07D7PA/s1600/objectinvariance.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
As you can see this code will try to store an &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;ArrayList &lt;/span&gt;on
a memory location which is structured to store a string, and it will clearly
mess up the type safety of the .net framework.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
This is the invariant behavior of .net. &lt;b&gt;C# adds invariance to the type system to
ensure type safety in our programming constructs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
According to the language specification, In C# &lt;b&gt;Generic Interfaces are Invariant by default
while Generic Classes are always Invariant.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
With that in mind, let’s have a look at the same
example from a deferent perspective.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
This time, let’s use two deferent interfaces to store
and retrieve data.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib7TBh7-1DSgblYvmOvkuq5qzr_7fXD0ygktdpsUU6Rlvh1OqH68inYxVx_8l_cABVDhA2q44QQYf9Y0KLxJUlzDtDYqX7SXPV-bl-UcJjDS07fNa3BLrOvJ3o8Ghm5s1IDOMnz_9S/s1600/variantfull.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib7TBh7-1DSgblYvmOvkuq5qzr_7fXD0ygktdpsUU6Rlvh1OqH68inYxVx_8l_cABVDhA2q44QQYf9Y0KLxJUlzDtDYqX7SXPV-bl-UcJjDS07fNa3BLrOvJ3o8Ghm5s1IDOMnz_9S/s1600/variantfull.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Now &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;IDepostior&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;t&gt;
&lt;/t&gt;&lt;/span&gt;have the storage facility while&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;IRetriever&lt;/span&gt;&lt;t&gt; &lt;/t&gt;&lt;/span&gt;provides
us with reading functionality&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
The code that uses this new structure will look like
this.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_9K2SlKw92B8_kFqPsMf16SSufQ_j4aX7h0967t7vSyW0StsLJjRo0CHBuvFxVp4Kkph2f4VaEy-aJwEhvrLgWSkX-G66OeTIq3tI2hrDf1NqsTxVy6ROgOFUwinvtRo_e3lnLhD8/s1600/varincesolvedfull.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_9K2SlKw92B8_kFqPsMf16SSufQ_j4aX7h0967t7vSyW0StsLJjRo0CHBuvFxVp4Kkph2f4VaEy-aJwEhvrLgWSkX-G66OeTIq3tI2hrDf1NqsTxVy6ROgOFUwinvtRo_e3lnLhD8/s1600/varincesolvedfull.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Here we cast an instance of “&lt;b&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Storage&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; inventory02”&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;to type&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; “&lt;span style=&quot;color: #2b91af;&quot;&gt;IDepostior&lt;/span&gt;&lt;b&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;&lt;/b&gt;
store” &lt;/span&gt;to store data, while we cast the same&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; “&lt;b&gt;inventory02”&lt;/b&gt;
&lt;/span&gt;object to&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; “&lt;b&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;IRetriever&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; retriever”&lt;/b&gt; &lt;/span&gt;to retrieve data.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
With that said, will the following line of code work now?&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;o:p&gt;&amp;nbsp;&amp;nbsp;&lt;/o:p&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 13px;&quot;&gt;Storage&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 13px;&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;&amp;gt; inventory02 = &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 13px;&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 13px;&quot;&gt;Storage&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 13px;&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Consolas; font-size: 13px;&quot;&gt;&amp;gt;();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;IRetriever&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; retreiver = inventory02;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;IRetriever&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;gt; objectRetreivor = inventory02;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
The answer is “NO”.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
In the previous example it made sense. Does it make
the same sense now?&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Here &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;IRetriever &lt;/span&gt;interface only provides you with means to read
data, and it doesn’t expose any method to store data. Because of that, you cannot
store incompatible types in the underlying storage now. So the loop hole that allowed
the previous example to break the type safety is no longer present in this
interface. In other words, now it’s perfectly safe to convert &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;IRetriever&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;
&lt;/span&gt;to&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;IRetriever&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;b&gt;In situations
like this, where the type parameter only acts as a return value of a method in
a generic interface, we can tell to the compiler that some implicit conversions
are legal and type safety does not have to be imposed on a type all the time.&lt;/b&gt;
To do that we can use the “&lt;b&gt;out&lt;/b&gt;”
keyword.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
And the modified &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;IRetriever &lt;/span&gt;interface will look
something like this.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0gNXyRrjTiwt0_ISPitq53_AiuaCHNDsq5WlV0CaqWdZOFW9tU0YmY2gefiFlTMkWKGBkaGZdnF80AMk1-Z_J4eRnU9qN3MZnTbL0Pkn6fd5B8HDsILItr0Jslb6gJvntuh6cXC7s/s1600/IROut.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0gNXyRrjTiwt0_ISPitq53_AiuaCHNDsq5WlV0CaqWdZOFW9tU0YmY2gefiFlTMkWKGBkaGZdnF80AMk1-Z_J4eRnU9qN3MZnTbL0Pkn6fd5B8HDsILItr0Jslb6gJvntuh6cXC7s/s1600/IROut.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Now we have just used &lt;b&gt;Covariance&lt;/b&gt; to preserve assignment compatibility where it makes
sense.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Right! Now let’s have a look at the other interface which
allows us to store data. Will this be ok?&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Storage&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;gt; inventory03 = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;Storage&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;&amp;gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;IDepostior&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; depositor = inventory03; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Let’s think of it like this. All strings are objects,
so if you can perform a specific behavior on a variable of type object, you
should be able to carry out the same thing on a variable of type string.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
In other words, &lt;b&gt;if
“B” derives from “A” and if type “A” exposes a set of members (behaviors,
properties, etc…), type “B” must also expose the same set of members too.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
So anything that can be carried out on &lt;b&gt;A &lt;/b&gt;must also be supported by &lt;b&gt;B.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
So if we consider our &lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;IDepostior &lt;/span&gt;example, if we can store &lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;object&lt;/span&gt;s and do
some exercises on them, we should be able to store &lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;string&lt;/span&gt;s and do the same set of exercise
on them too.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
That sounds correct, but there must be a way for us
to tell to the complier that operations which will be carried out on the
generic typed items will only be operations which are specified on the most
generalized type in the inheritance hierarchy. Or in other words only the
operations supported by &lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;object&lt;/span&gt;s will be carried out on our type.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
We do that using the keyword “&lt;b&gt;in&lt;/b&gt;”.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;b&gt;The “in”
keyword tells the compiler that, you can either pass type “T” as a parameter
type to methods or pass any type that derives from “T”. &amp;nbsp;And you cannot use “T” as a return type of a
method.&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
So the modified interface will look something like
this.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmItzy2kOMe2IVofDR_gTEolFGSzzcuTwn5pfwvhAudmEp5uzINt9S7Lw4gOPmKm5uQEvVWLv1QphlU7THCic93U91JNuVNjshYBnKDtVd4eAdvvKXuT6CpCzCc8L8uW6YBhPxpL_2/s1600/IDout.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmItzy2kOMe2IVofDR_gTEolFGSzzcuTwn5pfwvhAudmEp5uzINt9S7Lw4gOPmKm5uQEvVWLv1QphlU7THCic93U91JNuVNjshYBnKDtVd4eAdvvKXuT6CpCzCc8L8uW6YBhPxpL_2/s1600/IDout.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Now we can reference an object either through a
generic interface based on the object type or through a type that derived from
that object type. And by adding the “&lt;b&gt;in&lt;/b&gt;”
key word, we’ve had made sure that the needed restrictions are there to make our
assignment type safe.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
With that, we have just used &lt;b&gt;Contra variance to reverse Covariance&lt;/b&gt; and made classes in an
inheritance hierarchy reference each other when the reference is type safe.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
The completed interfaces will be…&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTDJBXlM_-2CogW0KNxu7FzzWcIAedwf0juPz5GmUY17S9J_tn1lrVGgUFyws0zEG8GvSqz5nuriV9sS3uwVklAAHF57SFiwI7U0_RQ6Xm6IwRqJuFnfGowqmQpdBiHEe4ye8yt0cI/s1600/fin.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTDJBXlM_-2CogW0KNxu7FzzWcIAedwf0juPz5GmUY17S9J_tn1lrVGgUFyws0zEG8GvSqz5nuriV9sS3uwVklAAHF57SFiwI7U0_RQ6Xm6IwRqJuFnfGowqmQpdBiHEe4ye8yt0cI/s1600/fin.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
If you have any questions, just add a comment and I’ll
answer it as soon as I can.&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
Hope this clears thing up.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/7645783136024066586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2011/12/tackling-invariance-using-covariance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7645783136024066586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7645783136024066586'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2011/12/tackling-invariance-using-covariance.html' title='Tackling Invariance using Covariance and Contra variance in C#'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPDfnMpP9PuMrxcl4S2lSAPxMOOTtLUrXqMlxl7qdl9q9MxBNugZsFgMoNzLX65OXDegboA9-XHOujUKU649z_ApCb1GivCLzZdpgffuhvvt8prqy5mYqO1K9tZOFr8lNeYcxLhihyphenhyphen/s72-c/invariant.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-6876296620533037670</id><published>2011-11-13T23:11:00.001+05:30</published><updated>2011-11-14T10:44:23.129+05:30</updated><title type='text'>Performing Cross Domain Requests with JSONP and JQuery using C# - Part 01</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;I will be breaking down the post in to two sections.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;First I will mention how to accomplish above mentioned task
using handlers and I will then go on and discuss the underlying concepts and
basic theories for the beginners in the next section.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: small;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;u&gt;How to get it
done!!!&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: small;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;What are the core parts we will need to perform a cross
domain request using JavaScript?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-indent: -0.25in;&quot;&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;A Mechanism to call the URL that sends data to
the calling page.&lt;/li&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;A padded JSON object (or a JSONP object)&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;If the calling URL don’t support cross domain
calls, functionality to wrap or pad the returned JSON object with a call back
function.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp;A method to handle the call back.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;OK! Let’s take this one step at a time.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;In this example I will be using JQuery AJAX facilities to
call the URL in the other domain.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;jQuery.ajax&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;({&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in; text-indent: 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;url:
&lt;span style=&quot;color: maroon;&quot;&gt;&quot;http://www.crosseddomain.com/testPage.html&lt;/span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in; text-indent: 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;dataType:
&lt;span style=&quot;color: maroon;&quot;&gt;&quot;jsonp&quot;&lt;/span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in; text-indent: 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;type:
&lt;span style=&quot;color: maroon;&quot;&gt;&quot;GET&quot;&lt;/span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in; text-indent: 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;cache:
&lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in; text-indent: 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;jsonpCallback:
&lt;span style=&quot;color: maroon;&quot;&gt;&#39;handleResponse&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;jsonpCallback&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;option allows us to
specify the call back method which will handle the returned data upon the
response is received.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;We specify &lt;b&gt;cache&lt;/b&gt; as true to avoid the
random time stamp value JQuery appends on the request.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;dataType&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;is set to&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;b&gt;&lt;span style=&quot;color: maroon;&quot;&gt;jsonp&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: maroon;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;so
the call back function will be added to the request.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;When the entire configuration is done correctly the page
will send a request like &lt;b&gt;&lt;a href=&quot;http://www.crosseddomain.com/testPage.html&amp;amp;callback=handleResponse&quot;&gt;http://www.crosseddomain.com/testPage.html&amp;amp;callback=handleResponse&lt;/a&gt;
&lt;/b&gt;through the network.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Now all we have to do is write a function to handle the
returned value, the &lt;/span&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;function name&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;
should be the value we passed for the&lt;/span&gt; &lt;b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;jsonpCallback&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;option&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; handleResponse(response) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in; text-indent: 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: darkgreen; font-family: Consolas;&quot;&gt;//your custom logic goes here&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0.0001pt 0.5in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;That will work only if the testPage.html wraps the response
with the call back. Or in other words if the requested page is responsible for
making the request cross domain compatible by converting the JSON object in to
a JSONP object by adding the call back function around it.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;What shall we do when we are given a URL that does not
support cross domain script calls? How to make it JSONP compatible?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Normal JSON objects will not work across cross domains because
of the &lt;b&gt;same origin policy, which
restricts &lt;u&gt;browser side programming langua&lt;/u&gt;ges from accessing scripts in
another site or a domain.&lt;/b&gt; (I will talk about these theory parts in detail on
my next blog, so stay tuned).&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;So obviously it does not restrict server side programming
languages like C# from accessing URLs in separate domains.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Keeping that in mind, we can send the request for the URL
from server side, after receiving the normal response we can wrap it with the
call back function and we can send it to the page where the call originated from.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;To get this done we will use a generic web handler or an
ashx file.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;For demonstration purposes, the handler will be expecting
some string data from the requesting page and it will send a dummy JSON object
that contains user inputted data with some custom data from the server side. (To
make things simple I will not add the code to do an actual web request, rather
I will just hard code the JSON string).&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;I will add a text box to the page and will get the user input
in each key press. After a response is received the call back function will
display retrieved data in a label.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The HTML markup will be&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Enter your text : &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;input&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;text&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;suggest&quot;&lt;/span&gt;
&lt;span style=&quot;color: red;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Suggestion&quot;&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;label&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;results&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;And the JQuery request will look something like this.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(document).ready(&lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; () {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;#suggest&quot;&lt;/span&gt;).keyup(&lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; () {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
data = $(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;#suggest&quot;&lt;/span&gt;).val();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jQuery.ajax({&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; url: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;http://localhost:18395/RequestHandler.ashx?data=&quot;&lt;/span&gt;
+ data,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataType: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;jsonp&quot;&lt;/span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;GET&quot;&lt;/span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cache: &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; jsonpCallback: &lt;span style=&quot;color: maroon;&quot;&gt;&#39;handleResponse&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The RequestHandler.ashx file code is mentioned below.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;
&lt;span style=&quot;color: #2b91af;&quot;&gt;RequestHandler&lt;/span&gt; : &lt;span style=&quot;color: #2b91af;&quot;&gt;IHttpHandler&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; ProcessRequest(&lt;span style=&quot;color: #2b91af;&quot;&gt;HttpContext&lt;/span&gt;
context)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
data = context.Request.QueryString[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;data&quot;&lt;/span&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
callback = context.Request.QueryString[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;callback&quot;&lt;/span&gt;];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
response = context.Response;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.Clear();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.ContentType = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;application/json&quot;&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
sampleJson = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;{\&quot;firstName\&quot;:\&quot;Dhanushka\&quot;,\&quot;lastName\&quot;:\&quot;Athukorala\&quot;,\&quot;dataReceived\&quot;:\&quot;&quot;&lt;/span&gt;
+ data + &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;\&quot;}&quot;&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
paddedResponse = &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.Format(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;{0}({1})&quot;&lt;/span&gt;, callback, sampleJson);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.Write(paddedResponse);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.Flush();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt; IsReusable&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;
&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;So let’s see what’s happening in the code behind file. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;We retrieve data passed from the user from the
query string&lt;/span&gt; (&lt;b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;data&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;variable&lt;/span&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Symbol;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Call back function name is also retrieved from
the query string&lt;/span&gt; (&lt;b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;callback&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;variable&lt;/span&gt;)&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Symbol;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;A JSON object is created (this is the line where
you have to call a URL and get data, you can use the functionalities
implemented in&lt;/span&gt; &lt;span style=&quot;color: #2b91af; font-family: Consolas;&quot;&gt;HttpWebRequest&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;HttpWebResponse
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;to accomplish this)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Symbol;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;We wrap the final JSON object with the call back
function so it will be in the format &lt;/span&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;callback(JSON)
&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;making it a JSONP object &lt;/span&gt;(&lt;b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;paddedResponse&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;variable&lt;/span&gt;)&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Symbol;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Symbol;&quot;&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;The JSONP object is written to the response making
it available for the calling page.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Now when the response is flushed it will return back to the
calling page. Here the script tag of that page will execute received data or
the JSONP object, or in other words it will call the call back method with a
JSON object.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;The code for our call back method is mentioned below.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; function&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; handleResponse(response) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
data = eval(response);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
firstName = data.firstName;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
lastName = data.lastName;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt;
sentData = data.dataReceived;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;#results&quot;&lt;/span&gt;).html(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;First Name : &quot;&lt;/span&gt; + firstName + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;br /&gt;Last Name : &quot;&lt;/span&gt; + lastName + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;br /&gt;Sent Data : &quot;&lt;/span&gt; + sentData);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;This call back method will process the returned JSON string
and will print the containing information in the results label&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;So in a nut shell the codes we need are&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Script tag and the HTML&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBwkYJ5XP-IFiMPhcE1UX4BQANbGIolrua7CITsuTlxjDx6lKxfHGZttUOv8jWrS_NVly-kQNaVQ5-ibI21SaF8lY4WkhDBbprDynVUzA3GxkVg2w7dQpalLuACJurgc58utQOg5Ts/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBwkYJ5XP-IFiMPhcE1UX4BQANbGIolrua7CITsuTlxjDx6lKxfHGZttUOv8jWrS_NVly-kQNaVQ5-ibI21SaF8lY4WkhDBbprDynVUzA3GxkVg2w7dQpalLuACJurgc58utQOg5Ts/s1600/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Handler code&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5RwBgPx0LIknS5effBfPqm0Z2376yWv4heQVu1ht77yt60Y-nLpXaXLo9jH3L2MjeOQkcJHokKBlyOn6wTomYKrju1DX4lWBGqiP0zcqtPaX2R3R0frNoRzc72oH54OkQp79_LyQN/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5RwBgPx0LIknS5effBfPqm0Z2376yWv4heQVu1ht77yt60Y-nLpXaXLo9jH3L2MjeOQkcJHokKBlyOn6wTomYKrju1DX4lWBGqiP0zcqtPaX2R3R0frNoRzc72oH54OkQp79_LyQN/s1600/3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;And the out put will be&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjED8XXDJxr-JXFo_mSaHCkH_hYuemW3tEgY-mRsroQFRT7jJg93N0JN7ao2M_qzNFDx5x-iMN7zyaWMHKoeJEicFn08NkJYodmMbyFcPtNphZt3aKPbE5eFTIil-u4wfwQRCIfmLmo/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjED8XXDJxr-JXFo_mSaHCkH_hYuemW3tEgY-mRsroQFRT7jJg93N0JN7ao2M_qzNFDx5x-iMN7zyaWMHKoeJEicFn08NkJYodmMbyFcPtNphZt3aKPbE5eFTIil-u4wfwQRCIfmLmo/s1600/4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Hope it helps.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;I will explain the underlying principals of cross domain communication with scripts in the second part of this blog.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;Cheers!!&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/6876296620533037670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2011/11/performing-cross-domain-requests-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/6876296620533037670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/6876296620533037670'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2011/11/performing-cross-domain-requests-with.html' title='Performing Cross Domain Requests with JSONP and JQuery using C# - Part 01'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBwkYJ5XP-IFiMPhcE1UX4BQANbGIolrua7CITsuTlxjDx6lKxfHGZttUOv8jWrS_NVly-kQNaVQ5-ibI21SaF8lY4WkhDBbprDynVUzA3GxkVg2w7dQpalLuACJurgc58utQOg5Ts/s72-c/2.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-4216441512490508279</id><published>2011-11-12T22:03:00.001+05:30</published><updated>2011-11-12T22:14:59.798+05:30</updated><title type='text'>LINQ – SQL Syntax Difference Explained.</title><content type='html'>&lt;w:sdt contentlocked=&quot;t&quot; id=&quot;89512093&quot; sdtgroup=&quot;t&quot;&gt;&lt;span style=&quot;font-family: Calibri, sans-serif; font-size: 1pt;&quot;&gt;&lt;w:sdtpr&gt;&lt;/w:sdtpr&gt;&lt;w:sdt docpart=&quot;96A3C461279B4ADB95C0BA16EA930DD1&quot; id=&quot;89512082&quot; storeitemid=&quot;X_7C9E2801-B296-4DD3-996A-EDEAC0DA722E&quot; text=&quot;t&quot; title=&quot;Post Title&quot; xpath=&quot;/ns0:BlogPostInfo/ns0:PostTitle&quot;&gt;&lt;/w:sdt&gt;&lt;/span&gt;
  &lt;/w:sdt&gt;&lt;br /&gt;
&lt;div class=&quot;Publishwithline&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;I got my blogger hat on after a very long time. With all the
week end lectures and office works cramping up my schedule, there was virtually
no time left for me to blog about anything. I came across pretty interesting topics
and subjects over my past few non blogging months and will try to share them
with you in the coming days.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Ok let’s get started…&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Let’s say we are writing a SQL query to retrieve the names
of the customers who are above 20, we will write something like this &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;select cust.name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;from customers cust&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;where cust.age&amp;gt;20&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Consolas;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;But when it comes to LINQ, as we all know the syntax is
totally inverted. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;The same query will look like this when we do it on a list
of Customer objects.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;color: #2b91af; font-family: Consolas;&quot;&gt;IEnumerable&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; olderCustomersQuery = &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; cust &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;
customers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; cust.Age &amp;gt; 20&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;select&lt;/span&gt; cust.Name;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;But WHY!!!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;To understand we need to get back to basics. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;There are two ways to build up a LINQ expression,
&lt;b&gt;Extension methods and Query operators&lt;/b&gt;. The one mentioned above falls in to the
latter part.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Let’s see how to write the same example using
extension methods.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;color: #2b91af; font-family: Consolas;&quot;&gt;IEnumerable&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; olderCustomersExtension =
customers&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .Where(cust =&amp;gt; cust.Age &amp;gt; 20)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .Select(cust =&amp;gt; cust.Name);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;All these extension methods are available on any
class that implements the generic &lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas;&quot;&gt;IQueryable&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;t&gt;&lt;/t&gt;&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;or &lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas;&quot;&gt;IEnumerable&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;T&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; interfaces.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;So what’s up with the ordering of the method calls, why do
we need to call the “Where” extension method before calling “Select”.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;The answer is simple.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;b&gt;Where&lt;/b&gt; &lt;b&gt;filters&lt;/b&gt; data that are returned from a data
source.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;While &lt;b&gt;Select&lt;/b&gt; &lt;b&gt;narrows down&lt;/b&gt; the information that shown
in the final projection by specifying &lt;b&gt;which
properties to retrieve&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;So when I say &lt;/span&gt;&lt;b style=&quot;font-family: Consolas;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;customers.Select(cust =&amp;gt;
cust.Name)&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; it just gives me a &lt;b&gt;list of strings&lt;/b&gt; so &lt;/span&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; font-family: Consolas;&quot;&gt;customers.Select(cust =&amp;gt; cust.Name).Where(cust =&amp;gt; cust.Age &amp;gt;
20)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt; &lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;ill not be possible because now the &lt;b&gt;Where clause don’t get a
customer object to query on&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghlh1fAVvPW1-yYV-yXfT12k2OGtxlKauPFzOxIiuQQfj6fnAtw3FYR8u07KbGS1WwXB6Mw10BfpPq1G46xRQ2l2oKkBP1AK8TS0ooA7hS2D5h4ONqSmTAIO2T3p0XYOkrQnnx8J7/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;105&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghlh1fAVvPW1-yYV-yXfT12k2OGtxlKauPFzOxIiuQQfj6fnAtw3FYR8u07KbGS1WwXB6Mw10BfpPq1G46xRQ2l2oKkBP1AK8TS0ooA7hS2D5h4ONqSmTAIO2T3p0XYOkrQnnx8J7/s400/1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Because of that when we are writing LINQ expressions we
should &lt;b&gt;use the extension methods in the
correct order&lt;/b&gt;, otherwise you may get unexpected query results or
compilation errors.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Although the LINQ extension methods and types that are
defined in &lt;b&gt;System.Linq&lt;/b&gt; namespace are very powerful, the syntax can be
quite cumbersome, and it is easy to introduce subtle errors that are difficult
to spot and correct.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;To avoid these drawbacks designers of C# have provided &lt;b&gt;an alternative approach&lt;/b&gt; to the use of
LINQ, through a series of &lt;b&gt;LINQ query operators&lt;/b&gt;
that are part of the C# language. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;There is an
equivalent query operator for each LINQ extension method.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Because these query operators are built to compliment the
functionality of the equalant extension methods. They should also follow the
above mentioned practices and rules to avoid any kind of side effects on the
data that will be retrieved by the LINQ expression.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Hope this clears things up!!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/4216441512490508279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2011/11/linq-sql-syntax-difference-explained.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4216441512490508279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4216441512490508279'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2011/11/linq-sql-syntax-difference-explained.html' title='LINQ – SQL Syntax Difference Explained.'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjghlh1fAVvPW1-yYV-yXfT12k2OGtxlKauPFzOxIiuQQfj6fnAtw3FYR8u07KbGS1WwXB6Mw10BfpPq1G46xRQ2l2oKkBP1AK8TS0ooA7hS2D5h4ONqSmTAIO2T3p0XYOkrQnnx8J7/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-1348434888581449475</id><published>2011-01-11T09:50:00.004+05:30</published><updated>2011-01-11T10:06:44.132+05:30</updated><title type='text'>LINQ to SQL with Views</title><content type='html'>&lt;span xmlns=&quot;&quot;&gt;We all know that data manipulation using tables have been made very easy by LINQ to SQL right! For an example a sample data retrieval and update query using LINQ will look something like this.&lt;br /&gt;
&lt;br /&gt;
I&#39;ll just note down the steps involved so rookies will have an idea of what I&#39;m talking about&lt;br /&gt;
&lt;ol style=&quot;margin-left: 38pt;&quot;&gt;&lt;li&gt;Add a new LINQ to SQL class file (.dbml) to your project&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Then drag and drop a table you want to query using the server explorer of VS (lets name the new file as Demo.dbml)&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;Here is some sample code to get you started with&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; context = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DemoDataContext&lt;/span&gt;(); &lt;span style=&quot;color: green;&quot;&gt;//get the data context you want to query&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;//retreive data from the table&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; records = &lt;span style=&quot;color: blue;&quot;&gt;from&lt;/span&gt; tableTest &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; dc.DemoTable&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;where&lt;/span&gt; tableTest.condition == -1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;select&lt;/span&gt; tableTest;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now let&#39;s play with them a bit&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; record &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; records){&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;  {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   var&lt;/span&gt; rowInfo = context.DemoTable.Single(ob =&amp;gt; ob.Id == rec.Id);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   var&lt;/span&gt; someValue=GetValue();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   rowInfo.condition = someValue &amp;gt; 0 ? 1 : 0;&lt;span style=&quot;color: green;&quot;&gt; //Change a value of a property&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;   context.SubmitChanges();&lt;span style=&quot;color: green;&quot;&gt;//Save the changed data to the table&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;  }&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Exception&lt;/span&gt; ex)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Console&lt;/span&gt;.WriteLine(ex.Message);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;continue&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;That&#39;s really straight forward right! We can use the same set of steps to manipulate data using SQL Views. But there seems to be some sort of a bug in VS2010 when using LINQ to SQL class files. When we drag and drop a table to a dbml file the primary key of the table is identified and is set correctly. But if we use a VIEW that incorporates a set of tables using UNIONS this does not happen. Making it&lt;/span&gt; impossible to save or update data in the underlying table because of the missing primary key.&lt;span xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; You will run the same code for a view but no data will get saved.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;span xmlns=&quot;&quot;&gt;To avoid such a bizarre situation you need to manually set the primary key of the view using properties. To do that select the view that you needs to work on and in its attributes set click on its primary key column and go to its properties. And set the Primary Key property to true.&lt;br /&gt;
&lt;br /&gt;
Now you will be able to work with your views without any problems.&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/1348434888581449475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2011/01/linq-to-sql-with-views.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1348434888581449475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1348434888581449475'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2011/01/linq-to-sql-with-views.html' title='LINQ to SQL with Views'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-8828743623398096919</id><published>2011-01-04T10:34:00.003+05:30</published><updated>2011-01-04T10:53:58.684+05:30</updated><title type='text'>JQuery Gantt chart</title><content type='html'>&lt;span xmlns=&quot;&quot;&gt;I came across a very useful plug-in few days back for drawing Gantt charts using JQuery. You can find all the information plus the files you need to download from here (&lt;a href=&quot;https://github.com/thegrubbsian/jquery.ganttView&quot;&gt;https://github.com/thegrubbsian/jquery.ganttView&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
As I described previously from a blog when we drew JQuery charts, we can use the power of JSON to get serialized data from the server side to populate the needed data model. In this case the the data model looked something like this.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; ganttData = &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;[&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id: 1, name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Feature 1&quot;&lt;/span&gt;,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; series:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Planned&quot;&lt;/span&gt;, start: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,01), end: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,03) },&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Actual&quot;&lt;/span&gt;, start: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,02), end: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,05) }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}, &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;
&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id: 2, name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Feature 2&quot;&lt;/span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span xmlns=&quot;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; series:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Planned&quot;&lt;/span&gt;, start: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,05), end: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,20) },&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Actual&quot;&lt;/span&gt;, start: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,06), end: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,17) },&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Projected&quot;&lt;/span&gt;, start: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,06), end: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,17) }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span xmlns=&quot;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
In order to tackle this, my server side data model should look something like this. &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;ContainerModel&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;    {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;String&lt;/span&gt; id { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;String&lt;/span&gt; name { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;DataModel&lt;/span&gt;&amp;gt; series { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;    }&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DataModel&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;    {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; string&lt;/span&gt; name { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DateTime&lt;/span&gt; start { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DateTime&lt;/span&gt; end { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;    }&lt;/span&gt; &lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span xmlns=&quot;&quot;&gt;Let&#39;s write a sample method to populate the data model with some dummy data.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;ContainerModel&lt;/span&gt;&amp;gt; PopulateData()&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;{&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; startDate = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DateTime&lt;/span&gt;(2010, 5, 12);&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; endDate = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DateTime&lt;/span&gt;(2010, 12, 5);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; planned = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DataModel&lt;/span&gt; { name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Planned&quot;&lt;/span&gt;, start = startDate, end = endDate };&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; actual = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DataModel&lt;/span&gt; { name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Actual&quot;&lt;/span&gt;, start = startDate, end = endDate };&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; projected = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DataModel&lt;/span&gt; { name = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Projected&quot;&lt;/span&gt;, start = startDate, end = endDate };&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; dataSet = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;ContainerModel&lt;/span&gt;&amp;gt;();&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; k = 0; k &amp;lt; 10; k++)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; container = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;ContainerModel&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                  id = k.ToString(),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                  name = &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.Format(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Feature {0}&quot;&lt;/span&gt;, k),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                  series = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;DataModel&lt;/span&gt;&amp;gt; { planned, actual, projected }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                              };&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;          dataSet.Add(container);&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span xmlns=&quot;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     }&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; dataSet;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;  }&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
And these methods were used to serialize the data model to JSON so we can use it from the JavaScript side.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; static&lt;/span&gt;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; ToJson(&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; obj)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;{&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; serializer = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;DataContractJsonSerializer&lt;/span&gt;(obj.GetType());&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; ms = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;MemoryStream&lt;/span&gt;();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     serializer.WriteObject(ms, obj);&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; json = &lt;span style=&quot;color: #2b91af;&quot;&gt;Encoding&lt;/span&gt;.Default.GetString(ms.ToArray());&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; json;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; }&lt;br /&gt;
&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; static&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; string&lt;/span&gt; GetJason(&lt;span style=&quot;color: #2b91af;&quot;&gt;List&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #2b91af;&quot;&gt;ContainerModel&lt;/span&gt;&amp;gt; dataModel)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;{&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; dataModel.ToJson();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; }&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s write a web method so we can use a JQuery AJAX call back to retrieve the prepared data.&lt;br /&gt;
I have embedded the above mentioned &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;PopulateData,&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;ToJson, GetJason &lt;/span&gt;methods in to a Helper class for more code clarity&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;[&lt;span style=&quot;color: #2b91af;&quot;&gt;WebMethod&lt;/span&gt;]&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; GetData()&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;{&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; modelData = &lt;span style=&quot;color: #2b91af;&quot;&gt;Helper&lt;/span&gt;.PopulateData();&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; jsonData = &lt;span style=&quot;color: #2b91af;&quot;&gt;Helper&lt;/span&gt;.GetJason(modelData);&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; jsonData;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;  }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now all our server side codes are completed, but then come the fun part. As you can see in the above mentioned data model the dates are represented as JavaScript Date objects&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;{ name: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Planned&quot;&lt;/span&gt;, start: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,05), end: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010,00,20) },&lt;/span&gt;&lt;br /&gt;
But date returned by Json is a string that looks something like this &quot;/Date(1273602600000+0530)/&quot; . &lt;br /&gt;
In order to convert that JSON serialized millisecond date string to a JavaScript Date object, we can use JavaScript &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;substring &lt;/span&gt;function with &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;eval&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;startDate = eval(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;new &quot;&lt;/span&gt; + start.substring(1, start.length - 7) + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;)&quot;&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
Resulting in returning a JavaScript Date object with a value like&lt;br /&gt;
&quot;Wed May 12 2010 00:00:00 GMT+0530 (Sri Lanka Standard Time)&quot;&lt;br /&gt;
&lt;br /&gt;
So let&#39;s replace the &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;DateUtils&lt;/span&gt; Class in the &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;jQuery.ganttView&lt;/span&gt;.js with this one&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; DateUtils = {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     daysBetweenBothString: &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; (start, end){&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; startDate, endDate;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;         startDate = eval(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;new &quot;&lt;/span&gt; + start.substring(1, start.length - 7) + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;)&quot;&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;         endDate = eval(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;new &quot;&lt;/span&gt; + end.substring(1, end.length - 7) + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;)&quot;&lt;/span&gt;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; count = 0, date = startDate.clone();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (date.compareTo(endDate) == -1) { count = count + 1; date.addDays(1); }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; count;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     },&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     daysBetweenEndString: &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; (start, end){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp; endDate = eval(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;new &quot;&lt;/span&gt; + end.substring(1, end.length - 7) + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;)&quot;&lt;/span&gt;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; count = 0, date = start.clone();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (date.compareTo(endDate) == -1) { count = count + 1; date.addDays(1); }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; count;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     },&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     daysBetween: &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; (start, end){&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; count = 0, date = start.clone();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (date.compareTo(end) == -1) { count = count + 1; date.addDays(1); }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; count;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     },&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     isWeekend: &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; (date){&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; date.getDay() % 6 == 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; };&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
And the addBlocks method with this&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;addBlocks: &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; (div, data, cellWidth, start){&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; rows = jQuery(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;div.ganttview-blocks div.ganttview-block-container&quot;&lt;/span&gt;, div);&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; rowIdx = 0;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; i = 0; i &amp;lt; data.length; i++) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; j = 0; j &amp;lt; data[i].series.length; j++) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; size = DateUtils.daysBetweenBothString(data[i].series[j].start, data[i].series[j].end);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; offset = DateUtils.daysBetweenEndString(start, data[i].series[j].start);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; blockDiv = jQuery(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&amp;lt;div&amp;gt;&quot;&lt;/span&gt;, {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: maroon;&quot;&gt;&quot;class&quot;&lt;/span&gt;: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;ganttview-block&quot;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: maroon;&quot;&gt;&quot;title&quot;&lt;/span&gt;: data[i].series[j].name + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;, &quot;&lt;/span&gt; + size + &lt;span style=&quot;color: maroon;&quot;&gt;&quot; days&quot;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: maroon;&quot;&gt;&quot;css&quot;&lt;/span&gt;: {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: maroon;&quot;&gt;&quot;width&quot;&lt;/span&gt;: ((size * cellWidth) - 9) + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;px&quot;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: maroon;&quot;&gt;&quot;margin-left&quot;&lt;/span&gt;: ((offset * cellWidth) + 3) + &lt;span style=&quot;color: maroon;&quot;&gt;&quot;px&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;                 }});&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (data[i].series[j].color){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;                 blockDiv.css(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;background-color&quot;&lt;/span&gt;, data[i].series[j].color);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;             }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;             blockDiv.append($(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&amp;lt;div&amp;gt;&quot;&lt;/span&gt;, { &lt;span style=&quot;color: maroon;&quot;&gt;&quot;class&quot;&lt;/span&gt;: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;ganttview-block-text&quot;&lt;/span&gt; }).text(size));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;             jQuery(rows[rowIdx]).append(blockDiv);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;             rowIdx = rowIdx + 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;         }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;     }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now you can use this modified version of the JS file to support your JSON serialized data object.&lt;br /&gt;
In the aspx page (in this case &lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9pt;&quot;&gt;Default.aspx&lt;/span&gt; ) where we need to draw the chart insert the following script&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt; &lt;/span&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;text/javascript&quot;&amp;gt;&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;$(document).ready(&lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; (){&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; ganttData = [];&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;     $(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;#btnGetData&quot;&lt;/span&gt;).live(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;click&quot;&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; (e){&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; button = $(&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;);&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; onDataReceived(series){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; &amp;nbsp;             ganttData = series.d;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; &amp;nbsp;             $(&lt;span style=&quot;color: maroon;&quot;&gt;&quot;#ganttChart&quot;&lt;/span&gt;).ganttView({&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; &amp;nbsp;                 data: $.parseJSON(ganttData),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; &amp;nbsp;                 start: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010, 05, 01),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; &amp;nbsp;                 end: &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(2010, 12, 31),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; &amp;nbsp;                 slideWidth: 900&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;             });&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;         }&lt;/span&gt; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; dataUrl = &lt;span style=&quot;color: maroon;&quot;&gt;&quot;Default.aspx/GetData&quot;&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; $.ajax({&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;             type: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;POST&quot;&lt;/span&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp; url: dataUrl,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;             data: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;{}&quot;&lt;/span&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;             contentType: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;application/json; charset=utf-8&quot;&lt;/span&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;             dataType: &lt;span style=&quot;color: maroon;&quot;&gt;&quot;json&quot;&lt;/span&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp; success: onDataReceived&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp; });&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;});&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; });&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;
And add the following div tag to the page so the JS file can inject the rendered Chart inside it&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt; &lt;/span&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;ganttChart&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Accompanied with the button to trigger the AJAX call back&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;color: maroon;&quot;&gt; &lt;/span&gt;id&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;btnGetData&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;type&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;button&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;value&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Get Data&quot;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; /&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now you are all set for your first JQuery Gantt Chart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&amp;nbsp;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/8828743623398096919/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2011/01/jquery-gantt-chart.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/8828743623398096919'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/8828743623398096919'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2011/01/jquery-gantt-chart.html' title='JQuery Gantt chart'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-4542278370267645019</id><published>2010-12-27T12:11:00.005+05:30</published><updated>2010-12-28T09:46:10.647+05:30</updated><title type='text'>What is the difference between Value types and Reference types in .net</title><content type='html'>&lt;span xmlns=&quot;&quot;&gt;&lt;span style=&quot;font-size: 12pt;&quot;&gt;I came across a pretty interesting series of articles when I was reading through &lt;/span&gt;Eric Lippert&#39;s MSDN blog today. Here are some of the things i grasped from him.&lt;br /&gt;
&lt;br /&gt;
What is the first thing that comes to your mind when someone asks from you &lt;b&gt;&quot;What is the difference between value types and reference types?&quot; &lt;/b&gt;Well I bet you will reply saying that value types are allocated in the stack and reference types are allocated in heap, right! Well you are correct that&#39;s what the C# documentation tells us. Then why don&#39;t we just call them &lt;b&gt;&lt;i&gt;stack types&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;heap types&lt;/i&gt;&lt;/b&gt; instead of value and reference. Well that&#39;s because that is not true most of the time.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s take the following class as an example.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; class&lt;/span&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;Demo&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;    {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; int&lt;/span&gt; ValueOne = 10;&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; int&lt;/span&gt; GetValue()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; ValueOne;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&amp;nbsp;&amp;nbsp;        }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;    }&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here the variable &quot;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;ValueOne&lt;/span&gt;&quot; is defined inside the &quot;Demo&quot; class. Here although &quot;&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;ValueOne&lt;/span&gt;&quot; is a value type integer variable it is an integral part of the &quot;Demo&quot; s instance memory. So it is allocated inside the heap.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s have a look at how this happens. &lt;br /&gt;
&lt;br /&gt;
Before we dwell in to it, let&#39;s see what does the terms &lt;b&gt;&lt;i&gt;&quot;short lived&quot;&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;&quot;long lived&quot; &lt;/i&gt;&lt;/b&gt;stands for in context of variables&lt;br /&gt;
&lt;br /&gt;
When a method is called an &lt;b&gt;&lt;i&gt;activation period &lt;/i&gt;&lt;/b&gt;is defined for that method&lt;b&gt;&lt;i&gt;, &lt;/i&gt;&lt;/b&gt;which can be defined as the time between the start of the method execution and its successful return or a throwing of an exception. Code in the method may require allocation of storage in memory for its variables. Let&#39;s look at a simple example&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt; public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; int&lt;/span&gt; GetSum()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; x = 10;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; y = 20;&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; sum = Add(x, y);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; sum;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; }&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; int&lt;/span&gt; Add(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; i, &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; j)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; i + j;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt; }&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here when the method &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;b&gt;&lt;i&gt;GetSum&lt;/i&gt;&lt;/b&gt;&lt;/span&gt; calls method &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;b&gt;&lt;i&gt;Add&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;, the use of the storage locations for the parameters passed to &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;b&gt;&lt;i&gt;Add&lt;/i&gt;&lt;/b&gt;&lt;/span&gt; and the value returned by &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;b&gt;&lt;i&gt;Add&lt;/i&gt;&lt;/b&gt;&lt;/span&gt; is required by &lt;span style=&quot;font-family: Consolas; font-size: 9pt;&quot;&gt;&lt;b&gt;&lt;i&gt;GetSum. &lt;/i&gt;&lt;/b&gt;&lt;/span&gt;This means that the required life time of the storage location is actually longer than the activation period of the method, thus making it a long lived variable or storage.&lt;br /&gt;
&lt;br /&gt;
So what does long/short lived stands for &lt;b&gt;&quot;If the required life time of a variable/storage is longer than its current method execution&#39;s activation period that variable is classified as a long lived variable otherwise a short lived one&quot;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
So how can value type variables get allocated inside the heap? Let&#39;s get to it one step at a time&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;There are three types of values in C#. Instances of value types, Instances of reference types and References.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;There are storage locations in memory that can store values they are stack, heap and registers.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Every value that is managed by some kind of a program stores their values in these storage locations, as well as every reference other than a null reference.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Every storage location in memory which has some content in them has a life time.(short/long lived)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Long lived storage locations are always heap locations and short lived storage locations are always in stack or registers.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;If the compiler cannot come to a clear decision if the variable is short lived or long lived that variable is considered as a long lived variable and is always stored in heap.&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;What happens is that during the compile time analysis if a local or a temporary variable is found to be un-used after the methods activation time it is stored on stack or register otherwise on heap. Depending on this model we can see that references and instances of value types are the same as far as their storage is concerned, but they can go on to either of those above mentioned storage locations depending on their life time. &lt;br /&gt;
&lt;br /&gt;
So that leaves us with an explanation that actually does not explain any concrete thing.&lt;br /&gt;
&lt;br /&gt;
Then what is the main, clearly distinctive difference between them. The best explanation is that &lt;b&gt;&quot;Value types are always copied by value and Reference types are always copied by reference&quot; &lt;/b&gt;and we can also go on to say that&lt;b&gt; &quot;Value types semantically represents a value and Reference types are a semantic reference to something&quot;.&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/4542278370267645019/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/difference-between-value-types-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4542278370267645019'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4542278370267645019'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/difference-between-value-types-and.html' title='What is the difference between Value types and Reference types in .net'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-1871388260527543541</id><published>2010-12-24T10:10:00.001+05:30</published><updated>2010-12-24T10:12:18.048+05:30</updated><title type='text'>Break a string by character type</title><content type='html'>Yesterday I came across an interesting situation. There are some times when you need to break a string in to two parts depending on their character type.&lt;br /&gt;
Lets say you have a string like &quot;Welfare Fund - 1000.00&quot; and you need to break the string part and the number part in to two different strings. Well the first thing that comes to mind is iterate the string till you get a number and break it to apart upon hitting on a number type character, right!!&lt;br /&gt;
Well then what about a string like &quot;Welfare Fund : 2009 - 3000.00&quot; &lt;br /&gt;
Here as you can see, there are numbers in the string part as well.&lt;br /&gt;
&lt;br /&gt;
The solution is simple, all you have to do is iterate through the string by starting from its end, till you reach a blank space. Here is the a method to accomplish that task&lt;br /&gt;
&lt;br /&gt;
public static List&amp;lt;string&amp;gt; BreakString(string stringToBreak)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var charArr = stringToBreak.ToCharArray();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var stringAppender = new StringBuilder();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var intAppender = new StringBuilder();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var isSeparated = false;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = charArr.Length - 1; i &amp;gt; -1; i--)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (isSeparated)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stringAppender.Append(charArr[i]);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isSeparated = charArr[i] == &#39; &#39;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!isSeparated)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intAppender.Append(charArr[i]);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var returnValues = new List&amp;lt;string&amp;gt; { ReverseString(stringAppender.ToString()), ReverseString(intAppender.ToString()) };&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return returnValues;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
public static string ReverseString(string s)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var arr = s.ToCharArray();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Array.Reverse(arr);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new string(arr);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
You can call it as follows&lt;br /&gt;
&lt;br /&gt;
var input = &quot;Welfare Fund - 1000.00&quot;;&lt;br /&gt;
var result = BreakString(input);</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/1871388260527543541/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/break-string-by-character-type.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1871388260527543541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1871388260527543541'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/break-string-by-character-type.html' title='Break a string by character type'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-1624488428066688145</id><published>2010-12-21T13:09:00.001+05:30</published><updated>2010-12-21T13:13:28.844+05:30</updated><title type='text'>Unit testing with Rhino Mock</title><content type='html'>There are some pretty good Mock object frameworks available out there for .net like NMock, EasyMock, TypeMock, etc... But I think every one will ultimately wind up using Rhino Mock at the end because of its easy to grasp rich feature set. So lets see how we can use Rhino to to mock a layered architecture for unit testing purposes.&lt;br /&gt;
&lt;br /&gt;
I will try to mock the repository and the service layer in the following code in an easy to understand manner&lt;br /&gt;
&lt;br /&gt;
Here are my sample repository and service interfaces (I have used NHibernate and Windsor Castle in this project as the ORM solutionl)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Repository Interface&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;public interface IInventoryRepository : IRepository&lt;recorditem&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;RecordItem&amp;gt; Get(List&amp;lt;int&amp;gt; ids);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;RecordItem&amp;gt; Get(List&amp;lt;int&amp;gt; ids, string orderByColumn, string orderType);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/recorditem&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Service Interface&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
public interface IInventoryService&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;ServiceItem&amp;gt; Get(List&amp;lt;int&amp;gt; ids, int truncLength);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;ServiceItem&amp;gt; Get(List&amp;lt;int&amp;gt; ids, string orderByColumn, string orderType, int truncLength);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
As I have described in my previous post lest use Nbuilder to mock the test objects that needs to be returned when the methods in the repository are called &lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Mock return for List&amp;lt;RecordItem&amp;gt; Get(List&amp;lt;&lt;/u&gt;&lt;u&gt;int&amp;gt;&lt;/u&gt;&lt;u&gt; ids)&lt;/u&gt;&lt;br /&gt;
private static List&amp;lt;RecordItem&amp;gt; CreateRecordItems()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var items = Builder&amp;lt;RecordItem&amp;gt;.CreateListOfSize(10).WhereAll().Have(x =&amp;gt; x.Title = &quot;sample title&quot;).WhereAll().Have(x =&amp;gt; x.AuthorName = &quot;Dhanushka&quot;).Build().ToList();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 1; i &amp;lt; items.Count + 1; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityIdSetter.SetIdOf(items[i - 1], i);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return items;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;Mock return for List&amp;lt;RecordItem&amp;gt; Get(List&amp;lt;int&amp;gt; ids, string orderByColumn, string orderType)&lt;/u&gt;&lt;br /&gt;
&amp;nbsp;private static List&amp;lt;RecordItem&amp;gt; CreateRecordItemsDesc()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var items = Builder&amp;lt;RecordItem&amp;gt;.CreateListOfSize(10).WhereAll().Have(x =&amp;gt; x.Title = &quot;sample title&quot;).WhereAll().Have(x =&lt;u&gt;&amp;gt;&lt;/u&gt; x.AuthorName = &quot;Dhanushka&quot;).Build().ToList();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var j = items.Count;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 1; i &amp;lt; items.Count + 1; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityIdSetter.SetIdOf(items[i - 1], j);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j--;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return items;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
Now lets use Rhino Mock to mock the Method Calls to the repository &lt;br /&gt;
&lt;br /&gt;
public static IInventoryRepository CreateMockInventoryRepository()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var mocks = new MockRepository();&lt;br /&gt;
//specify the repository to mock &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var mockedRepository = mocks.StrictMock&amp;lt;IInventoryRepository&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//specify what to return when a specific method is called in the mocked repository&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expect.Call(mockedRepository.Stub(x =&amp;gt; x.Get(Arg&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;.Is.Anything)).Return(CreateRecordItems()));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expect.Call(mockedRepository.Stub(x =&amp;gt; x.Get(Arg&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;.Is.Anything, Arg&amp;lt;string&amp;gt;.Is.Anything, Arg&amp;lt;string&amp;gt;.Is.Equal(&quot;asc&quot;))).Return(CreateRecordItems()));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expect.Call(mockedRepository.Stub(x =&amp;gt;x.Get(Arg&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;.Is.Anything, Arg&amp;lt;string&amp;gt;.Is.Anything, Arg&amp;lt;string&amp;gt;.Is.Equal(&quot;desc&quot;))).Return(CreateRecordItemsDesc()));&lt;br /&gt;
&lt;br /&gt;
//mock the current data base context&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var mockedDbContext = mocks.StrictMock&amp;lt;IDbContext&amp;gt;();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expect.Call(mockedDbContext.CommitChanges);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetupResult.For(mockedRepository.DbContext).Return(mockedDbContext);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mocks.Replay(mockedRepository);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return mockedRepository;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
As you can see this method mocks the repository with specification for method calls return values and reveal the mocked repository to the outer world.&lt;br /&gt;
&lt;br /&gt;
Now lets used this mocked repository to mock the service layer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public static IInventoryService&amp;nbsp;&amp;nbsp; CreateMockClipboardService()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var serviceMock =new InventoryService(InventoryRepositoryMock.CreateMockInventoryRepository());&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return serviceMock;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
Here the dependency injection is used with Windsor Castle to inject the service with the mocked repository layer.&lt;br /&gt;
&lt;br /&gt;
Now to write a sample test using NUnit all you have to do is&lt;br /&gt;
[TestFixture]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public class ServiceTest&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private IInventoryService&amp;nbsp; _service;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [SetUp]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void SetUp()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _service = new InventoryService(InventoryRepositoryMock.CreateMockInventoryRepository());&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Test]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void GetWithoutSortTest()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var idList = new List&amp;lt;int&amp;gt; {1, 2, 3, 4};&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const int truncLength = 100;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var itemsReturned = _service.Get(idList, truncLength);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var expectedItemType = typeof (ServiceItem);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const string expectedAuthor = &quot;Dhanushka&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const string expectedTitle = &quot;sample title&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(itemsReturned.Count, Is.GreaterThan(0),&quot;no items returned&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(itemsReturned[0], Is.TypeOf(expectedItemType),&quot;incorrect return type&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(itemsReturned[0].Author,Is.EqualTo(expectedAuthor),&quot;unexpected author returned&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Assert.That(itemsReturned[0].Title,Is.EqualTo(expectedTitle),&quot;unexpected title returned&quot;);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&lt;br /&gt;
Now we have a simple unit test in our hand that uses a mocked service and repository layer</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/1624488428066688145/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/unit-testing-using-rhino-mock.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1624488428066688145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1624488428066688145'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/unit-testing-using-rhino-mock.html' title='Unit testing with Rhino Mock'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-2760831524260177435</id><published>2010-12-21T11:24:00.000+05:30</published><updated>2010-12-21T11:25:38.865+05:30</updated><title type='text'>Mocking  objects using NBuilder</title><content type='html'>Most of us use some sort of a mocking library when doing unit tests in order to mock our service and repository layers right!&lt;br /&gt;
Well I am a big fan of Rhino Mock and I have used it in almost all of my testing projects.&lt;br /&gt;
But one thing that remains to be a pain in the ass is creating test objects to be returned when the mocked repository is called. Well not any more!!!&lt;br /&gt;
&lt;br /&gt;
Using NBulder we can avoid hard coding test objects for mocking purposes.&lt;br /&gt;
&lt;br /&gt;
Here are some sample codes to get you started with&lt;br /&gt;
&lt;br /&gt;
Let&#39;s say you want to mock a a repository call that returns an item, just write&lt;br /&gt;
var item = Builder&amp;lt;RepositoyType&amp;gt;&lt;repositoryitem&gt;.CreateNew().Build();&lt;/repositoryitem&gt;&lt;br /&gt;
//set the id property of each items (Nhibernate is used with Windsor Castle in this occasion) &lt;br /&gt;
EntityIdSetter.SetIdOf(item, 1);&lt;br /&gt;
&lt;br /&gt;
To mock a method call that returns a list of record objects.&lt;br /&gt;
var items = Builder&amp;lt;RepositoyType&amp;gt;&lt;recorditem&gt;.CreateListOfSize(10).WhereAll().Have(x =&amp;gt; x.Title = &quot;sample title&quot;).WhereAll().Have(x =&amp;gt; x.AuthorName = &quot;Dhanushka&quot;).Build().ToList();&lt;br /&gt;
&amp;nbsp;for (int i = 1; i &amp;lt; items.Count + 1; i++)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityIdSetter.SetIdOf(items[i - 1], i);&lt;br /&gt;
}&lt;/recorditem&gt;&lt;br /&gt;
As you can see from the above example we can even set specific values for the attributes for returned objects as well.&lt;br /&gt;
&lt;br /&gt;
And there are many more helper functions you can use to accomplish almost all the test object creation needs you hope for.&lt;br /&gt;
&lt;br /&gt;
Happy Coding!!</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/2760831524260177435/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/mocking-objects-using-nbuilder.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/2760831524260177435'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/2760831524260177435'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/mocking-objects-using-nbuilder.html' title='Mocking  objects using NBuilder'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-2318154096753209573</id><published>2010-12-03T12:22:00.000+05:30</published><updated>2010-12-03T12:22:40.051+05:30</updated><title type='text'>PasswordStrengthRegularExpression issue in MembershipProvider ResetPassword</title><content type='html'>I came across an interesting issue today. I used the &lt;b&gt;ResetPassword&lt;/b&gt; method provided by C# membership class to reset the password of a user and found out that although it allows us to define the password strength using a regular expression in the web.config file, it does not guarantee that the generated password adheres to the rules defined by the expression. Microsoft says and I quote&lt;br /&gt;
&quot;The random password created by the &lt;b&gt;&lt;span class=&quot;selflink&quot;&gt;ResetPassword&lt;/span&gt; &lt;/b&gt;method is not guaranteed to pass the regular expression in the &lt;b&gt;&lt;span style=&quot;color: black;&quot;&gt;PasswordStrengthRegularExpression&lt;/span&gt; &lt;/b&gt;property. However, the random password will meet the criteria established by the &lt;b&gt;MinRequiredPasswordLength &lt;/b&gt;and &lt;b&gt;MinRequiredNonAlphanumericCharacters &lt;/b&gt;properties.&quot;&lt;br /&gt;
&lt;br /&gt;
So to tackle the issue, I used the Regex class. The revised code is shown below&lt;br /&gt;
&lt;br /&gt;
var isNotMatch = true;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(isNotMatch)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; resetpwd = manager.ResetPassword();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var matcher=new Regex(Membership.PasswordStrengthRegularExpression);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt; isNotMatch = !(matcher.IsMatch(resetpwd));&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
This code snippet will force the &lt;b&gt;ResetPassword &lt;/b&gt;to fire until a password adhering to the rules defined by the regular expression is generated.</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/2318154096753209573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/passwordstrengthregularexpression-issue.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/2318154096753209573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/2318154096753209573'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/12/passwordstrengthregularexpression-issue.html' title='PasswordStrengthRegularExpression issue in MembershipProvider ResetPassword'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-7433498299370897322</id><published>2010-11-18T15:44:00.001+05:30</published><updated>2010-11-18T16:08:44.683+05:30</updated><title type='text'>JavaScript setAttribute not working for IE</title><content type='html'>I came across an interesting problem when using java script &quot;setSttribute&quot; method with IE. Apparently it does not work with IE versions 5.5 to 7 when we try to use it to set a style to an element.&lt;br /&gt;&lt;br /&gt;For all the browsers including IE8 and above this code will work fine when we a want to set a a style attribute to an element using java script.&lt;br /&gt;&lt;br /&gt;var elemntToTest=document.createElement(&#39;a&#39;);&lt;br /&gt;elemntToTest.setAttribute(&#39;href&#39;, &#39;#&#39;);&lt;br /&gt;elemntToTest.setAttribute(&#39;style&#39;, &#39;padding:3px&#39;);&lt;br /&gt;&lt;br /&gt;but in IE 5.5-7 you will need to set the style like this.&lt;br /&gt;&lt;br /&gt;elemntToTest.style.cssText = &quot;padding:3px;&quot;;&lt;br /&gt;&lt;br /&gt;Now it will work fine in all the browsers.&lt;br /&gt;&lt;br /&gt;Hope this work around helps!!!</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/7433498299370897322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/javascript-setattribute-not-working-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7433498299370897322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7433498299370897322'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/javascript-setattribute-not-working-for.html' title='JavaScript setAttribute not working for IE'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-3468172986451010822</id><published>2010-11-17T21:06:00.000+05:30</published><updated>2010-11-17T23:14:22.670+05:30</updated><title type='text'>Flot, A pure JQuery Charting tool and How to get the maximum from it using JSON serialization in C#</title><content type='html'>&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves/&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-US&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;TA&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:dontvertaligncellwithsp/&gt;    &lt;w:dontbreakconstrainedforcedtables/&gt;    &lt;w:dontvertalignintxbx/&gt;    &lt;w:word11kerningpairs/&gt;    &lt;w:cachedcolbalance/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val=&quot;Cambria Math&quot;&gt;    &lt;m:brkbin val=&quot;before&quot;&gt;    &lt;m:brkbinsub val=&quot;--&quot;&gt;    &lt;m:smallfrac val=&quot;off&quot;&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val=&quot;0&quot;&gt;    &lt;m:rmargin val=&quot;0&quot;&gt;    &lt;m:defjc val=&quot;centerGroup&quot;&gt;    &lt;m:wrapindent val=&quot;1440&quot;&gt;    &lt;m:intlim val=&quot;subSup&quot;&gt;    &lt;m:narylim val=&quot;undOvr&quot;&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate=&quot;false&quot; defunhidewhenused=&quot;true&quot; defsemihidden=&quot;true&quot; defqformat=&quot;false&quot; defpriority=&quot;99&quot; latentstylecount=&quot;267&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;0&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Normal&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;heading 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 7&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 8&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;9&quot; qformat=&quot;true&quot; name=&quot;heading 9&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 7&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 8&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; name=&quot;toc 9&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;35&quot; qformat=&quot;true&quot; name=&quot;caption&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;10&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Title&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;1&quot; name=&quot;Default Paragraph Font&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;11&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Subtitle&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;22&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Strong&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;20&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Emphasis&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;59&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Table Grid&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Placeholder Text&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;1&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;No Spacing&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;60&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Shading&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;61&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light List&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;62&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Grid&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;63&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;64&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;65&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;66&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;67&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;68&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;69&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;70&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Dark List&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;71&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Shading&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;72&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful List&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;73&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Grid&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;60&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Shading Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;61&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light List Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;62&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Grid Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;63&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 1 Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;64&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 2 Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;65&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 1 Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Revision&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;34&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;List Paragraph&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;29&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Quote&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;30&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Intense Quote&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;66&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 2 Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;67&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 1 Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;68&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 2 Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;69&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 3 Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;70&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Dark List Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;71&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Shading Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;72&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful List Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;73&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Grid Accent 1&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;60&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Shading Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;61&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light List Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;62&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Grid Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;63&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 1 Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;64&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 2 Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;65&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 1 Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;66&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 2 Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;67&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 1 Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;68&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 2 Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;69&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 3 Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;70&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Dark List Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;71&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Shading Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;72&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful List Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;73&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Grid Accent 2&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;60&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Shading Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;61&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light List Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;62&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Grid Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;63&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 1 Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;64&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 2 Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;65&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 1 Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;66&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 2 Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;67&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 1 Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;68&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 2 Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;69&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 3 Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;70&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Dark List Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;71&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Shading Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;72&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful List Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;73&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Grid Accent 3&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;60&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Shading Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;61&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light List Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;62&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Grid Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;63&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 1 Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;64&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 2 Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;65&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 1 Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;66&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 2 Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;67&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 1 Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;68&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 2 Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;69&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 3 Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;70&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Dark List Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;71&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Shading Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;72&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful List Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;73&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Grid Accent 4&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;60&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Shading Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;61&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light List Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;62&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Grid Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;63&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 1 Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;64&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 2 Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;65&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 1 Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;66&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 2 Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;67&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 1 Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;68&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 2 Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;69&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 3 Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;70&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Dark List Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;71&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Shading Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;72&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful List Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;73&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Grid Accent 5&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;60&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Shading Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;61&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light List Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;62&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Light Grid Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;63&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 1 Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;64&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Shading 2 Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;65&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 1 Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;66&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium List 2 Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;67&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 1 Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;68&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 2 Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;69&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Medium Grid 3 Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;70&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Dark List Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;71&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Shading Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;72&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful List Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;73&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; name=&quot;Colorful Grid Accent 6&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;19&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Subtle Emphasis&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;21&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Intense Emphasis&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;31&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Subtle Reference&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;32&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Intense Reference&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;33&quot; semihidden=&quot;false&quot; unhidewhenused=&quot;false&quot; qformat=&quot;true&quot; name=&quot;Book Title&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;37&quot; name=&quot;Bibliography&quot;&gt;   &lt;w:lsdexception locked=&quot;false&quot; priority=&quot;39&quot; qformat=&quot;true&quot; name=&quot;TOC Heading&quot;&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable  {mso-style-name:&quot;Table Normal&quot;;  mso-tstyle-rowband-size:0;  mso-tstyle-colband-size:0;  mso-style-noshow:yes;  mso-style-priority:99;  mso-style-qformat:yes;  mso-style-parent:&quot;&quot;;  mso-padding-alt:0in 5.4pt 0in 5.4pt;  mso-para-margin-top:0in;  mso-para-margin-right:0in;  mso-para-margin-bottom:10.0pt;  mso-para-margin-left:0in;  line-height:115%;  mso-pagination:widow-orphan;  font-size:11.0pt;  font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;  mso-ascii-font-family:Calibri;  mso-ascii-theme-font:minor-latin;  mso-fareast-font-family:&quot;Times New Roman&quot;;  mso-fareast-theme-font:minor-fareast;  mso-hansi-font-family:Calibri;  mso-hansi-theme-font:minor-latin;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;As we all know there are some pretty amazing and powerful charting tools available for web developers to use, some are commercial and some are free. But a main disadvantage i saw in many of them is that, almost all of them use flash to draw graphics and manipulate settings. &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;But there is some pretty sleek free JQuery chart plug-ins available out there. To name a few Flot, Google Charts, jQuery Chart, jQchart, TufteGraph etc...&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;After a brief R&amp;amp;D Flot attracted me most because of its rich options set and clean, easy to use and maintainable code.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Now I will explain how to draw a simple line chart using Flot in an ASP.net web site.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;I will use AJAX calls to fetch data from the server to populate chart data sets in the following example. But rather than using page methods or update panels, I will use simple JQuery AJAX post backs ($.ajax) to accomplish data retrieving tasks.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;So here we go...&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Let’s take a look at how Flot accepts data to draw its chart. Here is a simple JSON object which will be used to draw the chart line.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;{&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;label: &#39;Europe (EU27)&#39;,&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;data: [[1999, 3.0], [2000, 3.9]]&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;So let’s create a class similar to this JSON object so we can serialize an object of that class to something similar.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;public class Model&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;{&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;public string label;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;public List&amp;lt;List&amp;lt;int&amp;gt;&amp;gt; data;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;And let’s write a Helper class containing simple methods that can be used to serialize the Model object to a JSON object.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;public static class Helper&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;{&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;private static string ToJson(this object obj)&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;{&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;var serializer = new DataContractJsonSerializer(obj.GetType());&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;var ms = new MemoryStream();&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;serializer.WriteObject(ms, obj);&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;var json = Encoding.Default.GetString(ms.ToArray());&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;return json;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;public static string GetJason(Model dataModel)&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;{&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;return dataModel.ToJson();&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;* DataContractJsonSerializer is inside the System.Runtime.Serialization.Json namespace&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Now we will write a simple web method (web service method) that can be called from the client side JavaScript.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;[WebMethod]&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;public static string GetData()&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;{&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;var dataModel = new Model {label = &quot;Sample Chart&quot;};&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;var dataList = new List&amp;lt;List&amp;lt;int&amp;gt;&amp;gt;();&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;for (int i = 1; i &lt;&gt;  &lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;{&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;var data = new List&lt;int&gt; {i, (i*i) + 8};&lt;/int&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;dataList.Add(data);&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;dataModel.data = dataList;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;return Helper.GetJason(dataModel);&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;This function will return a serialized data object like this.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;{&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&quot;data&quot;:[[1,9],[2,12],[3,17],[4,24],[5,33],[6,44],[7,57],[8,72],[9,89]],&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&quot;label&quot;:&quot;Sample Chart&quot;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Now that&#39;s all from the server side. Let’s look at the client side javascript functions&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;In the aspx page add references to jquery.js and jquery.flot.js (download them from http://code.google.com/p/flot/downloads/list)&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;And inside the body add a div with the id &quot;placeholder&quot; to hold the chart.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;add a button with the id “btnGetData” so we can fetch data upon user request&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Here is the sample code to draw the chart using our predefined methods in the server side.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;$(document).ready(function() {&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;//options that can be enabled in the chart, more options are available&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;var options = {&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;lines: { show: true },&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;points: { show: true },&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;xaxis: { tickDecimals: 0, tickSize: 1 }&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;};&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;var data = []; //data used to draw the chart&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;var placeholder = $(&quot;#placeholder&quot;); //chart wrapper&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;$.plot(placeholder, data, options); //draw the chart&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;var alreadyFetched = {};&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;$(&quot;#btnGetData&quot;).live(&quot;click&quot;, function(e) {&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;var button = $(this); //get the clicked button&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;//execute this function after data is successfully retrieved from the ajax call&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;function onDataReceived(series) {&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;series = $.parseJSON(series.d); //get the json object (use the latest jquery script)&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;var firstcoordinate = &#39;(&#39; + series.data[0][0] + &#39;, &#39; + series.data[0][1] + &#39;)&#39;;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;button.siblings(&#39;span&#39;).text(&#39;Fetched &#39; + series.dabel + &#39;, first point: &#39; + firstcoordinate);&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;if (!alreadyFetched[series.label]) {&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                        &lt;/span&gt;alreadyFetched[series.label] = true;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                        &lt;/span&gt;data.push(series); //populate data&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;               &lt;/span&gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;$.plot(placeholder, data, options); //draw the chart&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;}&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;var dataUrl = &quot;Default.aspx/GetData&quot;; //server method to get data&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;$.ajax({&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;type: &quot;POST&quot;,&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;url: dataUrl,&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;data: &quot;{}&quot;,&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;contentType: &quot;application/json; charset=utf-8&quot;,&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;dataType: &quot;json&quot;,&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                    &lt;/span&gt;success: onDataReceived&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;});&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;});&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;});&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;This will draw a simple line chart on your screen.&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt; &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;Happy charting!!!&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/3468172986451010822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/pure-jquery-charting-tool-and-how-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/3468172986451010822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/3468172986451010822'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/pure-jquery-charting-tool-and-how-to.html' title='Flot, A pure JQuery Charting tool and How to get the maximum from it using JSON serialization in C#'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-1641299021708466957</id><published>2010-11-16T08:44:00.000+05:30</published><updated>2010-11-16T12:53:27.517+05:30</updated><title type='text'>Object Oriented JQuery/JavaScript</title><content type='html'>All of us are familiar with OOP concepts, right!! &lt;br /&gt;But how many of you have tried to use them in JavaScript.&lt;br /&gt;Here is a simple code example to get you up and running.&lt;br /&gt;&lt;br /&gt;First I will create a simple JavaScript class. When uing C# or Java etc... , We use the keyword &quot;class&quot;. &lt;br /&gt;To denote a class in JavaScript we use &quot;function&quot;. &lt;br /&gt;&lt;br /&gt;Here we go...&lt;br /&gt;&lt;br /&gt;function Helper() {&lt;br /&gt;&lt;br /&gt;    $.fn.getCurrentIds = function (name) {&lt;br /&gt;        var selectedIds = new Array();&lt;br /&gt;        $(&#39;input:checkbox[name=&#39; + name + &#39;]:checked&#39;).each(function () {&lt;br /&gt;            selectedIds.push($(this).val());&lt;br /&gt;        });&lt;br /&gt;        var idString = &quot;&quot;;&lt;br /&gt;        for (var i = 0; i &lt; selectedIds.length; i++) {&lt;br /&gt;            if (i == selectedIds.length - 1)&lt;br /&gt;                idString += selectedIds[i];&lt;br /&gt;            else&lt;br /&gt;                idString += selectedIds[i] + &#39;,&#39;;&lt;br /&gt;        }&lt;br /&gt;        return idString;&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    this.setAllSelectedIds = function (checkBoxName, hdnId) {&lt;br /&gt;        var hdnControlString = &#39;#&#39; + hdnId + &#39;&#39;;&lt;br /&gt;        if ($(hdnControlString)) {&lt;br /&gt;            if ((!($(hdnControlString).val())) || $(hdnControlString).val() == &quot;&quot;)&lt;br /&gt;                $(hdnControlString).val($.fn.getCurrentIds(checkBoxName));&lt;br /&gt;            else&lt;br /&gt;                if ($.fn.getCurrentIds(checkBoxName) != &quot;&quot;)&lt;br /&gt;                    $(hdnControlString).val($(hdnControlString).val() + &#39;,&#39; + $.fn.getCurrentIds(checkBoxName));&lt;br /&gt;        }&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    this.setCheckboxStatus = function (hdnId) {&lt;br /&gt;        var hdnControlString = &#39;#&#39; + hdnId + &#39;&#39;;&lt;br /&gt;        if ($(hdnControlString) &amp;&amp; $(hdnControlString).val()) {&lt;br /&gt;            if ($(hdnControlString).val() != &quot;&quot;) {&lt;br /&gt;                var idArray = $(hdnControlString).val().split(&#39;,&#39;);&lt;br /&gt;                $.each(idArray, function (index, value) {&lt;br /&gt;                    if (&quot;input:checkbox[value=&quot; + value + &quot;]&quot;)&lt;br /&gt;                        $(&quot;input:checkbox[value=&quot; + value + &quot;]&quot;).attr(&quot;checked&quot;, true);&lt;br /&gt;                });&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    this.getAllSelectedIds = function (hdnId) {&lt;br /&gt;        var hdnControlString = &#39;#&#39; + hdnId + &#39;&#39;;&lt;br /&gt;        var idString = &quot;&quot;;&lt;br /&gt;        if ($(hdnControlString))&lt;br /&gt;            idString = $(hdnControlString).val();&lt;br /&gt;        if (!idString)&lt;br /&gt;            idString = &quot;&quot;;&lt;br /&gt;        return idString;&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Here I have defined some useful common utility functions which will be used in and out side of the class.&lt;br /&gt;if you look closely, you will see that the function &quot;getCurrentIds&quot; is called from another method or a function within the class that is &quot;setAllSelectedIds&quot; we have used JQuery pointers to do so - &quot;$.fn.getCurrentIds(checkBoxName)&quot;&lt;br /&gt;&lt;br /&gt;what about out side of the class.&lt;br /&gt;&lt;br /&gt;Its the same as any OOP based language. &lt;br /&gt;  -Create an object of the class&lt;br /&gt;  -Call object methods&lt;br /&gt;&lt;br /&gt;here is an example&lt;br /&gt;&lt;br /&gt;var helperObj = new Helper();&lt;br /&gt;helperObj.setAllSelectedIds(itemCheckBoxName, hdnAllChkIds);//returns void&lt;br /&gt;var allItemsSelected = helperObj.getAllSelectedIds(hdnAllChkIds);//returns a string containing all the selected check box ids.&lt;br /&gt;&lt;br /&gt;you can elaborate further on this concept and can use it to write more complex but clean and maintainable code&lt;br /&gt;&lt;br /&gt;Hope it helped!!!</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/1641299021708466957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/object-oriented-jqueryjavascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1641299021708466957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1641299021708466957'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/object-oriented-jqueryjavascript.html' title='Object Oriented JQuery/JavaScript'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-6199049963196839726</id><published>2010-11-15T17:17:00.000+05:30</published><updated>2010-11-15T17:20:09.305+05:30</updated><title type='text'>Store a value in cookie from a class project in ASP MVC</title><content type='html'>You can use the following method to store a string value in cookie using C#.net 4.0&lt;br /&gt;&lt;br /&gt;        public static void StoreCookie(string name, string valueToStore)&lt;br /&gt;        {&lt;br /&gt;            var cookie = new HttpCookie(name) {Value = valueToStore, Expires = DateTime.Now.AddYears(1)};&lt;br /&gt;            HttpContext.Current.Response.Cookies.Add(cookie);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;Here classes like &quot;HttpCookie&quot; and &quot;HttpContext&quot; needs to be used in order to access cookies from a class library.</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/6199049963196839726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/store-value-in-cookie-from-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/6199049963196839726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/6199049963196839726'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/store-value-in-cookie-from-class.html' title='Store a value in cookie from a class project in ASP MVC'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-8395532690404964175</id><published>2010-11-15T17:08:00.000+05:30</published><updated>2010-11-15T17:10:54.646+05:30</updated><title type='text'>Truncate a paragraph to the last word</title><content type='html'>This kind of truncation is always needed if you are displaying a truncated version of a meaningful string in the UI. Rather than simply truncating the list to a specific maximum length it is always handy to chop it to the last meaningful word. &lt;br /&gt;The following lines of code accomplish that task&lt;br /&gt;&lt;br /&gt;        public static string TruncateToLastWord(string value, int maxLength)&lt;br /&gt;        {&lt;br /&gt;            string stringToTruncate = value.Substring(0, maxLength);&lt;br /&gt;            int indexOfLastSpace = stringToTruncate.LastIndexOf(&#39; &#39;);&lt;br /&gt;            string truncatedString = stringToTruncate.Substring(0, indexOfLastSpace);&lt;br /&gt;            return string.Format(&quot;{0}...&quot;, truncatedString);&lt;br /&gt;        }</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/8395532690404964175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/truncate-paragraph-to-last-word.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/8395532690404964175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/8395532690404964175'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/truncate-paragraph-to-last-word.html' title='Truncate a paragraph to the last word'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-5058475582563016582</id><published>2010-11-15T17:01:00.000+05:30</published><updated>2010-11-15T17:08:03.866+05:30</updated><title type='text'>Remove duplicate values from a list</title><content type='html'>Lets say you have two lists that contains a set of Ids, and some ids are repeated in both the lists. &lt;br /&gt;Here is a simple piece of code to get a concatenated list without the duplicate ids&lt;br /&gt;&lt;br /&gt;public static List&lt;int&gt; RemoveExistingValues(List&lt;int&gt; oldSet, List&lt;int&gt; newSet)&lt;br /&gt;        {&lt;br /&gt;            foreach (var item in newSet)&lt;br /&gt;                oldSet.RemoveAll(x=&gt;x==item);&lt;br /&gt;            return oldSet;&lt;br /&gt;        }</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/5058475582563016582/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/remove-duplicate-values-from-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/5058475582563016582'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/5058475582563016582'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/remove-duplicate-values-from-list.html' title='Remove duplicate values from a list'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-2198138705542452308</id><published>2010-11-15T15:57:00.000+05:30</published><updated>2010-11-15T17:00:59.209+05:30</updated><title type='text'>Set the check status of all check boxes in a page using JQuery</title><content type='html'>The requirement I am gonna illustrate now comes up in almost all development efforts where a grid or a tabular view is displayed. there is a single check box in the table header where upon click you need to change the checked status of all the check boxes in the grid&lt;br /&gt;Here is a simple bit of code you can use to achieve that task&lt;br /&gt;&lt;br /&gt;function(){&lt;br /&gt;$(&#39;#&#39; + allCheckBoxName + &#39;&#39;).live(&quot;change&quot;, function (e) {&lt;br /&gt;                    $(&quot;INPUT[type=&#39;checkbox&#39;]&quot;).attr(&#39;checked&#39;, $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).is(&#39;:checked&#39;));&lt;br /&gt;                });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Here &quot;allCheckBoxName&quot; is the master check box which is at the top of the grid.&lt;br /&gt;&lt;br /&gt;But an issue arise when using this script with a drop down in the same page in IE browsers. that is in IE you need to bind check boxes events first before any other event bindings in order to work them properly. and strangely this is true with drop downs as well. so you face a strange dillema. &quot;How can I bind events for two different kinds of controls at once?&quot;&lt;br /&gt;&lt;br /&gt;To overcome this just add the following code segment to the code&lt;br /&gt;&lt;br /&gt;if ($.browser.msie) {&lt;br /&gt;            $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).unbind(&quot;click&quot;);&lt;br /&gt;            $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).live(&quot;click&quot;, function (e) {&lt;br /&gt;                $(this).trigger(&quot;change&quot;);&lt;br /&gt;            });&lt;br /&gt;&lt;br /&gt;what it does is it rebinds the check box events after the drop down bind and trigger the change event.&lt;br /&gt;so the completed function will look some thing like this&lt;br /&gt;&lt;br /&gt;function () {&lt;br /&gt;        if ($.browser.msie) {&lt;br /&gt;            $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).unbind(&quot;click&quot;);&lt;br /&gt;            $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).live(&quot;click&quot;, function (e) {&lt;br /&gt;                $(this).trigger(&quot;change&quot;);&lt;br /&gt;            });&lt;br /&gt;            if (allCheckBoxVisibility) {&lt;br /&gt;                $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).live(&quot;change&quot;, function (e) {&lt;br /&gt;                    $(&quot;INPUT[type=&#39;checkbox&#39;]&quot;).attr(&#39;checked&#39;, $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).is(&#39;:checked&#39;));&lt;br /&gt;                });&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;            $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).live(&quot;click&quot;, function (e) {&lt;br /&gt;                $(&quot;INPUT[type=&#39;checkbox&#39;]&quot;).attr(&#39;checked&#39;, $(&#39;#&#39; + allCheckBoxName + &#39;&#39;).is(&#39;:checked&#39;));&lt;br /&gt;            });&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Hope it helps!!!</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/2198138705542452308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/set-check-status-of-all-check-boxes-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/2198138705542452308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/2198138705542452308'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/set-check-status-of-all-check-boxes-in.html' title='Set the check status of all check boxes in a page using JQuery'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-7715075583260571298</id><published>2010-11-15T15:44:00.000+05:30</published><updated>2010-11-15T15:57:06.384+05:30</updated><title type='text'>Get all the selected check box IDs in page using JQuery</title><content type='html'>lots of guys have asked from me how to do this using java script. here is a small code snippet to help them out &lt;br /&gt;&lt;br /&gt;function (name) {&lt;br /&gt;        var selectedIds = new Array();&lt;br /&gt;        $(&#39;input:checkbox[name=&#39; + name + &#39;]:checked&#39;).each(function () {&lt;br /&gt;            selectedIds.push($(this).val());&lt;br /&gt;        });&lt;br /&gt;        var idString = &quot;&quot;;&lt;br /&gt;        for (var i = 0; i &lt; selectedIds.length; i++) {&lt;br /&gt;            if (i == selectedIds.length - 1)&lt;br /&gt;                idString += selectedIds[i];&lt;br /&gt;            else {&lt;br /&gt;                idString += selectedIds[i] + &#39;,&#39;;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return idString;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;Cheers!!!</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/7715075583260571298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/get-all-selected-check-box-ids-in-page.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7715075583260571298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7715075583260571298'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/11/get-all-selected-check-box-ids-in-page.html' title='Get all the selected check box IDs in page using JQuery'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-7461707429479197098</id><published>2010-05-12T16:27:00.000+05:30</published><updated>2010-11-15T15:33:12.713+05:30</updated><title type='text'>Optional arguments in C# 4.0</title><content type='html'>With C# 4.0 you can assign a default value to a parameter when you are declaring a method&lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;public  static void updateMyCV(string name=”Dhanushka”){ do some task }&lt;br /&gt;&lt;br /&gt;you can call the method in following ways&lt;br /&gt;updateMyCV();   //this will assign the default value to the parameter name&lt;br /&gt;updateMyCV(“Athukorala”);    //passed in value is assigned to the parameter&lt;br /&gt;&lt;br /&gt;As you can see when you are calling these method, parameters in the method becomes optional. We can use this feature coupled with named parameters to define methods with an optional set of parameters.&lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;public static void &lt;br /&gt;   updateMyCV&lt;br /&gt;     (int employeeID, string firstName=”Dhanushka”, string lastName=”Athukorala”)&lt;br /&gt;     { do some task }&lt;br /&gt;&lt;br /&gt;When you are declaring a method with optional parameters, required parameters need to come first before any optional parameter declaration, here parameters with default values are considered as optional parameters while others are considered as required. There are several ways to call this method legally.&lt;br /&gt;&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;Cpp&quot;&gt;&lt;br /&gt;updateMyCV(155,”Tekla”,”Dilrukshi”);&lt;br /&gt;updateMyCV(155,”Tekla”);&lt;br /&gt;updateMyCV(155,lastName: “Dilrukshi”);&lt;br /&gt;updateMyCV(155);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But you cannot call the method in following ways although it makes sense to do so&lt;br /&gt;&lt;br /&gt;updateMyCV();     //required parameters need to be passed&lt;br /&gt;updateMyCV(155, ,”Dilrukshi”);     //cannot leave gaps between arguments&lt;br /&gt;updateMyCV(“Dilrukshi”,155);    &lt;br /&gt;//order has to be maintained if you are not using named arguments in the method call</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/7461707429479197098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/05/optional-arguments-in-c-40.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7461707429479197098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/7461707429479197098'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/05/optional-arguments-in-c-40.html' title='Optional arguments in C# 4.0'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-601713483425071050</id><published>2010-05-12T16:25:00.000+05:30</published><updated>2010-05-12T17:01:12.248+05:30</updated><title type='text'>Named arguments in C# 4.0</title><content type='html'>Let’s say that you wrote a method like this&lt;br /&gt;&lt;br /&gt;public static int getVolumeOfCylinder(int radius, int height)&lt;br /&gt;{&lt;br /&gt; return 22/7*radius*radius*height;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now we all know until now we have to know the order of the parameters to call this method correctly, right!&lt;br /&gt;Well not any more with C# 4.0 you can consider the parameter names as labels and call them without considering their declaration order in the following way&lt;br /&gt;&lt;br /&gt;getVolumeOfCylinder(height: 10, radius: 5);&lt;br /&gt;getVolumeOfCylinder(radius: 5, height: 10);&lt;br /&gt;&lt;br /&gt;And as you have imagined already, named arguments can follow a positional argument but a named argument can never be followed by a positional argument&lt;br /&gt;&lt;br /&gt;e.g&lt;br /&gt;getVolumeOfCylinder(5, height: 10);     //this will compile&lt;br /&gt;getVolumeOfCylinder(height:10, 5);     // this wont</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/601713483425071050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/05/named-arguments-in-c-40.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/601713483425071050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/601713483425071050'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/05/named-arguments-in-c-40.html' title='Named arguments in C# 4.0'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-1301308921295604476</id><published>2010-05-03T18:47:00.000+05:30</published><updated>2010-05-03T19:10:53.547+05:30</updated><title type='text'>CURSORS IN T_SQL</title><content type='html'>In programming languages such as c# and java we use data structures like arrays and lists to store a set of data in the memory so we can iterate through them and do some processing.&lt;br /&gt;when it comes to sql the alternative solution is the T-SQL CURSOR&lt;br /&gt;&lt;br /&gt;The basic steps of using a cursor are as follows&lt;br /&gt;1)Declare a cursor and associate it with a SELECT statement, the basic characteristics of the cursor needs to be defined here as well&lt;br /&gt;2)Open and populate the cursor&lt;br /&gt;3)Fetch a row from the cursor&lt;br /&gt;4)Process the fetched row inside the loop after checking the fetch status&lt;br /&gt;5)close and de-allocate the cursor&lt;br /&gt;&lt;br /&gt;lets write a simple cursor and demonstrate the above mentioned steps&lt;br /&gt;&lt;br /&gt;--Declare the variables needed, to do the necessary processing&lt;br /&gt;DECLARE @NAME VARCHAR(MAX)&lt;br /&gt;&lt;br /&gt;---(1)---&lt;br /&gt;DECLARE myCursor CURSOR FOR&lt;br /&gt;SELECT employee_name FROM EMPLOYEES&lt;br /&gt;&lt;br /&gt;* alternatively you can declare a local variable of type CURSOR and set its structure as well&lt;br /&gt;DECLARE @myCursor CURSOR&lt;br /&gt;SET @myCursor= CURSOR FOR SELECT employee_name FROM EMPLOYEES&lt;br /&gt;* you can also set the cursor for read only mode to gain more performance or to update mode to update the rows as you iterate through them&lt;br /&gt;DECLARE myCursor CURSOR READ_ONLY&lt;br /&gt;FOR SELECT employee_name FROM EMPLOYEES&lt;br /&gt;        OR&lt;br /&gt;DECLARE myCursor CURSOR&lt;br /&gt;FOR SELECT employee_name FROM EMPLOYEES&lt;br /&gt;FOR UPDATE OF designation&lt;br /&gt;&lt;br /&gt;---(2)---&lt;br /&gt;OPEN myCursor&lt;br /&gt;--(3)---&lt;br /&gt;FETCH NEXT FROM myCursor INTO @NAME&lt;br /&gt;---(4)---&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;PRINT @NAME&lt;br /&gt;FETCH NEXT FROM myCursor INTO @NAME&lt;br /&gt;END&lt;br /&gt;* here FETCH_STATUS is used to determine the boundary status of the iterator, following are values it returns depending on the situation&lt;br /&gt;    0 - fetch statement was executed successfully&lt;br /&gt;   -1 - row that needs to be fetched is beyond the result set&lt;br /&gt;   -2 - row that needs to be fetched is missing&lt;br /&gt;* FETCH_STATUS is defined globally for all the cursors on a connection, so when we are using it we need to be careful to check the status immediately after the fetch before another fetch occur.&lt;br /&gt;* you can get the number of rows in the cursors result set using the @@CURSOR_ROWS variable&lt;br /&gt;&lt;br /&gt;---(5)---&lt;br /&gt;CLOSE myCursor&lt;br /&gt;DEALLOCATE myCursor&lt;br /&gt;* after using the cursor we must close and de-allocate it so there wont be any references for the cursor in the memory</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/1301308921295604476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2010/05/cursors-in-tsql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1301308921295604476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/1301308921295604476'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2010/05/cursors-in-tsql.html' title='CURSORS IN T_SQL'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-6851257369879222210</id><published>2009-06-04T14:02:00.001+05:30</published><updated>2009-06-30T12:35:29.886+05:30</updated><title type='text'>Write to an XML file using C#</title><content type='html'>following code demonstrates how we can write a collection to an XML file using C#&lt;div&gt;we can do it in two ways first lets do it without using serilization.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;public static void writetoXML(string fileName)&lt;/div&gt;&lt;div&gt;        {            &lt;/div&gt;&lt;div&gt;            DataSet ds = new DataSet(&quot;ds01&quot;);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//root node&lt;/div&gt;&lt;div&gt;            DataTable t = new DataTable(&quot;table01&quot;);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//&lt;table01&gt;&lt;/div&gt;&lt;div&gt;            DataColumn qNo = new DataColumn(&quot;questionNo&quot;);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//&lt;questionno&gt;&lt;/div&gt;&lt;div&gt;            DataColumn ans = new DataColumn(&quot;answer&quot;);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//&lt;answer&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            t.Columns.Add(qNo);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//add columns to the table&lt;/div&gt;&lt;div&gt;            t.Columns.Add(ans);&lt;/div&gt;&lt;div&gt;            ds.Tables.Add(t);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//add table to the dataset&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            DataRow r;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;            int qLimit = 10;&lt;/div&gt;&lt;div&gt;            &lt;/div&gt;&lt;/div&gt;            for (int i = 0; i &lt;&gt;&lt;div&gt;            {&lt;/div&gt;&lt;div&gt;                r = t.NewRow();&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//create a new row of type table&lt;/div&gt;&lt;div&gt;                r[&quot;questionNo&quot;] = i;&lt;/div&gt;&lt;div&gt;                r[&quot;answer&quot;] = &quot;answer for question&quot; + i;&lt;/div&gt;&lt;div&gt;                t.Rows.Add(r);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;//add the newly populated row to the table&lt;/div&gt;&lt;div&gt;                &lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//write the added data to the console&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            Console.WriteLine(&quot;Data added to the table\n&quot;);&lt;/div&gt;&lt;div&gt;            Console.WriteLine(&quot;QuestionNo\t\tAnswer&quot;);&lt;/div&gt;&lt;div&gt;            Console.WriteLine(&quot;--------------------------------------------&quot;);&lt;/div&gt;&lt;div&gt;            for (int i = 0; i &lt;&gt;&lt;div&gt;            {&lt;/div&gt;&lt;div&gt;                Console.WriteLine(t.Rows[i][0].ToString()+&quot;\t\t|\t&quot;+t.Rows[i][1].ToString());&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            ds.WriteXml(fileName);       &lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;lets rewrite it again using serilization there is a big advantage in this i&#39;ll show it right away&lt;/div&gt;&lt;div&gt;when using serialization we write the data using a XMLSerializer object which will be created using the method typeof(). this allows us to write any type of collection to a XML file with little altering of code as possible&lt;/div&gt;&lt;div&gt;lets see how the above method will look like when written using serilization&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;public static void serializeDatSet(string fileName)&lt;/div&gt;&lt;div&gt;        {&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//create a new XMLSerializer object of type DataSet&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            XmlSerializer ser = new XmlSerializer(typeof(DataSet));&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            DataSet ds = new DataSet(&quot;ds01&quot;);&lt;/div&gt;&lt;div&gt;            DataTable t = new DataTable(&quot;table01&quot;);&lt;/div&gt;&lt;div&gt;            DataColumn qNo = new DataColumn(&quot;questionNo&quot;);&lt;/div&gt;&lt;div&gt;            DataColumn ans = new DataColumn(&quot;answer&quot;);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            t.Columns.Add(qNo);&lt;/div&gt;&lt;div&gt;            t.Columns.Add(ans);&lt;/div&gt;&lt;div&gt;            ds.Tables.Add(t);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            DataRow r;&lt;/div&gt;&lt;div&gt;            int qLimit = 10;&lt;/div&gt;&lt;div&gt;            &lt;/div&gt;&lt;div&gt;&lt;/div&gt;            for (int i = 0; i &lt;&gt;&lt;div&gt;            {&lt;/div&gt;&lt;div&gt;                r = t.NewRow();&lt;/div&gt;&lt;div&gt;                r[&quot;questionNo&quot;] = i;&lt;/div&gt;&lt;div&gt;                r[&quot;answer&quot;] = &quot;answer for question&quot; + i;&lt;/div&gt;&lt;div&gt;                t.Rows.Add(r);&lt;/div&gt;&lt;div&gt;                &lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            Console.WriteLine(&quot;Data added to the table\n&quot;);&lt;/div&gt;&lt;div&gt;            Console.WriteLine(&quot;QuestionNo\t\tAnswer&quot;);&lt;/div&gt;&lt;div&gt;            Console.WriteLine(&quot;--------------------------------------------&quot;);&lt;/div&gt;&lt;div&gt;            for (int i = 0; i &lt;&gt;&lt;div&gt;            {&lt;/div&gt;&lt;div&gt;                Console.WriteLine(t.Rows[i][0].ToString()+&quot;\t\t|\t&quot;+t.Rows[i][1].ToString());&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            &lt;/div&gt;&lt;div&gt;            TextWriter writer=new StreamWriter(fileName);&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;//write the data set to the writer stream using the serialization object&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            ser.Serialize(writer,ds);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            writer.Close();&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;so lets say you want to write an ArrayList to a XML file&lt;/div&gt;&lt;div&gt;well see the code below&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;public static void writeToXML(string fileName)&lt;/div&gt;&lt;div&gt;        {&lt;/div&gt;&lt;div&gt;            ArrayList arr = new ArrayList();&lt;/div&gt;&lt;div&gt;            for (int i = 0; i &lt;&gt;&lt;div&gt;            {&lt;/div&gt;&lt;div&gt;                arr.Add(&quot;answer for question&quot; + i);&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            &lt;/div&gt;&lt;div&gt;            XmlSerializer ser = new XmlSerializer(typeof(ArrayList));&lt;/div&gt;&lt;div&gt;            TextWriter writer = new StreamWriter(fileName);&lt;/div&gt;&lt;div&gt;            ser.Serialize(writer, arr);&lt;/div&gt;&lt;div&gt;            writer.Close();&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/6851257369879222210/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2009/06/write-to-xml-file-using-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/6851257369879222210'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/6851257369879222210'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2009/06/write-to-xml-file-using-c.html' title='Write to an XML file using C#'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-4668153187629266360</id><published>2009-05-28T11:58:00.000+05:30</published><updated>2009-05-28T15:41:59.524+05:30</updated><title type='text'>How to get the servers DateTime.Now Value to a client program</title><content type='html'>for this you have to write two applications, one will reside in the server machine and will wait till a client machine request its time. upon a succesful request the server will write its DateTime.Now value to the network stream, where the client can read it out and use it in his application&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;please consider that these two applications are windows console applications&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-decoration: underline;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: italic;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(0, 0, 153);&quot;&gt;Code for the Server Program&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(255, 0, 0); font-style: italic; font-weight: bold; text-decoration: underline;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Collections.Generic;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Text;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Net;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Net.Sockets;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;namespace Server&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    public class Program&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;        public static void Main(string[] args)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;        {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                //add a listner to liten on a port on a specified host&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                TcpListener listener=new TcpListener(Dns.Resolve(&quot;localhost&quot;).AddressList[0],14);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                listener.Start();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                Console.WriteLine(&quot;Waiting for client to connect&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                Console.WriteLine(&quot;Ctrl+C to quit&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                while (true)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    Socket s = listener.AcceptSocket();     //accept a connection request made by a client                                                                                              on the listning socket&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    DateTime now = DateTime.Now;            //get the servers date time value&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    string dateTime = now.ToShortDateString() + &quot; &quot; + now.ToLongTimeString();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    byte[] asciiDateTime = Encoding.ASCII.GetBytes(dateTime.ToCharArray()); &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;//encode the strring to aASCII byte stream to written in to the socket so it can be decoded from&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;the client easily&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    s.Send(asciiDateTime, asciiDateTime.Length, 0); &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;//write to the socket data(asciidatetime) starting from 0th index to a charcter count &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;of(asciidatetime.length)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    s.Close();      &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;//close the socket connection to the client&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    Console.WriteLine(&quot;Sent{0}&quot;,dateTime);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            catch (SocketException error)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                if (error.ErrorCode==10048)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                    Console.WriteLine(&quot;connection failed to this port, there is another server listning on this port&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;        }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-decoration: underline; -webkit-text-decorations-in-effect: underline; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: italic; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(0, 0, 153);&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;Code for the Client Program&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: italic; text-decoration: underline; &quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: italic; &quot;&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Collections.Generic;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Text;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Net;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.Net.Sockets;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;using System.IO;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;namespace ConsoleApplication2&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    class Program&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;        static void Main(string[] args)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            TcpClient client = new TcpClient();     //create a client&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            Console.WriteLine(&quot;specify a server name : &quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            string serverName = Console.ReadLine();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            try&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; //gets the DNS information of the specified server&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                IPHostEntry ipInfo = Dns.GetHostByName(serverName);    &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            catch (SocketException error)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                Console.WriteLine(&quot;cannot find server : &quot;+serverName+&quot;\nException :\n&quot;+error.ToString());&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                return;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            try&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                client.Connect(serverName,14);      //connect to the specified server via port 14&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            catch (Exception error2)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                Console.WriteLine(&quot;could not connect to server {0}\n&quot;+error2.Message,serverName);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            Stream s;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            try&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: italic; &quot;&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;//get a network stream to communicate with the server machine&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;this will add the client to the servers pending request query and will &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                s = client.GetStream(); initiate the AcceptSocket() method&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            catch (InvalidOperationException)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                Console.WriteLine(&quot;cannot connect to server {0}&quot;,serverName);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;                return;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            Byte[] read=new byte[32];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;//read the  the byte stream returned from the server&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            int bytes = s.Read(read, 0, read.Length);     &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            string time = Encoding.ASCII.GetString(read);   //decode it to a string&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            Console.WriteLine(&quot;received&quot;+bytes+&quot;bytes&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            Console.WriteLine(&quot;current server date time is : &quot;+time);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            client.Close();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            Console.WriteLine(&quot;press enter to exit&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;            Console.Read();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;this code base can be used to construct any simple-client server communication machanism based on your requirements. all you have to do is replace &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;DateTime now = DateTime.Now;            //get the servers date time value&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: normal; &quot;&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;        string dateTime = now.ToShortDateString() + &quot; &quot; + now.ToLongTimeString();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;part in the server program with ou server task&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;have fun coding!!!!!!&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/4668153187629266360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2009/05/how-to-get-servers-datetimenow-value-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4668153187629266360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4668153187629266360'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2009/05/how-to-get-servers-datetimenow-value-to.html' title='How to get the servers DateTime.Now Value to a client program'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1970206442337038620.post-4650789842171428887</id><published>2009-04-07T14:21:00.001+05:30</published><updated>2009-04-07T14:52:10.019+05:30</updated><title type='text'>What&#39;s new in c# 3.0 - Implicitly typed variables</title><content type='html'>&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(51, 204, 255);&quot;&gt;this is a first of a series about new features in c# 3.0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;all the programming languages have some kind of a machanism to store progrmatic data in c# there are two types called reference types and value types when we consider value types almost all the programming languages had implemented them as a part of their framework&lt;/div&gt;&lt;div&gt;Basically their are two types of value types &lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;static&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;dynamic&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(153, 153, 255);&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;static typing&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;type of the variables are known in cmpile time this is the common practice in languages like c#, java, c, c++&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;int a=10;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;string name=&quot;Dhanushka Sandaruwan Athukorala&quot;;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(153, 153, 255);&quot;&gt;dynamic typing&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;here the variable comes with some kind of a tag that contains it type. when you assign a value to the variable at the run time this tag value is set to the type of this assigned value&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the funny thing is every time an operation is performed the type will be checked to make sure that the operation is safe&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;for an example this will wok in dynamically typed code but not in static typing&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;a=&quot;Dhanushka Sandaruwan Athukorala&quot;;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;if(true)&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;a=12;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;b=a/2;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here as you can see when the devission occur a&#39;s type tag is set to int rather than string thats the magic of dynamic typing&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;now lets see what c# 3.0 offeres&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;var fullName=&quot;Dhanushka Sandaruwan Athukorala&quot;;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;var age=22;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;var arr=new[] {1, 2, 3, 4}&lt;br /&gt;&lt;/div&gt;&lt;div&gt;hmm...&lt;/div&gt;&lt;div&gt;what&#39;s going on&lt;/div&gt;&lt;div&gt;at first you would say that &quot;var&quot; is just a new value type!!!&lt;/div&gt;&lt;div&gt;No sir!!! its not!!!&lt;/div&gt;&lt;div&gt;its just a new keyword introduced in c# 3.0 to indicate to the compiler that &quot;i&#39;m gona create a new variable, but i dont know about its type. so you just take care of it for me!!&quot;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;we all know that c# is a staticstically typed language, but yet it si offering a functionallity similar to a dynamically typed one???&lt;/div&gt;&lt;div&gt;whats the secret??&lt;/div&gt;&lt;div&gt;what happens here is a newly written type inferencing algorithm is used by the &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: rgb(102, 255, 153);&quot;&gt;compiler&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;(take this to note, which means this happens at compile time not at run time) goes through the code and finds out what&#39;s the type of the variables assigned to the &quot;var&quot; variables. which means that this is similar to an explicit declaration of a variable but you dont have to know the type of it.&lt;/div&gt;&lt;div&gt;for an instance if we referfullName.GetType()  and age.GetType() values at run time they will give string and int32 as their variable types&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;but their are some other issues you should be aware of when you use var &lt;/div&gt;&lt;div&gt;you must  initialize a variable with a nonnull value when you declare it&lt;/div&gt;&lt;div&gt;this want compile&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;var a;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt;   &lt;/span&gt;var b=null;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space:pre&quot;&gt; &lt;/span&gt;a=18;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;as a conclusion we can say although this will distance c# from being a simple language, it will enhance the developer productivity as well as code readability. &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dhanushkaat.blogspot.com/feeds/4650789842171428887/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dhanushkaat.blogspot.com/2009/04/whats-new-in-c-30-implicitly-typed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4650789842171428887'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1970206442337038620/posts/default/4650789842171428887'/><link rel='alternate' type='text/html' href='http://dhanushkaat.blogspot.com/2009/04/whats-new-in-c-30-implicitly-typed.html' title='What&#39;s new in c# 3.0 - Implicitly typed variables'/><author><name>Dhanushka Athukorala</name><uri>http://www.blogger.com/profile/12563734202506606128</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglVY4uwUsvQyvKCBBf99UH1lmnJVceZVO_V5pXoKEzf6AyazWjWMSCbkpa9u3V0hhLaNZcv-cma8B2bJHTP5-MF93tlGAv8Dzm4QltOYhsyXRmEMcsktar884ewho5sg/s220/me.png'/></author><thr:total>0</thr:total></entry></feed>