<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>c#</title>
        <link>http://geekswithblogs.net/rajeshpillai/category/10980.aspx</link>
        <description>c#</description>
        <language>en-US</language>
        <copyright>Rajesh Pillai</copyright>
        <managingEditor>thinkrajesh@yahoo.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Reflection</title>
            <link>http://geekswithblogs.net/rajeshpillai/archive/2010/02/12/reflection.aspx</link>
            <description>&lt;p&gt;Reflection has always fascinated me.  Here a small reusable API to invoke methods dynamically.  This uses local caching for optimization and takes care of multithreading as well..&lt;/p&gt;
&lt;p&gt;You can use this class in a dll or a webservice.....    Pass this method the following parameters..&lt;/p&gt;
&lt;p&gt;1. dllPath : The path to the dll.&lt;/p&gt;
&lt;p&gt;2. className : The type to load dynamically&lt;/p&gt;
&lt;p&gt;3. methodName : The method to invoke&lt;/p&gt;
&lt;p&gt;4 pInput[] : The input parameters if any.&lt;/p&gt;
&lt;p&gt;private static Hashtable AssemblyHash = new Hashtable(1024);&lt;br /&gt;
private static Hashtable TypeHash = new Hashtable(10*1024);&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="" src="file:///C:/Users/RAJESH%7E2.PIL/AppData/Local/Temp/moz-screenshot.png" /&gt;&lt;img alt="" src="file:///C:/Users/RAJESH%7E2.PIL/AppData/Local/Temp/moz-screenshot-1.png" /&gt;&lt;img width="1084" height="752" src="/images/geekswithblogs_net/rajeshpillai/reflect_1.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Enjoy Programming...&lt;/p&gt; &lt;img src="http://geekswithblogs.net/rajeshpillai/aggbug/137935.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Rajesh Pillai</dc:creator>
            <guid>http://geekswithblogs.net/rajeshpillai/archive/2010/02/12/reflection.aspx</guid>
            <pubDate>Fri, 12 Feb 2010 12:13:16 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/rajeshpillai/comments/137935.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/rajeshpillai/archive/2010/02/12/reflection.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/rajeshpillai/comments/commentRss/137935.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/rajeshpillai/services/trackbacks/137935.aspx</trackback:ping>
        </item>
        <item>
            <title>Tech Tips: C# 3.0 Partial Methods</title>
            <link>http://geekswithblogs.net/rajeshpillai/archive/2009/11/28/tektippartial.aspx</link>
            <description>&lt;h1&gt;c# 3.0 : Partial Method&lt;/h1&gt;
&lt;p class="MsoNormal"&gt;You are all aware of “Partial Class” introduced in .net  2.0.    Partial class is useful in situation where you need to split the  definition of a class, &lt;br /&gt;
struct or an interface over two or more source files.   Each source file contains a section of the type or method  definition and all parts are &lt;br /&gt;
combined when the application is compiled. &lt;/p&gt;
&lt;p class="MsoNormal"&gt;There are several situations when splitting a class  definition is desirable:&lt;/p&gt;
&lt;p class="MsoNormal"&gt;When working  on large projects, spreading a class over separate files enables multiple  programmers to work on it at the same time.&lt;/p&gt;
&lt;p class="MsoListParagraph" style="text-indent: -0.25in;"&gt;&lt;span style="font-family: Symbol;"&gt;&lt;span&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;When working  with automatically generated source, code can be added to the class without  having to recreate the source file. Visual Studio &lt;br /&gt;
uses this approach when it  creates Windows Forms, Web service wrapper code, and so on. You can create code  that uses these classes without &lt;br /&gt;
having to modify the file created by Visual  Studio.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;u&gt;Partial Method (.net 3.0):&lt;br /&gt;
&lt;/u&gt;&lt;br /&gt;
 Partial methods are  the code block which reside inside a partial type and gets executed only when it  has definition. This gives us the extensibility &lt;br /&gt;
and if user wants to implement  the rule, they can go ahead and define the body but if they do not want it will  not. This improves the performance as &lt;br /&gt;
you are not loading/creating unwanted  methods. Partial methods are especially useful as a way to customize generated  code. They allow for a &lt;br /&gt;
method name and signature to be reserved, so that  generated code can call the method but the developer can decide whether to  implement the &lt;br /&gt;
method. Much like partial classes, partial methods enable code  created by a code generator and code created by a human developer to work  together &lt;br /&gt;
without run-time costs.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;A partial method declaration consists of two parts: the  definition, and the implementation. These may be in separate parts of a partial  class, or in the &lt;br /&gt;
same part. If there is no implementation declaration, then the  compiler optimizes away both the defining declaration and all calls to the  method.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;// Definition in file1.cs&lt;/p&gt;
&lt;p class="MsoNormal"&gt;partial void onNameChanged(); &lt;/p&gt;
&lt;p class="MsoNormal"&gt;// Implementation in file2.cs&lt;/p&gt;
&lt;p class="MsoNormal"&gt;partial void onNameChanged()&lt;br /&gt;
{&lt;br /&gt;
  // method body&lt;br /&gt;
}&lt;/p&gt;
&lt;ul type="disc"&gt;
    &lt;li class="MsoNormal"&gt;Partial method declarations must begin with the contextual  keyword &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/wbx7zzdd.aspx"&gt;partial&lt;/a&gt; and the method must return &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/yah0tteb.aspx"&gt;void&lt;/a&gt;.&lt;/li&gt;
    &lt;li class="MsoNormal"&gt;Partial methods can have &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/14akc2c7.aspx"&gt;ref&lt;/a&gt; but not &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/t3c3bfhx.aspx"&gt;out&lt;/a&gt; parameters.&lt;/li&gt;
    &lt;li class="MsoNormal"&gt;Partial methods are implicitly &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/st6sy9xe.aspx"&gt;private&lt;/a&gt;, and therefore they cannot be &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/9fkccyh4.aspx"&gt;virtual&lt;/a&gt;.&lt;/li&gt;
    &lt;li class="MsoNormal"&gt;Partial methods cannot be &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/e59b22c5.aspx"&gt;extern&lt;/a&gt;, because the presence of the body determines whether  they are defining or implementing.&lt;/li&gt;
    &lt;li class="MsoNormal"&gt;Partial methods can have &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/98f28cdx.aspx"&gt;static&lt;/a&gt; and &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/chfa2zb8.aspx"&gt;unsafe&lt;/a&gt; modifiers.&lt;/li&gt;
    &lt;li class="MsoNormal"&gt;Partial methods can be generic. Constraints are put on the  defining partial method declaration, and may optionally be repeated on the  implementing one. Parameter and type parameter names do not have to be the same  in the implementing declaration as in the defining one.&lt;/li&gt;
    &lt;li class="MsoNormal"&gt;You can make a &lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/900fyy8e.aspx"&gt;delegate&lt;/a&gt; to a partial method that has been defined and  implemented, but not to a partial method that has only been defined.&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="MsoNormal"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;span style="text-decoration: none;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;The above knowledge may seem  very miniscule but it opens up a whole new opportunity when you are designing  your system.  &lt;br /&gt;
For e.g.  Microsoft Entity Framework uses this feature for  notifying property changes.&lt;/span&gt;&lt;/u&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;span style="text-decoration: none;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;But beware there are caveats  to it.&lt;/span&gt;&lt;/u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;How can this knowledge be  applied?  Say for e.g. you have a class called “Address” which is declared as  follows&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;public &lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"&gt;partial&lt;/span&gt; class Address&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt; {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;      private string  city;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;      public string  City&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;      {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;             get { return  this.city;}&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;             set &lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;             {&lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;                     //  If this method is implemented then the actual code will be executed else  this will be ignored.&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;                      this.OnCityChanging(value);     //  This is partial method.  No exception will  be thrown if this method is not implemented.  &lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;                                                                &lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;                     this.city =  value;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;             }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;      }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;    &lt;br /&gt;
&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;    &lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"&gt;partial&lt;/span&gt; void OnCityChanging (string  city);&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;}&lt;/span&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;public &lt;b&gt;&lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"&gt;partial&lt;/span&gt;&lt;/b&gt; class Address&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;      &lt;b&gt;&lt;span style="background: yellow none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"&gt;partial&lt;/span&gt;&lt;/b&gt; void OnCityChanging(string  city)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;      {&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;                // You can add  business rules/validation or constraints here…&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;               If (city ==  “prohibited city”)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;                      throw new  InvalidArgumentException(“This city is not allowed”);&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;      }&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Create an instance of  Address…&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Address add = new  Address();&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(31, 73, 125);"&gt;add.City = “prohibited city”;    // exception will be thrown.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;This is just a rudimentary  example to wet up your appetite.&lt;/span&gt; &lt;span style="color: rgb(31, 73, 125);"&gt;Now, wear your “Thinking Hat”  and ponder over when you get some time &lt;br /&gt;
as to where this can be  applied.&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;u&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Reference:&lt;/span&gt;&lt;/u&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://msdn.microsoft.com/en-us/library/wa80x488.aspx"&gt;http://msdn.microsoft.com/en-us/library/wa80x488.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;&lt;a target="_blank" href="/exchweb/bin/redir.asp?URL=http://community.bartdesmet.net/blogs/bart/archive/2007/07/28/c-3-0-partial-methods-what-why-and-how.aspx"&gt;http://community.bartdesmet.net/blogs/bart/archive/2007/07/28/c-3-0-partial-methods-what-why-and-how.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/rajeshpillai/aggbug/136579.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Rajesh Pillai</dc:creator>
            <guid>http://geekswithblogs.net/rajeshpillai/archive/2009/11/28/tektippartial.aspx</guid>
            <pubDate>Sat, 28 Nov 2009 06:11:04 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/rajeshpillai/comments/136579.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/rajeshpillai/archive/2009/11/28/tektippartial.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/rajeshpillai/comments/commentRss/136579.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/rajeshpillai/services/trackbacks/136579.aspx</trackback:ping>
        </item>
    </channel>
</rss>
