<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx</link><description>Partial classes can be pretty cool because of the opportunities it gives in separating machine or designer generated code from user code. It does present a few issues, however. One that we've been talking about recently is a scenario where you have some</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66361</link><pubDate>Mon, 02 Feb 2004 23:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66361</guid><dc:creator>moo</dc:creator><description>Yes because we know designers generate good solid code. Take WinForms designer code and RESX files, theyre very very easy to refactor (not) and why we have a policy of NOT using the designer that generates RESX files in our projects. Its near impossible to refactor without redoing the form from scratch.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66380</link><pubDate>Mon, 02 Feb 2004 23:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66380</guid><dc:creator>Udi Dahan - The Software Simplist</dc:creator><description>Here's a possible solution:&lt;br&gt;&lt;br&gt;Use 2 files - one for the autogenerated designer stuff ( doesn't contain the constructor ) and the second for the user code ( which contains the constructor ).&lt;br&gt;&lt;br&gt;So, whenever creating a &amp;quot;partial&amp;quot; class, make 2 files right away. That way it'll compile the first time through without the user having to add anything. Later on, the autogenerated file keeps getting overwritten, while the &amp;quot;user file&amp;quot; doesn't.&lt;br&gt;&lt;br&gt;Quite a simplistic solution, but I think it covers the constructor problem alright.</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66410</link><pubDate>Tue, 03 Feb 2004 00:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66410</guid><dc:creator>Johnny Hall</dc:creator><description>Udi, in this scenario, what happens if the designer code has to alter the constructor code, after the user has changed it?</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66411</link><pubDate>Tue, 03 Feb 2004 00:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66411</guid><dc:creator>Johnny Hall</dc:creator><description>Udi, in this scenario, what happens if the designer code has to alter the constructor code, after the user has changed it?</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66422</link><pubDate>Tue, 03 Feb 2004 00:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66422</guid><dc:creator>Piers7</dc:creator><description>Don't we have this problem at with constructors at the moment anyway - just with base classes rather than partial ones?&lt;br&gt;&lt;br&gt;Seems to me that if you view the designer-generated partial class the same way you view a base class - ie the 'extending' (user) code runs after the 'base' (designer) code (designer constructor always calls stub method user init method) at least you know where you stand.&lt;br&gt;&lt;br&gt;After all, in a class designed for extension (whether partial or base), things firing off that might need actions taken prior to them fire some kind of virtual OnThing() method, right...</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66487</link><pubDate>Tue, 03 Feb 2004 05:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66487</guid><dc:creator>MartinJ</dc:creator><description>This could get ugly, fast.  I can see a recursive, or circular, situation getting introduced without some strict rules in place.&lt;br&gt;&lt;br&gt;You don't want any direct dependencies between the user and designer code.  But, you want the user to always be the one in the driver's seat.  So, I see the use of helper functions that the designer must honor.&lt;br&gt;&lt;br&gt;If the user creates a function named OnBeforeDesignerInitialization, the designer must add a call to that function immediately after any base class constructor is called.&lt;br&gt;&lt;br&gt;Basically, the brunt of the work falls on the designer to look through user code for key methods.  It then controls the actual constructor method implementation to accomodate what the user wants.&lt;br&gt;&lt;br&gt;You could also do this with attributes or compiler directives (kind of like the #pragma directive) so that the user has even more control of the actual method names.</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66561</link><pubDate>Tue, 03 Feb 2004 09:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66561</guid><dc:creator>moo</dc:creator><description>As if code cant be made bad enough, partial methods could end up being nasty if misused.  Gives a whole new meaning to obscfucation.&lt;br&gt;&lt;br&gt;Instead of adding all these fragmentation features, why not fix the designer in the first place, its schitzophrenic. .resx files don't refactor, the designer has a mind of its own.&lt;br&gt;&lt;br&gt;If one wants theyre code with good managability, I don't recomment the winform designer and I definately dont recommend the use of .resx files.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66565</link><pubDate>Tue, 03 Feb 2004 09:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66565</guid><dc:creator>moo</dc:creator><description>Will we see Inverse P/Invoke in later IDE builds as its supported in the framework specification as far as I know so I can make a native DLL from C#.&lt;br&gt;&lt;br&gt;Will we see static linking (.lib assemblies) of .net assemblies in future builds?  While today I can just do a &amp;quot;link to..&amp;quot; in the add existing... item for a project, sometimes I would like not to include the source on a project.&lt;br&gt;&lt;br&gt;While we have P/Invoke there but not Inverse P/Invoke, I dont understnad why this is left out on the IDE when its a supported feature.  Delphi .NET has it I belive in the IDE.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#66636</link><pubDate>Tue, 03 Feb 2004 14:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:66636</guid><dc:creator>John Morales</dc:creator><description>the more i hear about parital classes, the more i think they are useless...&lt;br&gt;&lt;br&gt;it'll just lead to crappy code: a file is a logical and useful container for code components, it's an elegant solution...  maybe it won't be THE solution in the future, but it is the main metaphor for our current coding techniques.</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#67399</link><pubDate>Wed, 04 Feb 2004 15:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67399</guid><dc:creator>Michael Giagnocavo</dc:creator><description>I hope designers let us make a choice if we want partial class code or base class code.  Partial classes are fine, but I fear that they'll be abused, and instead of being able to change SomeFunction(), we'll have to write ReallyThisIsSomeFunctionDontCallSomeFunction() if the designer functionality isn't what we want exposed.</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#67665</link><pubDate>Thu, 05 Feb 2004 00:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67665</guid><dc:creator>Jim Lyon</dc:creator><description>There's an easy quick hack to get partial constructors:&lt;br&gt;&lt;br&gt;In one of the files, add a member variable declaration like &amp;quot;int dummy = MyPartialInitialization();&amp;quot;&lt;br&gt;&lt;br&gt;The compiler will stock a call to MyPartialInitialization into the beginning of whatever constructors are eventually defined (and store the result into dummy).&lt;br&gt;</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#67934</link><pubDate>Thu, 05 Feb 2004 11:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67934</guid><dc:creator>Udi Dahan - The Software Simplist</dc:creator><description>The main use of partial classes as I see it is for code generation purposes.</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#67954</link><pubDate>Thu, 05 Feb 2004 12:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67954</guid><dc:creator>moo</dc:creator><description>Its a good thing to have partial types if its managed well but partial methods = BAD and I will never support this. It will be removed from all code I see this in and anybody adding partial methods will get a nice talking to.</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#67958</link><pubDate>Thu, 05 Feb 2004 12:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:67958</guid><dc:creator>moo</dc:creator><description>Unions in C#&lt;br&gt;&lt;br&gt;--&lt;br&gt;[StructLayout(LayoutKind.Explicit)]&lt;br&gt; public struct MyUnionWithCategories&lt;br&gt; {&lt;br&gt;  [FieldOffset(0)] public int Category;&lt;br&gt;  [FieldOffset(0)] public char CategoryRep;&lt;br&gt;  [FieldOffset(0)] public long CategoryIndicator;&lt;br&gt; }&lt;br&gt;--&lt;br&gt;&lt;br&gt;Instead of hacks like this, why cant we have a union type in C#?&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#68085</link><pubDate>Thu, 05 Feb 2004 17:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:68085</guid><dc:creator>Eric</dc:creator><description>Moo, if you have other questions, please put them in the &amp;quot;things Eric should blog about&amp;quot; thread on the main web page</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#69620</link><pubDate>Sun, 08 Feb 2004 14:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:69620</guid><dc:creator>Nick</dc:creator><description>Always funny to read about problems you wouldn't have if  you'd use a dynamic language like Python, Smalltalk, Ruby oder Lisp. If you need code generators it's very likely something is broken at a language level...</description></item><item><title>re: Partial classes and initialization</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#69634</link><pubDate>Sun, 08 Feb 2004 15:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:69634</guid><dc:creator>moo</dc:creator><description>Ive seen developers that cry because they cant use a designer and if the designer doesnt work they refuse to touch code. WTF. Fire them. Theyre useless.</description></item><item><title>Partial Success</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#164313</link><pubDate>Thu, 24 Jun 2004 07:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:164313</guid><dc:creator>K. Scott Allen's Blog</dc:creator><description /></item><item><title> Eric Gunnerson s C Compendium Partial classes and initialization | fix my credit</title><link>http://blogs.msdn.com/ericgu/archive/2004/02/02/66356.aspx#9764547</link><pubDate>Wed, 17 Jun 2009 05:08:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9764547</guid><dc:creator> Eric Gunnerson s C Compendium Partial classes and initialization | fix my credit</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://fixmycrediteasily.info/story.php?id=3825"&gt;http://fixmycrediteasily.info/story.php?id=3825&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>