<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Saving server control properties to ViewState with custom attributes</title>
	<atom:link href="http://helephant.com/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/feed/" rel="self" type="application/rss+xml" />
	<link>http://helephant.com/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/</link>
	<description></description>
	<lastBuildDate>Thu, 24 Jun 2010 11:27:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
	<item>
		<title>By: Jeff G.</title>
		<link>http://helephant.com/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/#comment-2832</link>
		<dc:creator>Jeff G.</dc:creator>
		<pubDate>Tue, 17 Nov 2009 13:38:40 +0000</pubDate>
		<guid isPermaLink="false">http://helephant.net/?p=402#comment-2832</guid>
		<description>There&#039;s a more efficient way to do this in the recent version of C#:

public class PieControl1 : Control
{
    …
    public int Pies
    {
        get { return (int) (ViewState[&quot;Pies&quot;] ?? 0); }
        set { ViewState[&quot;Pies&quot;] = value; }
    }
}

The new ?? operator says, &quot;Use the value if it is not null, or else use the second operand if it is.&quot; So if ViewState[&quot;Pies&quot;] is null, a 0 will be returned. Otherwise, the value of ViewState[&quot;Pies&quot;] will be returned.</description>
		<content:encoded><![CDATA[<p>There&#8217;s a more efficient way to do this in the recent version of C#:</p>
<p>public class PieControl1 : Control<br />
{<br />
    …<br />
    public int Pies<br />
    {<br />
        get { return (int) (ViewState["Pies"] ?? 0); }<br />
        set { ViewState["Pies"] = value; }<br />
    }<br />
}</p>
<p>The new ?? operator says, &#8220;Use the value if it is not null, or else use the second operand if it is.&#8221; So if ViewState["Pies"] is null, a 0 will be returned. Otherwise, the value of ViewState["Pies"] will be returned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim West</title>
		<link>http://helephant.com/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/#comment-910</link>
		<dc:creator>Jim West</dc:creator>
		<pubDate>Tue, 28 Jul 2009 13:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://helephant.net/?p=402#comment-910</guid>
		<description>Nice work, I made a slight alteration to your LoadViewstate method to enable use of the default value attribute:

if (ViewState[property.Name] != null)
                        property.SetValue(this, ViewState[property.Name], null);
                    else
                    {
                        // Load the default value instead
                        attributes = property.GetCustomAttributes(typeof(DefaultValueAttribute), true);
                        if (attributes.Length &gt; 0)
                        {
                            DefaultValueAttribute dva = (DefaultValueAttribute)attributes[0];
                            property.SetValue(this, dva.Value, null);
                        }

                    }</description>
		<content:encoded><![CDATA[<p>Nice work, I made a slight alteration to your LoadViewstate method to enable use of the default value attribute:</p>
<p>if (ViewState[property.Name] != null)<br />
                        property.SetValue(this, ViewState[property.Name], null);<br />
                    else<br />
                    {<br />
                        // Load the default value instead<br />
                        attributes = property.GetCustomAttributes(typeof(DefaultValueAttribute), true);<br />
                        if (attributes.Length &gt; 0)<br />
                        {<br />
                            DefaultValueAttribute dva = (DefaultValueAttribute)attributes[0];<br />
                            property.SetValue(this, dva.Value, null);<br />
                        }</p>
<p>                    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: House</title>
		<link>http://helephant.com/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/#comment-908</link>
		<dc:creator>House</dc:creator>
		<pubDate>Wed, 03 Jun 2009 14:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://helephant.net/?p=402#comment-908</guid>
		<description>Really useful, thanks.</description>
		<content:encoded><![CDATA[<p>Really useful, thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ting Zwei Kuei</title>
		<link>http://helephant.com/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/#comment-907</link>
		<dc:creator>Ting Zwei Kuei</dc:creator>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://helephant.net/?p=402#comment-907</guid>
		<description>Good idea, wondered why Microsoft didn&#039;t implement this.</description>
		<content:encoded><![CDATA[<p>Good idea, wondered why Microsoft didn&#8217;t implement this.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
