Random Gradient Wallpaper Generator

Oops, I did it again 🙂 Created a new CodePlex project, that is. Introducing http://wallpaper.codeplex.com – a simple tool to generate a nice random wallpaper and display it on your desktop with just one click: Randomize – assigns random colors to all four corners Set as Wallpaper – saves the picture to My Pictures\GradientWallpaper.bmp and…

10

Dump Environment Folder Paths

This is just a quick snippet to dump the value of Environment.GetFolderPath for all special folders on a machine (so I don’t have to write it again next time): public static string DumpEnvironmentPaths() { var paths = Enum.GetValues(typeof(Environment.SpecialFolder)) .Cast<Environment.SpecialFolder>() .Select(folder => folder + " = " + Environment.GetFolderPath(folder)) .Aggregate((line1, line2) => line1 + Environment.NewLine +…

7

Reflection with dynamic

This past summer the Visual C# IDE team was fortunate enough to have Paul van Brenk intern with us. Paul is a great guy and an experienced .NET developer from Rotterdam, Netherlands, who is interested in Azure, cloud computing and many other things. He also happens to be one of the contributors for dasBlog, which…


UI without code or XAML: PropertyGrid, DataForm, etc.

WPF has certainly advanced the state-of-the-art in programming the UI. I personally think that WPF and Silverlight remove all the limits that existed to UI development in the past. The only limit now is your imagination. XAML is there for declarative machine-friendly UI descriptions, data-binding is for easier logic of syncing the UI to the…

2

Calling new on an interface

Interesting thing: technically there is a way to call new on an interface to create an object. How? Using a feature in the C# compiler for COM-interop support: using System.Runtime.InteropServices; class Program { static void Main(string[] args) { IFoo foo = new IFoo(); } } class Foo : IFoo { } [ComImport] [Guid("DC1CB768-0BE5-4200-8D0A-C844BFBE3DE7")] [CoClass(typeof(Foo))] interface…

10

Instantiating types with no public constructors

It turns out, Activator.CreateInstance and Activator.CreateInstance<T> fail if there is no public parameterless constructor defined on a type we’re trying to instantiate. Even if the constructor is internal (basically, anything other than public), CreateInstance will fail. This one was a surprise actually, I would expect the reflection binder to work for internal constructors at least….

7

Samples for the Undo Framework

I just added some samples for the Undo Framework. You can find the samples in the source code or download them from the project website. MinimalSample First is a simple Console App sample called MinimalSample. Here’s the full source code: using System; using GuiLabs.Undo; namespace MinimalSample { class Program { static void Main(string[] args) {…

13

Algorithms in C#: shortest path around a polygon (polyline routing)

Suppose you have to build a road to connect two cities on different sides of a lake. How would you plan the road to make it as short as possible? To simplify the problem statement, a lake is sufficiently well modeled by a polygon, and the cities are just two points. The polygon does not…

14

yield return and Continuation-Passing Style

Someone was recently porting some C# code to VB and had a question about how to convert the C# yield return iterator methods to VB (VB currently doesn’t support iterators). There were a lot of replies like “use Reflector on a compiled binary and copy-paste the generated state machine code”. The problem with the Reflector…

5

A simple sample for C# 4.0 ‘dynamic’ feature

Earlier I posted some code to start Visual Studio using C# 3.0: using System; using EnvDTE; class Program { static void Main(string[] args) { Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.9.0"); DTE dte = Activator.CreateInstance(visualStudioType) as DTE; dte.MainWindow.Visible = true; } } Now here’s the code that does the same in C# 4.0: using System; class Program {…

11