Browse by Tags

Tagged Content List
  • Blog Post: Converting between RTF to HTML and HTML to RTF

    A while back I posted Converting RTF to HTML which showed how to convert RTF text into HTML markup using the WPF RichTextBox control.  Since then I have noticed many posts on forums asking for a free and easy way … Continue reading →
  • Blog Post: FastSharp 2.0

    I just released a new version of my FastSharp program. Download it   or  View the source code This release contains some notable enhancements: Support for multiple languages C# Visual Basic F# Persistence of your current code language and snippet. This allows you to close FastSharp and start...
  • Blog Post: Useful Moq Extension Method

    I have been working with ASP .NET MVC and I use the Moq mocking library to help test the code I write. Often in ASP MVC anonymous objects are passed around as function arguments. This is especially common in calls to RouteUrl. Since I want to be able to test this and verify that it is called correctly...
  • Blog Post: Converting RTF to HTML

    Have you ever had the desire to convert some RTF text into HTML? Probably not. But if you do, then you are in luck! I recently had the need to do this conversion and after some searching found out a way to do it by enhancing a sample distributed in the MSDN library. The sample is called: XAML to HTML...
  • Blog Post: I finally got fed up with Enum.Parse

    I don’t know why I didn’t do this long ago, but I am done writing this: var val = (SomeEnum)Enum.Parse( typeof (SomeEnum),”someString”); I have typed this too many times and it annoys me.  I wrote a small extension method on the string type to make this better: public static...
  • Blog Post: My xUnit.net Visual Studio Code Snippets

    The xUnit .Net codeplex page lists one useful Visual Studio code snippet for creating a Fact. As you can tell I am fairly fond of code snippets so I created a few more which I use when writing xUnit.net facts. These are one line snippets that I find very convenient when writing my assertions. Below...
  • Blog Post: Inline Regular Expression Options

    I was using attributes from the System.ComponentModel.DataAnnotations    namespace for model validation.  This namespace includes a few very useful validation attributes such as Required Attribute – Validates the field has a value Range Attribute – Validates the field is within a given...
  • Blog Post: Model Binder

    When working with a multi-tier application I often find myself converting from one of the tiers object models to my own similar (but often different) model.  I often write code that would set one by one each property from a web tier object to my object.  In order to make this easier I wrote...
  • Blog Post: SQL CE 3.5 with LINQ to SQL Revisited

    A few days ago I made a post about using SQL CE 3.5 with LINQ to SQL . I described a way to use connection pooling with SQL CE. A gracious blog reader (Mike Brown) pointed out a way I could make my solution much simpler by using the [ ThreadStatic ] attribute. I never heard of this attribute but it is...
  • Blog Post: SQL CE 3.5 with LINQ to SQL

    Using LINQ to SQL with SQL CE 3.5 can be a bit of a challenge. First off, the LINQ to SQL Visual Studio designer doesn't support SQL CE so you need to run sqlmetal from the command line to create the object model (or write it by hand). Once you get past this point then you can use LINQ to SQL the same...
  • Blog Post: CollectionView.DeferRefresh() : My new best friend

    Well, maybe not best friend but its a nice function.  When working with bound collections in WPF you often end up dealing with a CollectionView .  This is the MSDN documentation description of a CollectionView : You can think of a collection view as a layer on top of a binding source collection...
  • Blog Post: Generic Insert and Update for LINQ To SQL

    Quick code snippet time! The following are generic methods for inserting and updating a detached entity into a database using LINQ to SQL. 1: /// <summary> 2: /// Updates the database with item. 3: /// </summary> 4: /// <typeparam name="T">Type of the item<...
  • Blog Post: Foreach is Duck Typed!

    I thought I know how the foreach construct worked under the covers. I figured the compiler would check if the type being iterated over implement IEnumerable or IEnumerator. And if so it will call MoveNext and Current to loop over the elements. But then I read this: http://blogs.msdn.com/kcwalina/archive...
  • Blog Post: ArgumentNullException vs ArgumentException

    Both ArgumentNullException and ArgumentException have a constructor which takes two strings. One is the name of the parameter (or argument) in question and the other is a string describing the exception. The funny/odd/interesting thing about them is that one has the opposite order of arguments. For ArgumentException...
  • Blog Post: Intro to LINQ to SQL Optimistic Concurrency

    After some investigation I feel I have a decent understanding on how LINQ to SQL concurrency works. LINQ to SQL uses optimistic concurrency which means that it never takes an exclusive lock on a table.  It caches the information you are working with and then (by default) when you submit changes verifies...
  • Blog Post: Closures and Pass by Reference

    What do you think the following code will do? Compile time error Run time error Work fine 1: static void Main( string [] args) 2: { 3: int x = 10; 4: int y = 5; 5: Swap( ref x, ref y); 6: } 7: 8: 9: static void Swap( ref int x, ref int y) 10: { 11: int temp = x; 12: x = y; 13: y = temp; 14: Func<...
  • Blog Post: Covariance and Contravariance

    I just finished reading the series of ten blog posts by Eric Lippert about covariance and contravariance . These topics were new to me but after reading this blog series it all made sense. It finally explained to me why some things which I thought I should be able to do does not work in C#. One example...
  • Blog Post: Lazy Prime Number Sieve in C#

    In my last post I talked about a Stream class for creating efficient lazy lists in C#. In addition, I showed several classic functional methods I ported to C# to be used on the lazy lists. As I mentioned in that post, I will now talk about an example I included in the source code for the lazy list class...
  • Blog Post: Digging deeper into C# Lazy Lists

    One of the most interesting aspects of the Haskell language is the fact that features lazy evaluation. My interest in lazy evaluation led me to a post on Wes Dyers blog about lazy lists in C#. In his blog post he talks describes how to create a lazy list class in C# and demonstrates some classic lazy...
  • Blog Post: Useful LINQ Method- GetMemberTypeChain

    Recently, I have been working on a custom LINQ provider in C#. In a later post (when I have more time to write) I will go in depth into what I am worked on and what have I learned about writing a LINQ provider. But for now I will present a simple function that simplified part of my work. It is called...
  • Blog Post: Understanding Variable Capturing in C#

    With the addition of anonymous delegates in C# 2.0 and with lambda expressions in C# 3.0 you might have been hearing a lot about variable capturing. This is the mechanism in which the delegate/lambda which was defined inline is able to hold on to any variables within its lexical scope. For example in...
  • Blog Post: FastSharp - Write it, Execute it

    UPDATE: New version on FastSharp that includes a Windows 7 Gadget! Learn more here. Last year I wrote this program which I named FastSharp. It is a text editor which lets you compile and run C# code that would normally exist inside a method. The inspiration for this came from getting tired of opening...
  • Blog Post: Who would have thunk it?

    I recently read this article about Lazy Computation in C# . What the article discusses is creating lazy evaluation in C#. Lazy evaluation is a key feature of functional languages like Haskell but is not common in imperative languages. It is used in Haskell because it implements parameter passing on a...
  • Blog Post: Did you know.... Generic Methods

    Did you know that you can call a generic method with out supplying the type argument. The C# compiler will fill in the type parameter for you at compile time since the language is strongly typed. static void MyMethod<S>(S myParam) { Console.WriteLine( typeof (S).ToString()); Console...
  • Blog Post: Lambda Expressions are more fun in Visual Basic .NET

    I love C# and I would never want to do anything to make it seem any less amazing but I have to give credit where credit is due ... to Visual Basic .NET. Yes, I said it. Both languages have been adding features inspired by the functional and dynamic programing world. However, VB .NET has went a few steps...
Page 1 of 2 (31 items) 12