Welcome to Honest Illusion Sign in | Help

Browse by Tags

All Tags » C# » .Net   (RSS)

PropertyBagTextWriter (Stream into Dictionary)

It’s been too long since I posted since .NET code, and I’ve been itching to. (Actually, I really want to write more about politics, but I figured if I don’t show some code soon, I’m gonna lost my techy audience) Fortunately, I’ve got a backlog of things
Posted by James | 1 Comments

Get an ApplicationBarIconButton by name (Redux)

Yesterday, I read a blog post on getting an ApplicationBarIconButton by name . The author made a couple minor errors in the code, which I was going to leave a comment about, except his comment page is broken. So, another excuse to write something for

Creating an Entity Framework connection from another one.

Database connection strings used to be simple. Well, simple, once you learned the arcane syntax, But, at least they had stayed the same for about a decade. But with the EntityFramework, they took on an even more arcane “connection string – within –a –connection

Automating Retry on Exception

Every so often, you run across some action, which just fails, where the best response it to just try it again. This is particularly true when dealing with an external source, like a database or web service, which can have network or other temporary problems,
Posted by James | 0 Comments
Filed under: , , , , ,

The Evolutionary Guide to C# Lambda Syntax

Originally (.NET V1.1), we had to explicitly create a Delegate object to wrap a method reference to use it as a callback method, and that method had to named. button1.Click += new EventHandler(button1_Click); // : // : void button1_Click( object sender,
Posted by James | 2 Comments
Filed under: , , , , ,

Running An Async Event Handler on the UI thread (with lambdas and extension methods!)

So, it’s been a freakishly long time since my last post here. I’ve been trying to get better… I even wrote out a list of topics I wanted to write about. So, let’s start talking about them. As we do more and more work in our applications asynchronously,
Posted by James | 0 Comments
Filed under: , , , , ,

Lambda Expressions as Properties

Peter recently caused a bit of a stir with his article “ Sometimes an enum is not the best idea ”. In it, he had a very specific problem: When an enum is passed to a method as an Object, and that method converts it to a usable value by calling ToString(),
Posted by James | 6 Comments
Filed under: , , , , ,

Portable Areas for Castle Monorail, Part 2

In our last episode, we discussed the PortableAreaController base class, which makes it simple to create a portable area using Monorail. In this installment, we put that class to use. For the purposes of this example, the controller isn’t going to do
Posted by James | 1 Comments

Portable Areas for Castle Monorail

Recently I had read a blogger comparing Castle Monorail with ASP.NET MVC. He chose ASP.NET mainly because it supported Portable Areas while Monorail did not. As a supporter of Monorail, I was very offended by this, and decided to correct the problem.
Posted by James | 1 Comments

Some Better-Written Custom String Methods using C#

In my daily web-surfing, I often stumble upon snippets of C# code posted by people. Usually, I can tweak it a bit. Sometimes, I can tweak it a lot. I usually post a quick comment to the site offering it. Today, I came upon some code that was so bad ---
Posted by James | 2 Comments
Filed under: , , , , ,

A ViewComponent extension for Castle MonoRail, Part II

This was intended to be a two-part article. It was just after I published the original article, I noticed that I’d left out a large part of ViewComponentEx. We continue….. protected bool RenderOptionalSection(string section) protected bool RenderOptionalSection(string
Posted by James | 0 Comments

A ViewComponent extension for Castle MonoRail

I’ve been rewriting my website, njtheater.com, (very slowly) as a Castle MonoRail application. Along the way, I’ve written a number of ViewComponent and other elements. Many of these were of general use, so I’ve added them to the CastleContib project,
Posted by James | 1 Comments

#songsincode : The Turtle’s “Happy Together”

(Me + you) && (you + me) var nomatter = dice.toss(); assert (it != null) me.Only1(you); assert(you == me.Only1()); (Me + you).happy = so; (more on the meme here ) Share this post: Email it! | bookmark it! | digg it! | reddit! Readability Stats:
Posted by James | 0 Comments

Code Tune-Up: Shuffling a List

Over on CodeProject, I spotted an article by Mahdi Yousefi called " Creating an ASP.NET captcha using jQuery and s3capcha”. public static List<int> shuffle(List<int> input) { List<int> output = new List<int>(); Random rnd = new
Posted by James | 0 Comments
Filed under: , , , , ,

Posts from Comments: QuickDataBind

You may have noticed that I don’t write on this blog much. But the thing is I do write a lot on the inter-webs about technical matters --- I just don’t to it here. Usually, I find something interesting on someone else’s blog, and then write an improvement
Posted by James | 0 Comments
Filed under: , , , , ,

DEV102's Programming Job Interview Challenge #6

Another week, another C# interview question from the good folk's at Dev102.com -- Although I use the term "good folks" advisedly, as this week they did not even acknowledge the solution I posted for last weeks puzzle (which was both correct, and, I believe,
Posted by James | 0 Comments
Filed under: , , , ,

DEV102's Programming Job Interview Challenge #4

The folks at Dev102.com are offering weekly programming challenges, where they offer questions, and let bloggers post about them. I meant to write an answer for last week, but never got around to it. Just as well -- my answer would have been wrong. SO,
Posted by James | 1 Comments
Filed under: , , , , ,

How can I easily log a message to a file for debugging purposes?

Today, either Bloglines.com or blogs.MSDN.com blinked, and suddenly I'm seeing old entries on the 'C# Frequently Asked Questions' blog as new. No one has posted anything there in over two years. Anyway, reading the most recent message, it offered a method
Posted by James | 0 Comments
Filed under: , , , ,

What's inside a foreach() statement?

Recently I was looking at some C# code where the author, to loop through some collection, would frequently use call GetEnumerator() and the manually step through the collections, calling MoveNext(). It seemed to me that the code could be written more
Posted by James | 2 Comments
Filed under: , , ,

Design Patterns: Thoughts on the Singleton Pattern

(Note: I started writing this a couple days ago --- a short while before Andrew Matthews published his own very similar article . He, of course, finished his first...) (Update: Fixed the spelling/grammar, and then wrote a bit more) Lately on some of the
Posted by James | 2 Comments
Filed under: , , ,

More Fun with C# Iterators: Take, Skip, TakeWhile, SkipWhile

As I was reading this article by Granville Barnett on some of the new operators available on LINQ queries, I thought, "That's all well and good, but for the time being, we're living in a .Net 2.0 world. I wonder if I could emulate those with just generics

Implementing A Circular Iterator

Many years ago, I wrote an article entitled "Implement A Circular Iterator" for The VisualC++ Developer's Journal . (Unfortunately, VCDJ is now out of business, and it's successor, Visual Studio Magazine , doesn't maintain an online archive of articles
Posted by James | 2 Comments
Filed under: , , ,

C# Code: Adding Skip First to Foreach

A couple years back, I made a proposal online for a new feature in C#. It gathered some interest in the newsgroup. I later emailed it to someone on the C# team at Microsoft (I believe it was Eric Gunnerson but I'd really have to look it up), who emailed

Generics without Collections, Pt. 3

Over the weekend, I attended the third NJ Code Camp. And since the moderators asked nicely, I presented this series as a talk. Overall, the lecture didn't go well. (I was too nervous and talk too quickly. Oddly, on one of the evaluation sheets, someone

Generics without Collections, pt. 2

My previous article on this subject dealt with creating a lazy-loaded data type. But, if you think about it, that's realy just a collection, with just one item. I promised you use of generics without collections, so let's move this to the next step, using

Wordwrapping in C#

Some time ago, I needed a function that would take a block of text, and word-wrap it at a specific line length. As apparently you have now done, I googled for it, and found a blog with a seemingly appropriate algorithm. Except it wasn't. I immediately
Posted by James | 2 Comments
Filed under: , , ,

Generics without Collections

Having moved to C# after years of being a C++ programmer, I was quite happy when generics were added to C#. I could finally do some of the things I was doing before with C++'s templates. However, I noticed something about how C# programmers were using

Performance optimization of an if/else-statement

Mads Kristensen wrote on the subject on if/else statements in C#, running time benchmarks on code such as this: private bool RunIf( string input) { if (input == "hello" ) return true ; else if (input == "jelly" ) return true ; else return true ; } I wrote
Posted by James | 0 Comments
Filed under: , , ,