Posts Tagged ‘.net’
WPF’ing around with Boo and external xaml files
Here is a snippet of Boo code (formatted with Python syntax highlighter) that will load a xaml file into a WPF Window:
import System import System.Windows from PresentationFramework import System.Windows.Markup from PresentationFramework import System.IO class XamlWindow(Window): def constructor(name): load_xaml(name) def load_xaml(name): xaml_file = File.OpenRead(Path.GetFullPath(name)) self.Content = XamlReader.Load(xaml_file) Application().Run(XamlWindow("mainui.xaml"))</pre>
See http://devpinoy.org/blogs/smash/archive/2006/10/04/XAMl-meets-Boo.aspx for reference.
Alternatively, here is the equivalent IronPython code:
import clr clr.AddReference("PresentationFramework") clr.AddReference("PresentationCore") from System.Windows import Window, Application from System.Windows.Markup import XamlReader from System.IO import File, Path class XamlWindow(Window): def __init__(self, name): self.load_xaml(name) def load_xaml(self, name): xaml_file = File.OpenRead(Path.GetFullPath(name)) self.Content = XamlReader.Load(xaml_file) Application().Run(XamlWindow("mainui.xaml"))
Lastly, here is an example xaml file
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Label Content="Hello World" /> <Button Content="Clickable" /> </StackPanel>

VMWare VMDebugger “unable to detect current startup project”
I spent many small packets of time trying to find a solution to this problem over about two months. Luckily, I stumbled across an answer that actually worked for me.
Problem: Visual Studio 2008 with VMWare VMDebugger integration does not work. When I try to launch debugging in a VM, I get a message that says “Unable to detect current startup project”.
Solution: Remove any installer projects that are in the solution.
Source: Read MartinMoesby comment here.
Gestalt = Low-Lying Awesome
Microsoft appears to be betting big on Silverlight. When the Silverlight 1.0 bits were released in 2007, my initial thoughts were, “Yay, Flash for .NET developers.” As Microsoft pushed forward with version 2, version 3, and now version 4 of Silverlight, those sarcastic thoughts have subsided to make way for more genuine curiosity. How did that happen?
Well, for starters, Microsoft delivered real features. Initially, Silverlight demos were all about media (music and video). In addition, Microsoft touted the interopability between dynamic languages like vbx, c#, python, ruby, and javascript. Then, that interopability was sidelined and Silverlight applications started to emerge. Which was interesting. In fact, Silverlight 2 had enough features to stir up debates in the enterprise over which RIA technology was best suited for enterprise applications: Flash 8 with Flex or Silverlight 2. Then, Microsoft played their wildcard. They made Silverlight play nicely with … ugh … Mac OSX. Out-of-browser Silverlight applications made me raise my eyebrows for a technology that I had quickly written off as a “fad”.
That might still be the case. I won’t make a claim either way. But, Silverlight and RIA are spaces where Microsoft continue to innovate. Gestalt is a very good example of that last statement. Gestalt is built atop a foundation consisting of XAML, Silverlight, and dynamic languages. It enables web developers to script their way to rich internet applications in a way that both Flash and Silverlight seemingly missed.
With that said, it is difficult to pinpoint exactly what value Gestalt adds, but you feel it when you’re molding some python, ruby, or javascript hackery into a magical Silverlight-powered application that just works.
The technology appears to still be more of a proof-of-concept than a supported product. But, it makes a strong case for embracing XAML and Silverlight.
Checkout the website and the samples at http://visitmix.com/labs/gestalt/.
Richmond Code Camp 2009.2
Wow! What an event!
This weekend, I joined ~400 others for the Richmond Code Camp and a good time was had. As others have noted, the hardest part of the day was choosing which talks to attend due to a schedule full of excellent topics and speakers.
I started off with Justin Etheredge’s talk on Linq Expressions. This was 75 minutes of great slides and polished demos of basic to advanced Linq concepts. I left that talk more educated and less scared of the power of Linq Expressions. Justin has an unbelievable understanding of how Linq works and an amazing ability to convey that to the layman with nothing more than a stock photo of a cat and a VM with Win 7 and VS 2010.
Second, I attended a talk that was missed from Raleigh’s Code Camp two weeks earlier. I went to John Feminella’s talk on Ruby for C# developers. John gave .NET developers a great introduction to the Ruby language using IronRuby (I thought that was brave at this point). To my surprise, John held up his end with great content and examples, and IronRuby held up its end with stability and support for most of the features of Matz Ruby (the original implementation of Ruby).
Next, I decided to checkout Open Spaces. The evening before, I jokingly suggested that the audience would convince Kevin Hazzard to present something on the DLR at Open Spaces since he was not officially presenting. Well, I guess they did! Kevin led a discussion on IronPython and the DLR that included some very nice demos. He also discussed C# 4.0’s new “Dynamic” type and how it actually works. I gained a lot of insight on when and where the DLR and Dynamic Languages on .NET are useful. And, while I love Ruby, IronPython is making the Python language very attractive to me.
Another talk that I was able to attend was by Chris Love. He talked about building quality ASP.NET applications faster. I know Chris to be a very experienced developer. He just completed an updated version of a book I found to be very practical when I was getting into more advanced ASP.NET concepts, ASP.NET 3.5 Website Programming: Problem – Design – Solution. His talk drew off of his experiences building applications and sites for his clients. He talked about architecture as well as development practices. I recommend his talk to anyone doing ASP.NET development that is looking for practical advice on how to manage it all from start to finish.
In the last time slot of the day, I presented Spark, an ASP.NET MVC View Engine, to a great audience. This was essentially the same talk that I gave a couple of weeks earlier at Raleigh’s Code Camp, but I made some modifications for the Richmond crowd. Here are the slides from that talk:
Enjoy!
Slides from Raleigh Code Camp 2009
This weekend, I had the pleasure of presenting a talk on Spark View Engine at Raleigh Code Camp (#rducc). It was a well organized event with a schedule full of great topics and presenters. The Triangle .NET User Group (TriNUG) did a wonderful job at organizing and running the event. Thanks, TriNUG!
As promised, I am posting the slides that I used in the Spark talk. Although the true context of the talk is not present on the slides, I hope these are helpful to someone using the Spark View Engine or considering it.
Stay tuned, or subscribe to the rss. I am planning to post a series of short to-the-point screencasts that demonstrate how to practically use Spark in your ASP.NET MVC application.
In the meantime, checkout http://www.dimecasts.net for some great videos on Spark.
Ruby-like Times method for Ints in C#
Yesterday, @mccartsc did a presentation on Linq for a group of us at work. As part of his presentation, he demonstrated an extension method he threw together to give .NET Integers the Times method that Ruby programmers have enjoyed for years.
Basically, the n.Times methods is passed a block that it will execute n number of times. In Ruby, you could do something like this:
5.times {|x| puts x }
That trivial line of code would output integers 0 through 4.
With such a trivial use case, you may be wondering “Why would anyone want to do that?” Well, @mccartsc and I had a discussion about coding without traditional For Loops. Foreach Loops are great for enumerating IEnumerable objects, but it is not a replacement for the traditional For Loop. We thought, “Wouldn’t it be great if you could use a Ruby-like Time method to execute a block of code an arbitrary number of times?” So, @mccartsc built it as part of his Linq demonstration.
Here’s how he did it:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LinqDemo { static class Extensions { public static void Each<T>(this IEnumerable<T> collection, Action<T> action) { foreach (var item in collection) action(item); } public static IEnumerable<int> Range(this int max) { for (int i = 0; i < max; i++) yield return i; } public static void Times(this int i, Action<int> action) { i.Range().Each(action); } } }
@mccartsc created three extension methods to implement the Times method. “Each” is an extension method for IEnumerable types. It passes each member of a collection into an Action delegate.
“Range” is an extension method for Int types. It creates a zero-based IEnumerable collection out of an integer. For instance, 5.Range();, would return a collection consisting of integers 0,1,2,3,4.
Finally, “Times” is another extension method for Int types that allows a user to execute an action an arbitrary number of times by using the aforementioned Range and Each methods. Once I have these extension methods in my C# project, I can execute code like this:
5.Times(i => Console.WriteLine(i.ToString()));
The above would output:
0
1
2
3
4
I think that’s pretty cool.
Thanks @mccartsc for the code and the demonstration.
Update: @mccartsc got a blog! Check him out at http://scmccart.wordpress.com/.
(Reminder) How to reset my environment settings in Visual Studio 2008
A co-worker once asked me how to reset his environment settings. His environment was set to Visual Basic, but he wanted to change it to C#. Both of us are very experienced .NET programmers, but neither of us could remember how to do it. Here is a reminder to us all:

Goto Tools > Import and Export Settings > Reset all settings
Not really a Fan, but still kind of Groovy
Fan is a very young programming language with some promise. The features of the language are more pragmatic than theoretical. This means, Fan, like Python and Ruby, should allow you to be productive in a concise manner. The syntax of Fan left a lot to be desired. It is not the prettiest language, but hopefully, syntactic sugar will be added in the future to facilitate Fan’s adoption.The killer feature that Fan promises to deliver is the interoperability with both the Java Virtual Machine and the .NET Runtime. Currently, one or the other are required to compile Fan source code. However, Fan currently does not offer much in terms of interoperability with Java and/or any of the CLR languages. That is disappointing for now, but the language is extremely young. Powerful features like that take time.
While a more developed Fan will find its niche audience of developers, I wonder about the true utility of such a language. The JVM already has the well-known scriptingly awesome language known as Groovy. I do not qualify as a Java developer, but I hold Groovy in high regard because of its performance, language features, and *gulp* use of the JVM. Java reservations aside, Groovy is a language I look forward to learning.
.NET is not absent of nice scripting languages either. Boo is one such language, noted for its Python-like syntax. Oh, and did I mention IronPython? It is also noted for its Python-like syntax, but .NET-like performance. Perhaps, the most awaited .NET language is IronRuby, a dynamic language with the features of ruby and the power of the .NET Framework. It is going to be great.
There is one other .NET language that I think deserves mention. It is called Nemerle. Nemerle is a static language, much like C#. However, Nemerle implemented features like type inference long before the release of C# 3.0. Since the latest release of C#, Nemerles advantages have become less pronounced. But, it still differentiates itself from C# with features like Macros that allow you to customize the syntax of Nemerle (think domain specific language).
Nemerle is a pretty mature language. It has some integration with Visual Studio 2005. Also, the Nemerle compiler is written in Nemerle. That could be a sign of a pretty usable language.
Nemerle is open-source. I don’t know if it is actively developed today. However, I recently came across a blog post that sums up some of the features of Nemerle. That post was the inspiration for this post actually. Onur went as far as to call Nemerle “C# glorified.” I’m not sure I agree with that.
However, I believe Groovy is definitely “Java glorified.” Maybe Nemerle is a little Groovy.