<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bob on Medical Device Software &#187; Visual Studio</title>
	<atom:link href="http://rdn-consulting.com/blog/category/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://rdn-consulting.com/blog</link>
	<description>Software Development and Biomedical Engineering</description>
	<lastBuildDate>Wed, 28 Jul 2010 03:13:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<cloud domain='rdn-consulting.com' port='80' path='/blog/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Loading Individual Designer Default Values into Visual Studio .NET Settings</title>
		<link>http://rdn-consulting.com/blog/2008/07/23/loading-individual-designer-default-values-into-visual-studio-net-settings/</link>
		<comments>http://rdn-consulting.com/blog/2008/07/23/loading-individual-designer-default-values-into-visual-studio-net-settings/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 04:02:15 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://rdn-consulting.com/blog/2008/07/23/loading-individual-designer-default-values-into-visual-studio-net-settings/</guid>
		<description><![CDATA[The VS.NET Settings designer creates an ApplicationSettingsBase Settings class in Settings.Designer.cs (and optionally Settings.cs).  The default values from the designer are saved in app.config and are loaded into the Settings.Default singleton at runtime. So, now you have a button on a properties page that says &#8216;Reset to Factory Defaults&#8217; where you want to reload the [...]]]></description>
			<content:encoded><![CDATA[<p>The VS.NET <code>Settings</code> designer creates an <a href="http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase(VS.80).aspx" target="_blank"><code>ApplicationSettingsBase</code></a> <code>Settings</code> class in Settings.Designer.cs (and optionally Settings.cs).  The default values from the designer are saved in app.config and are loaded into the <code>Settings.Default</code> singleton at runtime.</p>
<p>So, now you have a button on a properties page that says &#8216;Reset to Factory Defaults&#8217; where you want to reload the designer default values back into your properties.  If you want do this for <em>all</em> property values you can just use <code>Settings.Default.Reset()</code>. <strong>But what if you only want to reset a subset of your properties? </strong></p>
<p>There may be a better way to do this, but I couldn&#8217;t find one.  The following code does the job and will hopefully save someone from having to reinvent this wheel.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Resets properties to their designer default settings</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> ResetToFactoryDefaults<span style="color: #000000;">&#40;</span>SettingsPropertyCollection collection<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Iterate through the settings and reset to their default values</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>SettingsProperty setting <span style="color: #0600FF;">in</span> collection<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">object</span> prop <span style="color: #008000;">=</span> Properties.<span style="color: #0000FF;">Settings</span>.<span style="color: #0600FF;">Default</span><span style="color: #000000;">&#91;</span>setting.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// The DefaultValue object is always a string but can be null.</span>
            <span style="color: #FF0000;">string</span> defvalue <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>setting.<span style="color: #0000FF;">DefaultValue</span> <span style="color: #008000;">??</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Set the property with its converted default value</span>
                Properties.<span style="color: #0000FF;">Settings</span>.<span style="color: #0600FF;">Default</span><span style="color: #000000;">&#91;</span>setting.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span>
                       TypeDescriptor.<span style="color: #0000FF;">GetConverter</span><span style="color: #000000;">&#40;</span>prop<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ConvertFromString</span><span style="color: #000000;">&#40;</span>defvalue<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>NotSupportedException ex<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// If the TypeConverter fails try to handle XML deserialization</span>
                <span style="color: #008080; font-style: italic;">// ourselves (e.g. StringCollection).</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>prop.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">IsSerializable</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    StringReader stringReader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringReader<span style="color: #000000;">&#40;</span>defvalue<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    XmlSerializer reader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span>prop.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">try</span>
                    <span style="color: #000000;">&#123;</span>
                        Properties.<span style="color: #0000FF;">Settings</span>.<span style="color: #0600FF;">Default</span><span style="color: #000000;">&#91;</span>setting.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span>
                                                     reader.<span style="color: #0000FF;">Deserialize</span><span style="color: #000000;">&#40;</span>stringReader<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>InvalidOperationException ex2<span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>
                            <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ResetToFactoryDefaults deserialization failed: &quot;</span> <span style="color: #008000;">+</span>
                            <span style="color: #666666;">&quot;setting={0} xml={1} {2}&quot;</span>,setting.<span style="color: #0000FF;">Name</span>, defvalue, ex2.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">else</span>
                <span style="color: #000000;">&#123;</span>
                    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>
                          <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ResetToFactoryDefaults: setting={0} {1}&quot;</span>,
                          setting.<span style="color: #0000FF;">Name</span>, ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
             <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008080; font-style: italic;">// Save the changes</span>
        Properties.<span style="color: #0000FF;">Settings</span>.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">Save</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The <code>ResetToFactoryDefaults</code> method takes a collection of <code>SettingsProperty</code>s and uses the DefaultValue string to reset the value. Most value types (string, int, bool, etc.) worked with the <code>TypeConverter</code>, but the <code>StringCollection </code>class is not supported so the XML string has to be deserialized manually.</p>
<p>These helper methods show how just selected (and all) properties can be reset.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Reset only the date and time format defaults.</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> SetDateTimeFormatDefaults<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    SettingsPropertyCollection col <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SettingsPropertyCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    col.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Properties.<span style="color: #0000FF;">Settings</span>.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;DateFormat&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    col.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Properties.<span style="color: #0000FF;">Settings</span>.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;TimeFormat&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    ResetToFactoryDefaults<span style="color: #000000;">&#40;</span>col<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Resets ALL properties to their designer default settings.</span>
<span style="color: #008080; font-style: italic;">// Same as Settings.Default.Reset()</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> ResetToFactoryDefaults<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    ResetToFactoryDefaults<span style="color: #000000;">&#40;</span>Properties.<span style="color: #0000FF;">Settings</span>.<span style="color: #0600FF;">Default</span>.<span style="color: #0000FF;">Properties</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This code was developed with VS 2005, but should also work in VS 2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://rdn-consulting.com/blog/2008/07/23/loading-individual-designer-default-values-into-visual-studio-net-settings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SolutionZipper Updated</title>
		<link>http://rdn-consulting.com/blog/2007/08/03/solutionzipper-updated/</link>
		<comments>http://rdn-consulting.com/blog/2007/08/03/solutionzipper-updated/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 17:29:33 +0000</pubDate>
		<dc:creator>Bob</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://rdn-consulting.com/blog/2007/08/03/solutionzipper-updated/</guid>
		<description><![CDATA[I&#8217;ve updated my SolutionZipper source and installer to version 1.3 on CodeProject. Here are the changes: Fixed a bug that was causing SZ to fail during the &#8220;Handle external projects&#8221; phase. Ignore VC++ Intellisense Database files, i.e. *.ncb. Ignore hidden files and folders. I originally wrote this last year as simply a convenience function. Even [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve updated my <a href="http://www.codeproject.com/csharp/SolutionZipper.asp">SolutionZipper</a> source and installer to version 1.3 on CodeProject. Here are the changes:</p>
<ul>
<li>Fixed a bug that was causing SZ to fail during the &#8220;Handle external projects&#8221; phase.</li>
<li>Ignore VC++ Intellisense Database files, i.e. *.ncb.</li>
<li>Ignore hidden files and folders.</li>
</ul>
<p>I originally wrote this last year as simply a convenience function. Even though I use a source code control system (Subversion) at work, I still need a quick way to snapshot and backup my personal projects at home.</p>
<p>I recently started a solution that included a C++ project and noticed some problems. First was that there was no need to backup the VC++ Intellisense database file. The second problem might be related to one of these:</p>
<ul>
<li>Microsoft Visual Studio 2005 Professional Edition &#8211; ENU Service Pack 1 (KB926601)</li>
<li>Visual Studio 2005 extensions for .NET Framework 3.0 (WCF &amp; WPF), November 2006 CTP</li>
<li>Microsoft ASP.NET 2.0 AJAX Extensions 1.0</li>
</ul>
<p>I don&#8217;t know which one caused the problem, but after one of these was installed VS2005 had project list items that were not file system based &#8212; a project called &lt;MiscFiles&gt;? Anyway, this caused the search for external projects to fail.</p>
<p>There was a request to ignore Subversion (.svn) directories. This was a good idea so I just ignore all hidden directories and files. This also means that VS Solution User Option files (.suo) are not included in the zip file.</p>
]]></content:encoded>
			<wfw:commentRss>http://rdn-consulting.com/blog/2007/08/03/solutionzipper-updated/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
