Browse by Tags

Tagged Content List
  • Blog Post: A prototype WPF/Silverlight layout designer

    I’ve been thinking recently about how would I write a WPF UI designer that would specifically highlight the new WPF layout paradigm, and not try to mimic the old WinForms paradigm. The old VB6/WinForms designer was built around absolute positioning. It allowed for rapid WYSIWYG prototyping of interfaces...
  • Blog Post: How to live forever (if you’re a CLR object)

    Just subscribe to a static event, or an event of a long-lived object (such as a singleton instance). That long lived object will keep alive all objects that subscribed to any of its events (including you).
  • Blog Post: Updated C# all-in-one file

    Thanks to everyone who came up with suggestions on my Did I miss any C# syntax construct? post. The updated file is below. #error Error message #warning Warning message #pragma warning disable 414, 3021 #pragma warning restore 3021 #line 6 #line 2 "test.cs" #line default #line hidden #define foo...
  • Blog Post: Did I miss any C# syntax construct?

    Dear readers, I’m asking for your valuable input again. I went through some of our test files and combined a single “all-in-one” C# syntax file that I want to contain all C# 4.0 constructs. I’m specifically not looking for combinations (because there’s an infinite number , obviously), it’s enough to...
  • Blog Post: Interview answers

    In the previous post , I’ve come up with this interview question: In a given .NET string, assume there are line breaks in standard \r\n form (basically Environment.NewLine). Write a method that inserts a space between two consecutive line breaks to separate any two line breaks from each other. Update...
  • Blog Post: Interview question

    Here’s a nice simple interview question: In a given .NET string, assume there are line breaks in standard \r\n form (basically Environment.NewLine). Write a method that inserts a space between two consecutive line breaks to separate any two line breaks from each other. Also, anyone venture a guess what...
  • Blog Post: A million-dollar pen vs. a pencil

    You know this legend about how NASA spent millions to develop a pen that can write in zero gravity , and the russians have just used a pencil? Well, I was reminded about this by Dejan ’s post in response to my post about the Random Gradient Wallpaper Generator . I used an O(NxN) algorithm to generate...
  • Blog Post: Bezier Curves and Car Manufacturers

    Michael has asked me if it was possible to add Bezier curves to Live Geometry. So I went ahead and added a Bezier tool (and it took me about 30 minutes to do so!): This draws a cubic Bezier curve using four points: There is something beautiful and elegant about these curves. No wonder industrial designers...
  • Blog Post: Irony

    (Ironically, this post is not about irony in it's traditional sense ) Irony ( http://irony.codeplex.com ) is an open-source .NET compiler construction framework written by Roman Ivantsov . It is a ".NET Language Implementation Toolkit". The language grammar is described in C# (or any other .NET language...
  • Blog Post: Saving images (.bmp, .png, etc) in WPF/Silverlight

    I’ve recently added a new feature to Live Geometry that allows users to save the current drawing as a bitmap or a .png file. Just push the save button and pick the desired image format in the Save dialog: Fortunately, both WPF and Silverlight support saving full visual contents of any visual into a file...
  • Blog Post: 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 ...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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 have self-intersections...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: Kirill’s Whitespace Guidelines for C#

    I don’t remember seeing any explicit guidelines on whitespace formatting for C# programs, however it seems that experienced C# developers all format their C# code files in a very similar fashion, as if there are some implicit but widely-accepted rules. In this post, I’ll try to formalize my own rules...
  • Blog Post: ForEach

    In my recent post about coding styles one particular thing provoked the majority of feedback and discussions: the ForEach extension method on IEnumerable<T>. Justin Etheredge has a good post about this method here . StackOverflow.com also has a good question: Why is there not a ForEach extension...
  • Blog Post: Reflections on coding style

    I've been monitoring my coding style for quite a while and I noticed that I often prefer chaining method calls to normal control flow. Now I think it might not always be such a good idea. To give you an example, today I had a task of reflecting over constants in a class and stuffing them into a dictionary...
  • Blog Post: A one-line program to count lines of code

    I wanted to sum the total lines of code in files in a given folder. I thought that writing my own program to do this would be faster than looking for it on the internet, so here's what I came up with (1 line broken into 7 lines to fit into your blog reader): using System; using System.Linq; using...
  • Blog Post: Too much type information, or welcome back System.Object and boxing

    We all know that generics are good - they promote code reuse, static type checking by the compiler, increase runtime performance, allow more flexible OOP designs, lay the foundation for LINQ, help the IDE to provide more helpful IntelliSense and have tons and tons of other vital advantages. "var" is...
Page 1 of 2 (33 items) 12