tag:blogger.com,1999:blog-44128787367262150172024-03-07T06:59:45.614+02:00Mostly tech related...random ramblings about mostly tech stuff.../SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.comBlogger98125tag:blogger.com,1999:blog-4412878736726215017.post-42530970779668705492011-05-15T20:13:00.001+03:002011-05-15T20:13:46.380+03:00Expressionistic copying<p>Recently I had the need of cloning a number of object, traditionally you’d have to use reflection based techniques if you wanted a generic solution, (unless you go really hardcore with Reflection.Emit)</p> <p>The sample code below only accounts for public properties, but in many cases that isn’t enough.</p> <p>Given the performance implications of using reflection, and the fact that you are allowed to include blocks in expressions in .NET 4 I figured I’d do a small experiment and micro-benchmark comparing these two approaches:</p> <p>I have an entity I want to copy like so </p> <p> <pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">Entity<br /> </span>{<br /> <span style="color: blue">public int </span>Foo { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public string </span>Bar { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public string </span>Baz { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public int </span>Foo2 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public string </span>Bar2 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public string </span>Baz2 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public int </span>Foo3 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public string </span>Bar3 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> <span style="color: blue">public string </span>Baz3 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }<br /> }</pre><br />I implemented reflection based copy like so (with some room for optimizations):</p><br /><br /><pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">ReflectionObjectCopier </span>: <span style="color: #2b91af">IObjectCopier<br /> </span>{<br /> <span style="color: blue">#region </span>IObjectCopier Members<br /><br /> <span style="color: blue">public void </span>Copy<T>(T fromObj, T toObj)<br /> {<br /> <span style="color: blue">var </span>properties = <span style="color: blue">from </span>prop <span style="color: blue">in </span>fromObj.GetType().GetProperties(<span style="color: #2b91af">BindingFlags</span>.Public | <br /> <span style="color: #2b91af">BindingFlags</span>.Instance | <br /> <span style="color: #2b91af">BindingFlags</span>.FlattenHierarchy)<br /> <span style="color: blue">where </span>prop.CanRead && prop.CanWrite<br /> <span style="color: blue">select </span>prop;<br /> <span style="color: blue">foreach </span>(<span style="color: #2b91af">PropertyInfo </span>pi <span style="color: blue">in </span>properties)<br /> {<br /> pi.SetValue(toObj, pi.GetValue(fromObj, <span style="color: blue">null</span>), <span style="color: blue">null</span>);<br /> }<br /> }<br /><br /> <span style="color: blue">#endregion<br /> </span>}</pre><br /><br /><p>When using this copying 10 000 objects takes 250ms or so.</p><br /><br /><p>However, if I create an expression that performs the copying directly it only takes 10ms (with subsequent testruns only taking 4, when reusing the cached expression). That is a pretty decent saving if you ask me.</p><br /><br /><pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">ExpressionObjectCopier </span>: <span style="color: #2b91af">IObjectCopier<br /> </span>{<br /> <span style="color: #2b91af">Dictionary</span><<span style="color: #2b91af">Type</span>, <span style="color: blue">object</span>> cache = <span style="color: blue">new </span><span style="color: #2b91af">Dictionary</span><<span style="color: #2b91af">Type</span>, <span style="color: blue">object</span>>();<br /><br /> <span style="color: #2b91af">Action</span><T,T> CreateCopier<T>()<br /> {<br /> <span style="color: #2b91af">ParameterExpression </span>fromParam = <span style="color: #2b91af">Expression</span>.Parameter(<span style="color: blue">typeof</span>(T), <span style="color: #a31515">"from"</span>);<br /> <span style="color: #2b91af">ParameterExpression </span>toParam = <span style="color: #2b91af">Expression</span>.Parameter(<span style="color: blue">typeof</span>(T), <span style="color: #a31515">"to"</span>);<br /><br /> <span style="color: #2b91af">LambdaExpression </span>exp = <span style="color: #2b91af">Expression</span>.Lambda(<span style="color: blue">typeof</span>(<span style="color: #2b91af">Action</span><T, T>),<br /> <span style="color: #2b91af">Expression</span>.Block(<br /> <span style="color: blue">from </span>prop <span style="color: blue">in typeof</span>(T).GetProperties(<span style="color: #2b91af">BindingFlags</span>.Public | <br /> <span style="color: #2b91af">BindingFlags</span>.Instance | <br /> <span style="color: #2b91af">BindingFlags</span>.FlattenHierarchy)<br /> <span style="color: blue">where </span>prop.CanRead && prop.CanWrite<br /> <span style="color: blue">select </span><span style="color: #2b91af">Expression</span>.Assign(<span style="color: #2b91af">Expression</span>.Property(toParam, prop), <br /> <span style="color: #2b91af">Expression</span>.Property(fromParam, prop))<br /> ),<br /> fromParam,<br /> toParam);<br /><br /> <span style="color: #2b91af">Action</span><T, T> copier = (<span style="color: #2b91af">Action</span><T, T>)exp.Compile();<br /> cache[<span style="color: blue">typeof</span>(T)] = copier;<br /> <span style="color: blue">return </span>copier;<br /> }<br /><br /> <span style="color: blue">#region </span>IObjectCopier Members<br /><br /> <span style="color: blue">public void </span>Copy<T>(T fromObj, T toObj)<br /> {<br /> <span style="color: blue">object </span>action;<br /> <span style="color: #2b91af">Action</span><T,T> copier;<br /> <span style="color: blue">if </span>(!cache.TryGetValue(fromObj.GetType(), <span style="color: blue">out </span>action))<br /> {<br /> copier = CreateCopier<T>();<br /> }<br /> <span style="color: blue">else<br /> </span>{<br /> copier = (<span style="color: #2b91af">Action</span><T, T>)action;<br /> }<br /><br /><br /> copier(fromObj, toObj);<br /> }<br /><br /> <span style="color: blue">#endregion<br /> </span>}</pre><br /><br /><p>The above code obviously isn’t production quality…</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-21932473470176266162010-11-02T00:14:00.001+02:002010-11-02T00:14:54.454+02:00Timeline – or restyling controls<p>One nice thing with WPF that is slightly different is that the controls are lookless. This means that you can re-style or apply a different template altogether if the behavior of a standard control is what you want, but the looks are not.</p> <p>A real world example: At work we recently needed to show a list of items with associated timestamps, in a way so that the time differences between them are easily determined at a glance.</p> <p>Thanks to the lookless controls of WPF I was able to solve this simply by using a ListBox with re-templated ListBoxItems giving the following result:</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKDch9qPaOQGtpi2liOebe3o5n5pVsCLSnfC-wD9U5F_PjC8bsKvE2miA8CQd_e8RZhRD4NKRQTFByLKnTD3cozn27K82cRwBDwoku_rmj5vc37sS2DyjkSI5_g6yq8gNq-3xUwHnkDPw/s1600-h/image%5B5%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8g8C3rsu73vboHJ-R6yKNN0kyFaEPIfowlKWIV8DlYFtOyGPbbnNC7Phbu-Umv4Lqzx0hHY2TILGJeDBj8MNuA5NdTVik_BvJlq9nMCOCnvPOlUTu5heohJ5sq9prYcpPO36ppsDBH48/?imgmax=800" width="175" height="244" /></a></p> <p>The style is defined as follows:</p> <p>        <span style="color: blue"><</span><span style="color: #a31515">Style </span><span style="color: red">TargetType</span><span style="color: blue">="ListBoxItem" </span><span style="color: red">x</span><span style="color: blue">:</span><span style="color: red">Key</span><span style="color: blue">="TimelineStyle"> <br />            <</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">="SnapsToDevicePixels" </span><span style="color: red">Value</span><span style="color: blue">="true"/> <br />            <</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">="OverridesDefaultStyle" </span><span style="color: red">Value</span><span style="color: blue">="true"/> <br />            <</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">="FocusVisualStyle" </span><span style="color: red">Value</span><span style="color: blue">="{</span><span style="color: #a31515">x</span><span style="color: blue">:</span><span style="color: #a31515">Null</span><span style="color: blue">}"/> <br />            <</span><span style="color: #a31515">Setter </span><span style="color: red">Property</span><span style="color: blue">="Template"> <br />                <</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">> <br />                    <</span><span style="color: #a31515">ControlTemplate </span><span style="color: red">TargetType</span><span style="color: blue">="ListBoxItem"> <br />                        <</span><span style="color: #a31515">StackPanel </span><span style="color: red">Orientation</span><span style="color: blue">="Vertical"> <</span><span style="color: #a31515">Border <br />                            </span><span style="color: red">Name</span><span style="color: blue">="Border" <br />                            </span><span style="color: red">Padding</span><span style="color: blue">="2" <br />                            </span><span style="color: red">CornerRadius</span><span style="color: blue">="2" <br />                            </span><span style="color: red">BorderThickness</span><span style="color: blue">="2" <br />                            </span><span style="color: red">SnapsToDevicePixels</span><span style="color: blue">="true"> <br />                                <</span><span style="color: #a31515">ContentPresenter </span><span style="color: blue">/> <br />                            </</span><span style="color: #a31515">Border</span><span style="color: blue">> <br />                            <</span><span style="color: #a31515">Grid</span><span style="color: blue">> <br />                                <</span><span style="color: #a31515">Rectangle </span><span style="color: red">Width</span><span style="color: blue">="2" </span><span style="color: red">Stroke</span><span style="color: blue">="LightBlue" <br />                                           </span><span style="color: red">Height</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red">TimeToNext</span><span style="color: blue">, </span><span style="color: red">Converter</span><span style="color: blue">={</span><span style="color: #a31515">StaticResource </span><span style="color: red">HeightConverter</span><span style="color: blue">}}" <br />                                           </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Center" <br />                                           </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Center"/> <br />                                <</span><span style="color: #a31515">TextBlock </span><span style="color: red">Text</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red">TimeToNext</span><span style="color: blue">, </span><span style="color: red">Converter</span><span style="color: blue">={</span><span style="color: #a31515">StaticResource </span><span style="color: red">DurationConverter</span><span style="color: blue">}}" <br />                                           </span><span style="color: red">Background</span><span style="color: blue">="White" <br />                                           </span><span style="color: red">VerticalAlignment</span><span style="color: blue">="Center" <br />                                           </span><span style="color: red">HorizontalAlignment</span><span style="color: blue">="Center" <br />                                           </span><span style="color: red">FontSize</span><span style="color: blue">="8" <br />                                           </span><span style="color: red">Foreground</span><span style="color: blue">="Gray"/> <br />                            </</span><span style="color: #a31515">Grid</span><span style="color: blue">> <br />                        </</span><span style="color: #a31515">StackPanel</span><span style="color: blue">> <br />                        <</span><span style="color: #a31515">ControlTemplate.Triggers</span><span style="color: blue">> <br />                            <</span><span style="color: #a31515">Trigger </span><span style="color: red">Property</span><span style="color: blue">="IsSelected" <br />                                     </span><span style="color: red">Value</span><span style="color: blue">="true"> <br />                                <</span><span style="color: #a31515">Setter </span><span style="color: red">TargetName</span><span style="color: blue">="Border" <br />                                        </span><span style="color: red">Property</span><span style="color: blue">="BorderBrush" <br />                                        </span><span style="color: red">Value</span><span style="color: blue">="Blue"/> <br />                            </</span><span style="color: #a31515">Trigger</span><span style="color: blue">> <br />                        </</span><span style="color: #a31515">ControlTemplate.Triggers</span><span style="color: blue">> <br />                    </</span><span style="color: #a31515">ControlTemplate</span><span style="color: blue">> <br />                </</span><span style="color: #a31515">Setter.Value</span><span style="color: blue">> <br />            </</span><span style="color: #a31515">Setter</span><span style="color: blue">> <br />        </</span><span style="color: #a31515">Style</span><span style="color: blue">> <br /> <br /><font color="#000000">and and the listbox uses the style like this:</font></span></p> <pre class="code"><span style="color: blue"><</span><span style="color: #a31515">ListBox </span><span style="color: red">ItemsSource</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red">DataItems</span><span style="color: blue">}" </span><span style="color: red">ItemContainerStyle</span><span style="color: blue">="{</span><span style="color: #a31515">StaticResource </span><span style="color: red">TimelineStyle</span><span style="color: blue">}" /><br /></span></pre><br /><br /><br /><p>The style uses two converters, but those should be fairly trivial.</p><br /><br /><p>Setting FocusVisualStyle to {x:Null} is done to hide the indication of keyboard focus, as unless it is fixed properly, will be more confusing than helpful. Fixing it properly is left as an exercise for the reader.</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-28859352464808932172010-02-06T00:16:00.001+02:002010-02-06T00:16:32.760+02:00MCTS<p>Today I passed the second certification exam 70-502. So now I’m officially a Microsoft Certified Technology Specialist: .NET Framework 3.5, Windows Presentation Foundation Applications.</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-72798242046962818092010-02-01T18:59:00.001+02:002010-02-01T18:59:06.831+02:00Nullable<T> and IFormattable<p>If you ever tried to format a nullable type you would soon realize that you cannot directly as Nullable<T> does not implement IFormattable and thus you only have object.ToString() available.</p> <p>This is easily fixed using an extension method:</p> <pre class="code"><span style="color: blue">public static class </span><span style="color: #2b91af">NullableExtensions<br /> </span>{<br /> <span style="color: blue">public static string </span>ToString<T>(<br /> <span style="color: blue">this </span><span style="color: #2b91af">Nullable</span><T> nullable,<br /> <span style="color: blue">string </span>format,<br /> <span style="color: #2b91af">IFormatProvider </span>formatProvider)<br /> <span style="color: blue">where </span>T : <span style="color: blue">struct</span>, <span style="color: #2b91af">IFormattable<br /> </span>{<br /> <span style="color: blue">if </span>(!nullable.HasValue) <span style="color: blue">return string</span>.Empty;<br /> T notNull = nullable.Value;<br /> <span style="color: blue">return </span>notNull.ToString(format, formatProvider);<br /> }<br /> }</pre><br /><br /><p><a href="http://11011.net/software/vspaste"></a>and you can use it e.g. like so:</p><br /><br /><pre class="code"><span style="color: #2b91af"> DateTime</span>? foo = <span style="color: blue">null</span>;<br /> ...<br /> foo.ToString(<span style="color: #a31515">"t"</span>, <span style="color: #2b91af">CultureInfo</span>.CurrentCulture);</pre><br /><a href="http://11011.net/software/vspaste"></a> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-24780347964545230992010-01-21T22:06:00.001+02:002010-01-21T22:06:32.592+02:00WPF project building inside of Visual Studio but not with MSBuild/TFSBuild<p>At work, I recently run into a strange build error when building from MSBuild and TFSBuild while the same solution built inside of Visual Studio 2008 just fine.</p> <p>The error message was:</p> <p><strong>error MC3015: The attached property '?' is not defined on '?' or one of its base classes.</strong></p> <p>(obviously with real names instead of the questionmarks)</p> <p>Feeding the above into google provided the following solution to the issue:</p> <blockquote> <p>One of the differences between building in VS and command line is that a WPF build in VS defaults to </p> <p><AlwaysCompileMarkupFilesInSeparateDomain>true</AlwaysCompileMarkupFilesInSeparateDomain>. <br />Outside of VS, the default is false.</p> </blockquote> <p>(Answer by <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/00907c94-c6b2-4bf1-98f9-113c5c4392d8?prof=required&ppud=4">Rob Relyea</a>) </p> <p>Adding that to the relevant .csproj made the project build successfully.</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-1852905735333781332009-11-30T22:37:00.001+02:002009-11-30T22:39:31.372+02:00MeasureUp FAIL<p>I’m currently studying for the 70-536 on my way towards MCTS certification.</p> <p>I have the self-paced training kit and thought I’d do the Training Kit Exam Prep “Powered by MeasureUp”</p> <p>Things go without technical issues until I get to scoring.</p> <p>Then I am greeted with:</p> <p><font face="Courier">--------------------------- <br />Application Message <br />--------------------------- <br />An unanticipated error has occurred in the application.InsertScoreHistory </font></p> <p><font face="Courier">[Microsoft OLE DB Provider for ODBC Drivers] [3604] [Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression '#30.11.2009 21:51:40#'. <br />--------------------------- <br />OK   Cancel   <br />---------------------------</font></p> <p>Trying to review a particular answer fails with:</p> <p><font face="Courier">--------------------------- <br />Application Message <br />--------------------------- <br />An unanticipated error has occurred in the application.GoToQuestionSelected </font></p> <p><font face="Courier">[Microsoft.VisualBasic] [13] Conversion from string "7." to type 'Short' is not valid. <br />--------------------------- <br />OK   Cancel   <br />---------------------------</font></p> <p>I then eventually end up at the <a href="http://www.measureup.com/Site/display_article.aspx?AudienceID=&id=1175">FAQ page at MeasureUp</a> and find</p> <p>“<em><strong>I'm receiving Error: Mismatch 13.</strong> <br /></em><font color="#ff0000" size="4"><strong>In order for tests to display correctly, your computer's regional settings should be set to English (United States).</strong></font></p> <p><em>In the control panel, please double click on the icon labeled Regional Settings. Please choose English (United States), and click the box that says "use default properties for this input locale."</em></p> <p><em>Alternatively, in the regional settings, look at the Currency tab. If it is set the decimal symbol to . (dot) instead of , (coma), that may be enough to get it working properly.</em></p> <p><em>If the trouble persists, try setting the keyboard language layout to English (United States). In the control panel, double click on the icon labeled "Keyboard". Then click on the tab labeled input locales. Select the Add button. And then choose English (United States) as the input locale.</em>”</p> <p><strong>W T F !?!</strong></p> <p>It’s kinda ironic that one of the skills measured is “Implementing <strong>globalization</strong>, … in a .NET Framework application”</p> <p>What’s even more tragic is that if I actually DO change to en-us, trying to start a new test fails, this time with:</p> <p><font face="Courier">--------------------------- <br />Application Message <br />--------------------------- <br />An unanticipated error has occurred in the application.PreviousSessionTestRecord </font></p> <p><font face="Courier">[Microsoft.VisualBasic] [13] Conversion from string "30.11.2009 21:58:26" to type 'Date' is not valid. <br />--------------------------- <br />OK   Cancel   <br />---------------------------</font></p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com2tag:blogger.com,1999:blog-4412878736726215017.post-4165337364817475152009-11-10T23:01:00.001+02:002009-11-10T23:01:03.167+02:00roleProvider app.config parsing troubles<p>I recently had the pleasure of trying to get our RC out the door, while doing that we realized that for whatever reason, Microsoft seems to use a non-standard parser for the app.config file.</p> <p>Basically this does not work:</p> <p><span style="color: blue"><</span><span style="color: #a31515">system.web</span><span style="color: blue">> <br />  <</span><span style="color: #a31515">roleManager </span><span style="color: red">defaultProvider</span><span style="color: blue">=</span>"<span style="color: blue">MyCustomProvider</span>" <span style="color: red">enabled</span><span style="color: blue">=</span>"<span style="color: blue">true</span>"<span style="color: blue">> <br />    <</span><span style="color: #a31515">providers</span><span style="color: blue">> <br />      <</span><span style="color: #a31515">clear</span><span style="color: blue">></</span><span style="color: #a31515">clear</span><span style="color: blue">> <br />      <</span><span style="color: #a31515">add </span><span style="color: red">name</span><span style="color: blue">=</span>"<span style="color: blue">MyCustomProvider</span>" <span style="color: red">type</span><span style="color: blue">=</span>"<span style="color: blue">Namespace.MyCustomProvider, MyAssembly</span>"<span style="color: blue">/> <br />    </</span><span style="color: #a31515">providers</span><span style="color: blue">> <br />  </</span><span style="color: #a31515">roleManager</span><span style="color: blue">> <br /></</span><span style="color: #a31515">system.web</span><span style="color: blue">></span></p> <a href="http://11011.net/software/vspaste"></a> <p>While this does:</p> <p><span style="color: blue"><</span><span style="color: #a31515">system.web</span><span style="color: blue">> <br />  <</span><span style="color: #a31515">roleManager </span><span style="color: red">defaultProvider</span><span style="color: blue">=</span>"<span style="color: blue">MyCustomProvider</span>" <span style="color: red">enabled</span><span style="color: blue">=</span>"<span style="color: blue">true</span>"<span style="color: blue">> <br />    <</span><span style="color: #a31515">providers</span><span style="color: blue">> <br />      <</span><span style="color: #a31515">clear</span><span style="color: blue">/> <br />      <</span><span style="color: #a31515">add </span><span style="color: red">name</span><span style="color: blue">=</span>"<span style="color: blue">MyCustomProvider</span>" <span style="color: red">type</span><span style="color: blue">=</span>"<span style="color: blue">Namespace.MyCustomProvider, MyAssembly</span>"<span style="color: blue">/> <br />    </</span><span style="color: #a31515">providers</span><span style="color: blue">> <br />  </</span><span style="color: #a31515">roleManager</span><span style="color: blue">> <br /></</span><span style="color: #a31515">system.web</span><span style="color: blue">></span></p> <a href="http://11011.net/software/vspaste"></a> <p>Of course, the well known commercial installer making tool we are using insists of creating the former… :(</p> <p>A workaround is to throw the file through an identity XSLT transform in a custom tool / custom action run after custom actions from said vendor have done their job.</p> <p>Oh, the bug reported on connect is already closed as <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=508146">Won’t Fix</a></p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-71073411260115173112009-09-02T18:18:00.001+03:002009-09-02T18:18:42.878+03:00Windows Live Movie Maker - FAIL<p>As I wanted to edit some movies, and Windows 7 no longer includes Windows Movie Maker I had to give Windows Live Movie Maker a try, as based on the name you’d assume it does something similar?</p> <p>Turns out I was wrong. This application seems to be geared towards dropping a number of photos and creating a “movie” and not actually editing movies.</p> <p>While you can import video from a DV camera, it does not split the imported video into scenes, instead it chops it into pieces, the size of which you can determine by dragging a slider !?! And to make matters worse, it does not bother to extract thumbnails from the individual pieces but instead uses what seems to be the first frame of the entire movie. Good luck finding the pieces you need.</p> <p>Of course, the timeline also seemed unnecessary to include …</p> <p>Time to look for a Video editor, Windows Live Movie Maker is not one.</p> <p></rant></p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com1tag:blogger.com,1999:blog-4412878736726215017.post-43531068907258371212009-03-03T00:18:00.001+02:002009-03-03T00:18:07.279+02:00Generating GUIDs<p>This may seem trivial but here we go:</p> <p>I recently created an installer with WIX and obviously had to create a number of GUIDs along the way. While there is a "Create GUID" option in the Tools menu it has a number of drawbacks:</p> <ul> <li>Clicking around a UI with a mouse is not the most efficient thing in the world</li> <li>There is not an immediately suitable format available, registry format is closest, but braces need to be removed and the rest uppercased</li> </ul> <p>The obvious? solution to this problem is to create a macro like the following:</p> <pre class="code"><span style="color: blue">Public Sub </span>CreateWixGuid()<br /> <span style="color: blue">Dim </span>g <span style="color: blue">As </span>Guid = Guid.NewGuid()<br /> <span style="color: blue">Dim </span>textSelection <span style="color: blue">As </span>EnvDTE.TextSelection<br /><br /> textSelection = <span style="color: blue">CType</span>(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)<br /> textSelection.Text = g.ToString(<span style="color: #a31515">"D"</span>).ToUpper()<br /><span style="color: blue">End Sub</span></pre><br /><br /><p>and assign a keyboard shortcut to it (I chose Ctrl+G,Ctrl+G), and voilà a GUID in the correct format is generated and inserted.</p><br /><br /><p> </p><br /><br /><p><a href="http://11011.net/software/vspaste"> </a></p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com1tag:blogger.com,1999:blog-4412878736726215017.post-51145107991368924822008-11-11T22:04:00.001+02:002008-11-11T22:04:01.229+02:00How to not do validation<p>Yesterday when I was trying to do some online shopping I the e-commerce system in use perfomed input validation in a slightly suboptimal way. Here is what happened:</p> <ul> <li>To be able check out the stuff in my shopping basket I had to create an account.</li> <li>To create an account I had to enter username, password and address.</li> <li>Go to checkout</li> <li>Confirm to use the just entered address as the shipping address</li> <li>On the following page where the pay button should be there's this small note "The city is not long enough"  WTF!?!</li> <li>Try again with the city name in the other language as it is longer</li> <li>Same story "The city is not long enough" ...</li> <li>Only when changing the primary address the order goes through</li> </ul> <p>A validation rule stating that the city cannot be just three letters are just plain stupid, secondly <strong>if</strong> there is a need to use stupid validation rules, then do the validation when the data is <strong>entered</strong> and not when it is used ...</p> <p>This <a href="http://www.makeuseof.com/tech-fun/sorry-your-password-is-not-long-enough-pic/" target="_blank">comic</a> comes to mind.</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-55455675169605125682008-11-08T00:21:00.001+02:002008-11-08T00:21:25.591+02:00Debugging WPF databinding issues<p>Lately due to switching teams and project I've been doing much more WPF than before. I cannot say I have fully mastered the learning curve yet but I'm getting better and it is an interesting journey.</p> <p>Occasionally the data bindings does not work as expected and then it is nice to get more information about them in order to figure out what went wrong.</p> <p>The following is useful when you want to know why a particular binding is misbehaving (or rather you want to know where you screwed up...)</p> <pre class="code"><span style="color: red">xmlns</span><span style="color: blue">:</span><span style="color: red">diagnostics</span><span style="color: blue">="clr-namespace:System.Diagnostics;assembly=WindowsBase"</span></pre><br /><a href="http://11011.net/software/vspaste"></a><br /><br /><pre class="code"><span style="color: red">ItemsSource</span><span style="color: blue">="{</span><span style="color: #a31515">Binding </span><span style="color: red"><snip></span><span style="color: blue">, </span><span style="color: red">diagnostics</span><span style="color: blue">:</span><span style="color: red">PresentationTraceSources</span><span style="color: blue">.TraceLevel=High}"</span></pre><br /><br /><p>The above information and MUCH more is presented by <a href="http://www.beacosta.com/blog/?p=52" target="_blank">Beatriz Stollnitz</a></p><br /><br /><p>(This post is also a 'reminder to self')</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-7242739153692481982008-11-03T19:20:00.001+02:002008-11-03T19:20:37.876+02:00C# quiz 9/?<p>Consider the following:</p> <pre class="code"><span style="color: #2b91af">Guid </span>globallyUnique1 = <span style="color: blue">new </span><span style="color: #2b91af">Guid</span>();<br /><span style="color: #2b91af">Guid </span>globallyUnique2 = <span style="color: blue">new </span><span style="color: #2b91af">Guid</span>();<br /><span style="color: blue">if </span>(globallyUnique1 == globallyUnique2)<br />{<br /> <span style="color: #2b91af">MessageBox</span>.Show(<span style="color: #a31515">"This cannot be"</span>);<br />}<br /><span style="color: blue">else<br /></span>{<br /> <span style="color: #2b91af">MessageBox</span>.Show(<span style="color: #a31515">"Everything is well"</span>);<br />}</pre><br />What is shown? Why?<a href="http://11011.net/software/vspaste"></a> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com1tag:blogger.com,1999:blog-4412878736726215017.post-8487792295778652112008-10-15T00:23:00.001+03:002008-10-15T00:23:45.625+03:00Sandcastle to dead tree format woes<p>For reasons partially unknown to me, I was tasked with converting Sandcastle generated API documentation to dead tree format.</p> <p>The best way seems to be feeding some magic XSLT to Sandcastle that would that would directly create PDF via XSL-FO or DocBook or whatever. However, I haven't been able to find such a thing and I'm not ready to put down that kind of work to create it myself at this point.</p> <p>Another option I pursued was to print the CHM to XPS/PDF but this has its own cons. Firstly directly printing from CHM viewer strips CSS rendering ugliness. This is correctable by finding the correct html file from %TEMP% and a little search/replace magic and providing the stylesheets and images.</p> <p>Having gotten this far I found out that the stylesheet needs to use something else but relative font size to keep the text legible.</p> <p>Now as if this wasn't enough the browser or at least the PDF/XPS "printer" chokes on the sheer amount of input, still not finished after N hours, and this just for the documentation of a smallish test assembly. :(</p> <p>This does not look feasible at this point.</p> <p>Bright ideas appreciated!</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-2092632812679956072008-04-03T22:48:00.001+03:002008-04-03T22:48:21.778+03:00C# quiz 8/?<p>Now it's time for some one regarding serialization:</p> <p>Given this serializable class:</p><pre class="code"> [<span style="color: rgb(43,145,175)">Serializable</span>]<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">class</span> <span style="color: rgb(43,145,175)">Victim</span> {<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">static</span> <span style="color: rgb(0,0,255)">int</span> InstanceCount;<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">int</span> Data { <span style="color: rgb(0,0,255)">get</span>; <span style="color: rgb(0,0,255)">set</span>; }<br /><br /> <span style="color: rgb(0,0,255)">public</span> Victim() {<br /> InstanceCount++;<br /> Data = 2;<br /> }<br /> }<br /></pre><br /><p>and the following test code:</p><pre class="code"> <span style="color: rgb(0,0,255)">class</span> <span style="color: rgb(43,145,175)">Program</span> {<br /> <span style="color: rgb(0,0,255)">static</span> <span style="color: rgb(0,0,255)">void</span> Main(<span style="color: rgb(0,0,255)">string</span>[] args) {<br /> <span style="color: rgb(43,145,175)">Victim</span> v = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">Victim</span>();<br /> v.Data = 3;<br /> <span style="color: rgb(43,145,175)">BinaryFormatter</span> serial = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">BinaryFormatter</span>();<br /> <span style="color: rgb(43,145,175)">MemoryStream</span> ms = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">MemoryStream</span>();<br /> serial.Serialize(ms, v); <br /> ms.Seek(0, <span style="color: rgb(43,145,175)">SeekOrigin</span>.Begin);<br /> v = (<span style="color: rgb(43,145,175)">Victim</span>)serial.Deserialize(ms);<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"Data {0}"</span>, v.Data);<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"Instances {0}"</span>, <span style="color: rgb(43,145,175)">Victim</span>.InstanceCount);<br /> }<br /> }<br /></pre><br /><p>What is the output, and why?</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-9583717236863403772008-04-03T21:25:00.001+03:002008-04-03T21:25:49.668+03:00C# quiz 7/?<p>If we compile the following code to a dll, for example using the following command line:</p> <p>csc.exe /t:library Library.cs</p><pre class="code"><span style="color: rgb(0,0,255)">namespace</span> Library {<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">class</span> <span style="color: rgb(43,145,175)">Library</span> {<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">const</span> <span style="color: rgb(0,0,255)">int</span> FOO = 1;<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">static</span> <span style="color: rgb(0,0,255)">readonly</span> <span style="color: rgb(0,0,255)">int</span> BAR = 2;<br /> }<br />}<br /></pre><br /><p>And refer those in our test program:</p><pre class="code"> <span style="color: rgb(0,0,255)">class</span> <span style="color: rgb(43,145,175)">Program</span> {<br /> <span style="color: rgb(0,0,255)">static</span> <span style="color: rgb(0,0,255)">void</span> Main(<span style="color: rgb(0,0,255)">string</span>[] args) {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(Library.<span style="color: rgb(43,145,175)">Library</span>.FOO);<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(Library.<span style="color: rgb(43,145,175)">Library</span>.BAR);<br /> }<br /> }<br /></pre><br /><p>Now, if we change FOO to 10 and BAR to 12 and recompile Library.dll <strong>without</strong> recompiling the test program, what is the output when we run the test program?</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-55214232176796968642008-04-03T19:53:00.001+03:002008-04-03T19:53:55.813+03:00C# quiz: 6/?<p>Consider the following:</p><pre class="code"> <span style="color: rgb(0,0,255)">class</span> <span style="color: rgb(43,145,175)">Test</span> {<br /> <span style="color: rgb(0,0,255)">private</span> <span style="color: rgb(0,0,255)">int</span> m_foo;<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">int</span> Foo {<br /> <span style="color: rgb(0,0,255)">get</span> { <span style="color: rgb(0,0,255)">return</span> m_foo; }<br /> }<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">int</span> set_Foo(<span style="color: rgb(0,0,255)">int</span> value) {<br /> m_foo = value;<br /> }<br /> }<br /></pre><br /><p>What happens when you compile, and why?</p><br /><p><a href="http://11011.net/software/vspaste"></a></p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com2tag:blogger.com,1999:blog-4412878736726215017.post-17185245910614484122008-04-02T22:10:00.001+03:002008-04-02T22:10:18.143+03:00C# quiz: 5/?<p>Consider a console application with the following Main:</p><pre class="code"><span style="color: rgb(0,0,255)"> static</span> <span style="color: rgb(0,0,255)">void</span> Main(<span style="color: rgb(0,0,255)">string</span>[] args) {<br /> System.Threading.<span style="color: rgb(43,145,175)">Timer</span> t = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">Timer</span>(dummy =><br /> {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"In callback: "</span> + <span style="color: rgb(43,145,175)">DateTime</span>.Now);<br /> <span style="color: rgb(43,145,175)">GC</span>.Collect();<br /><br /> }, <span style="color: rgb(0,0,255)">null</span>, 0, 1000);<br /><br /> <span style="color: rgb(43,145,175)">Console</span>.ReadLine();<br /> t = <span style="color: rgb(0,0,255)">null</span>;<br /> }</pre><br /><p>What does the code do? Does it matter if it is compiled Debug or Release, if so, why?</p><br /><p>(To give proper credit where credit is due, this example is heavily inspired by CLR via C# by Jeffrey Richter)</p><br /><p><a href="http://11011.net/software/vspaste"></a></p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com1tag:blogger.com,1999:blog-4412878736726215017.post-43123034219460796052008-04-02T18:11:00.000+03:002008-04-01T18:12:56.985+03:00C# quiz: 4/?<p>Given the following code:</p><pre class="code"> <span style="color: rgb(0,0,255)">internal</span> <span style="color: rgb(0,0,255)">class</span> <span style="color: rgb(43,145,175)">Test</span> {<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">int</span> Foo { <span style="color: rgb(0,0,255)">get</span>; <span style="color: rgb(0,0,255)">set</span>; }<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">int</span> Bar { <span style="color: rgb(0,0,255)">get</span>; <span style="color: rgb(0,0,255)">set</span>; }<br /><br /><span style="color: rgb(0,0,255)">#if</span> CUSTOM<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">override</span> <span style="color: rgb(0,0,255)">int</span> GetHashCode() {<br /> <span style="color: rgb(0,0,255)">return</span> Foo.GetHashCode() ^ Bar.GetHashCode();<br /> }<br /><br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">override</span> <span style="color: rgb(0,0,255)">bool</span> Equals(<span style="color: rgb(0,0,255)">object</span> obj) {<br /> <span style="color: rgb(0,0,255)">if</span> (<span style="color: rgb(0,0,255)">object</span>.ReferenceEquals(obj, <span style="color: rgb(0,0,255)">null</span>)) <span style="color: rgb(0,0,255)">return</span> <span style="color: rgb(0,0,255)">false</span>;<br /> <span style="color: rgb(43,145,175)">Test</span> t = obj <span style="color: rgb(0,0,255)">as</span> <span style="color: rgb(43,145,175)">Test</span>;<br /> <span style="color: rgb(0,0,255)">if</span> (t != <span style="color: rgb(0,0,255)">default</span>(<span style="color: rgb(43,145,175)">Test</span>)) {<br /> <span style="color: rgb(0,0,255)">return</span> (Foo == t.Foo) && (Bar == t.Bar);<br /> }<br /> <span style="color: rgb(0,0,255)">return</span> <span style="color: rgb(0,0,255)">false</span>;<br /> }<br /><span style="color: rgb(0,0,255)">#endif<br /></span> }<br /></pre><a href="http://11011.net/software/vspaste"></a><br /><p>and the following test code:</p><pre class="code"> <span style="color: rgb(43,145,175)">Dictionary</span><<span style="color: rgb(43,145,175)">Test</span>, <span style="color: rgb(0,0,255)">string</span>> dict = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">Dictionary</span><<span style="color: rgb(43,145,175)">Test</span>, <span style="color: rgb(0,0,255)">string</span>>();<br /> <span style="color: rgb(43,145,175)">Test</span> foo = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">Test</span> { Foo = 1, Bar = 2 };<br /> dict[foo] = <span style="color: rgb(163,21,21)">"Hello World"</span>;<br /> foo.Bar = 42;<br /> <span style="color: rgb(0,0,255)">if</span> (dict.ContainsKey(foo)) {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"it's there"</span>);<br /> } <span style="color: rgb(0,0,255)">else</span> {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"it's not"</span>);<br /> }<br /></pre><br /><p>Answer the following questions:</p><br /><ol><br /><li>With CUSTOM not defined, what does the test code print?</li><br /><li>If CUSTOM is defined, does it change the outcome?</li><br /><li>What if Test is changed to a <strong>struct</strong> and CUSTOM is not defined, what is the output?</li><br /><li>If Test is a struct and CUSTOM is defined, what happens?</li></ol> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-3688248573291517602008-04-01T17:53:00.001+03:002008-04-01T17:53:44.574+03:00C# quiz: 3/?<p>Consider the following class:</p><pre class="code"> <span style="color: rgb(0,0,255)">internal</span> <span style="color: rgb(0,0,255)">class</span> <span style="color: rgb(43,145,175)">Test</span> {<br /><br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">int</span> Code { <span style="color: rgb(0,0,255)">get</span>; <span style="color: rgb(0,0,255)">set</span>; }<br /><br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">static</span> <span style="color: rgb(0,0,255)">bool</span> <span style="color: rgb(0,0,255)">operator</span> ==(<span style="color: rgb(43,145,175)">Test</span> lhs, <span style="color: rgb(43,145,175)">Test</span> rhs) {<br /> <span style="color: rgb(0,0,255)">if</span> (<span style="color: rgb(0,0,255)">object</span>.ReferenceEquals(lhs, rhs)) <span style="color: rgb(0,0,255)">return</span> <span style="color: rgb(0,0,255)">true</span>;<br /> <span style="color: rgb(0,0,255)">if</span> (lhs == <span style="color: rgb(0,0,255)">null</span> || rhs == <span style="color: rgb(0,0,255)">null</span>) {<br /> <span style="color: rgb(0,0,255)">return</span> <span style="color: rgb(0,0,255)">false</span>;<br /> } <span style="color: rgb(0,0,255)">else</span> {<br /> <span style="color: rgb(0,0,255)">return</span> lhs.Code == rhs.Code;<br /> }<br /> }<br /><br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">static</span> <span style="color: rgb(0,0,255)">bool</span> <span style="color: rgb(0,0,255)">operator</span> != (<span style="color: rgb(43,145,175)">Test</span> lhs, <span style="color: rgb(43,145,175)">Test</span> rhs) {<br /> <span style="color: rgb(0,0,255)">return</span> !(lhs == rhs);<br /> }<br /> }<br /></pre><a href="http://11011.net/software/vspaste"><a href="http://11011.net/software/vspaste"></a><br /><p>What is the outcome of the following test code, and why?</p><pre class="code"> <span style="color: rgb(43,145,175)">Test</span> test1 = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">Test</span> { Code = 42 };<br /> <span style="color: rgb(43,145,175)">Test</span> test2 = <span style="color: rgb(0,0,255)">new</span> <span style="color: rgb(43,145,175)">Test</span> { Code = 42 };<br /> <span style="color: rgb(0,0,255)">if</span> (test1 != test2) {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"different"</span>);<br /> } <span style="color: rgb(0,0,255)">else</span> {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"equals"</span>);<br /> }<br /></pre><a href="http://11011.net/software/vspaste"></a> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com2tag:blogger.com,1999:blog-4412878736726215017.post-70767277160934453622008-03-31T20:15:00.005+03:002008-04-01T12:32:17.280+03:00C# quiz: 2/?<p>Continuing on the series of C# and/or .NET Framework short questions:</p><pre class="code"> <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> Foo(<span style="color: rgb(43, 145, 175);">List</span><<span style="color: rgb(0, 0, 255);">int</span>> bar) {<br /> bar = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">List</span><<span style="color: rgb(0, 0, 255);">int</span>>();<br /> <span style="color: rgb(0, 128, 0);">// ...<br /></span> }</pre><a href="http://11011.net/software/vspaste"></a><br /><p>With the method above and the code below:</p><pre class="code"><span style="color: rgb(43, 145, 175);"> List</span><<span style="color: rgb(0, 0, 255);">int</span>> bar = <span style="color: rgb(0, 0, 255);">null</span>;<br /> Foo(bar);<br /> <span style="color: rgb(0, 0, 255);">if</span> (bar != <span style="color: rgb(0, 0, 255);">null</span>) {<br /> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"populated"</span>);<br /> } <span style="color: rgb(0, 0, 255);">else</span> {<br /> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"still null"</span>);<br /> }</pre>If or else ?<br /><br />EDIT: fixed typo in code sample./SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com2tag:blogger.com,1999:blog-4412878736726215017.post-90729038986364309202008-03-31T20:15:00.003+03:002008-03-31T20:15:53.408+03:00C# quiz: 1/?<p>I'm starting a series with small questions C# and/or .NET Framework related questions:</p> <p>First out, NaN values:</p><pre class="code"> <span style="color: rgb(0,0,255)">double</span> foo = <span style="color: rgb(0,0,255)">double</span>.NaN;<br /> <span style="color: rgb(0,128,0)">// ...<br /></span> <span style="color: rgb(0,0,255)">if</span> (foo == <span style="color: rgb(0,0,255)">double</span>.NaN) {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"NaN"</span>);<br /> } <span style="color: rgb(0,0,255)">else</span> {<br /> <span style="color: rgb(43,145,175)">Console</span>.WriteLine(<span style="color: rgb(163,21,21)">"a number"</span>);<br /> }<br /></pre><br /><p>If or else ?</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com3tag:blogger.com,1999:blog-4412878736726215017.post-26349974997855217482008-03-19T19:52:00.001+02:002008-03-19T19:52:01.345+02:00Safari - first impressions<p>I thought that I might give it a shot after all so I installed it. First impressions:</p> <p>- it's a memory hog! 4 sites in 4 tabs consumes a whopping 210MB, while Firefox 3 beta 4 for the same sites consumes "only" 74MB</p> <p>- the UI is ugly</p> <p>- scroll wheel doesn't work properly in bookmarks</p> <p>- close tab X button on the left !?! </p> <p>- As I don't have mouse gestures, I often right-click and choose back. If I happen to have the cursor over a word, (quite likely), safari chooses to select the word and only select search with google or copy. WTF?</p> <p>...my default browser isn't changing.</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-11364389209136789892008-03-18T22:13:00.001+02:002008-03-18T22:13:24.136+02:00Safari for Windows - Apple spamming users<p>I have an ipod, and therefore I have ITunes installed. Today Apple Software Update popped up and greeted me with the following totally unrelated thing: Safari 3.1 (22.65Mb)</p> <blockquote> <p><em>Safari for Windows is the fastest and easiest-to-use web browser for the PC. It displays web pages faster than any other browser and is filled with innovative features -- all delivered in an efficient and elegant user interface.</em> <p><em>For more information on Safari 3.1, please visit </em><a href="http://docs.info.apple.com/article.html?artnum=307467"><em>http://docs.info.apple.com/article.html?artnum=307467</em></a></p></blockquote> <p>Hmm, that sounds too good to be true. <p>...and why does it notify me about it in the first place?</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com1tag:blogger.com,1999:blog-4412878736726215017.post-16544986158074462222008-03-14T00:08:00.001+02:002008-03-14T00:09:00.302+02:00Gotcha: Hidden [Flags] attribute on bitfield enumerations<p></p> <p> </p> <p>Just got reminded of a still <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=273645" target="_blank">unfixed bug</a>. </p> <p>Consider an enumeration of the following kind:</p><pre class="code"> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><summary><br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> Modes enumeration<br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"></summary><br /></span> [<span style="color: rgb(43,145,175)">Flags</span>]<br /> <span style="color: rgb(0,0,255)">public</span> <span style="color: rgb(0,0,255)">enum</span> <span style="color: rgb(43,145,175)">Modes</span> {<br /> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><summary><br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> Yes<br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"></summary><br /></span> Foo = 1,<br /> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><summary><br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> No<br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"></summary><br /></span> Bar = 2,<br /> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"><summary><br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> Maybe<br /></span> <span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(128,128,128)"></summary><br /></span> Both = Foo|Bar<br /> }<br /></pre><br /><p>For the user of this enumeration, it is essential to know that it in fact is a bitfield (as specified by the FlagsAttribute).</p><br /><p>However, <strong>both</strong> Intellisense <strong>and</strong> object browser fails to give any hint about this fact!?! (Yes, this occurs in both VS 2005 and VS 2008)</p><br /><p>So for now, remember to document (within in the summary, so it is visible) this fact for your fellow developers.</p><br /><p><a href="http://11011.net/software/vspaste"></a></p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0tag:blogger.com,1999:blog-4412878736726215017.post-6250161258498994012008-01-15T22:25:00.001+02:002008-01-15T22:25:34.441+02:00New phone<p>I received my new phone today, this time I thought I'd try something different for various reasons, so I got a <a href="http://www.htc.com/product/03-product_htctouch_dual.htm" target="_blank">HTC Touch Dual</a>. I haven't really used it enough yet to post any reviews, but first impression is quite nice. Unfortunately it still takes two weeks until I they switch over to the new SIM card (due to carrier change), so until then I cannot really use it fully. But yes, I will keep my old number...</p> <p>On a related note, things don't seem as bright with the handsfree that I got, it was cheap yes, but first it had the wrong kind of mains plug on the charger, and secondly after I found an appropriate adapter, the thing won't charge !?!</p> /SiDhttp://www.blogger.com/profile/14502300853105995585noreply@blogger.com0