<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/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>Two Notes About Anonymous Types</title><link>http://weblogs.asp.net/okloeten/archive/2007/04/12/2221833.aspx</link><description>The example of anonymous types from the C# 3.0 specification document is as follows: class __Anonymous1 { private T1 f1 ; private T2 f2 ; // … private Tn fn ; public T1 p1 { get { return f1 ; } set { f1 = value ; } } public T2 p2 { get { return f2 ; </description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: Two Notes About Anonymous Types</title><link>http://weblogs.asp.net/okloeten/archive/2007/04/12/2221833.aspx#6797806</link><pubDate>Fri, 19 Dec 2008 09:57:45 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6797806</guid><dc:creator>Hugh</dc:creator><author>Hugh</author><description>&lt;p&gt;I agree with some others here, it would be most helpful to be able to serialize an anonymous type, doing so if all &amp;#39;member&amp;#39; classes are so marked (as suggested by Matt above) is a very reasonable way of controlling this, or perhaps some compiler option, or even allow &amp;#39;public&amp;#39; as part of the types &amp;#39;var&amp;#39; declaration?&lt;/p&gt;
&lt;p&gt;In a system that allows arbitrary queries to be run on a server with results sent to a generic client for presentation (e.g. DataGridView) being able to serialize the anonymous query result type is essential.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6797806" width="1" height="1"&gt;</description></item><item><title>re: Two Notes About Anonymous Types</title><link>http://weblogs.asp.net/okloeten/archive/2007/04/12/2221833.aspx#6306650</link><pubDate>Sun, 22 Jun 2008 03:29:08 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6306650</guid><dc:creator>Matt Valerio</dc:creator><author>Matt Valerio</author><description>
&lt;p&gt;Good points.&lt;/p&gt;

&lt;p&gt;I&amp;#39;ve come to the conclusion that it might be useful to mark anonymous types as serializable.&lt;/p&gt;

&lt;p&gt;For example, I was recently trying to reduce the amount of plumbing needed to run a snippet of code in another AppDomain. &amp;nbsp;I turned to anonymous methods and generic classes, and ran into the issue that anonymous types are not marked as serializable and thus can&amp;#39;t cross the AppDomain boundaries. &amp;nbsp;Check out this post for some example code that fails.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://thevalerios.net/matt/2008/06/run-anonymous-methods-in-another-appdomain/" rel="nofollow" target="_new"&gt;http://thevalerios.net/matt/2008/06/run-anonymous-methods-in-another-appdomain/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, how about this:&lt;/p&gt;

&lt;p&gt;If any anonymous type is created where ALL of the member property types are marked as Serializable, then also mark the anonymous type’s class as Serializable.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6306650" width="1" height="1"&gt;</description></item><item><title>re: Two Notes About Anonymous Types</title><link>http://weblogs.asp.net/okloeten/archive/2007/04/12/2221833.aspx#6110403</link><pubDate>Fri, 18 Apr 2008 17:07:03 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6110403</guid><dc:creator>Sean</dc:creator><author>Sean</author><description>&lt;p&gt;I&amp;#39;m thinking future extensibility -- what if I could have an anonymous type that performed some anonymous behavior for each of it&amp;#39;s properties? perhaps an OnPropertyChanged() similar to rails... it would be somewhat breaking to change the fields to properties...??&lt;/p&gt;
&lt;p&gt;&amp;quot;As for binding - I don&amp;#39;t see why anyone would want to go through that nightmare.&amp;quot;&lt;/p&gt;
&lt;p&gt;But people still use untyped datasets *shrug*&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6110403" width="1" height="1"&gt;</description></item><item><title>re: Two Notes About Anonymous Types</title><link>http://weblogs.asp.net/okloeten/archive/2007/04/12/2221833.aspx#2248447</link><pubDate>Sun, 15 Apr 2007 15:57:34 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2248447</guid><dc:creator>Omer van Kloeten</dc:creator><author>Omer van Kloeten</author><description>&lt;p&gt;Alex / Leon - When a SerializableAttribute is placed on a type, all fields not marked as NotSerialized are used for the type's serialization. Properties are used for binding and maybe that's what threw you off.&lt;/p&gt;
&lt;p&gt;Serialization is only useful when you're persisting/reading an object grid to a stream. Since the original intention was for anonymous types to be contained in a single scope, there's no reason to ever serialize them.&lt;/p&gt;
&lt;p&gt;Since the type's name/structure isn't deterministic, you can't expect to be able to read it from a stream after having it written somewhere else with zero problems.&lt;/p&gt;
&lt;p&gt;As for binding - I don't see why anyone would want to go through that nightmare.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2248447" width="1" height="1"&gt;</description></item><item><title>re: Two Notes About Anonymous Types</title><link>http://weblogs.asp.net/okloeten/archive/2007/04/12/2221833.aspx#2246730</link><pubDate>Sun, 15 Apr 2007 12:12:12 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2246730</guid><dc:creator>lb</dc:creator><author>lb</author><description>&lt;p&gt;&amp;gt;Properties are used for serilization purposes I&lt;/p&gt;&lt;p&gt;&amp;gt;believe. Public fields are not serialized.&lt;/p&gt;&lt;p&gt;this is the glib answer i thought of too ;-)&lt;/p&gt;&lt;p&gt;any response? is serialization still useful with anonymous types? &lt;/p&gt;&lt;p&gt;are these types not likely to be persisted or transmitted (hence serialization is less important)? &lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2246730" width="1" height="1"&gt;</description></item><item><title>re: Two Notes About Anonymous Types</title><link>http://weblogs.asp.net/okloeten/archive/2007/04/12/2221833.aspx#2222331</link><pubDate>Thu, 12 Apr 2007 22:53:34 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:2222331</guid><dc:creator>Alex</dc:creator><author>Alex</author><description>&lt;p&gt;Properties are used for serilization purposes I believe. &amp;nbsp;Public fields are not serialized.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=2222331" width="1" height="1"&gt;</description></item></channel></rss>