Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, May 03, 2011

C#: Does a Close() automatically call a Flush()

The following C# code always looked a little clunky to me, because a Close() should probably perform a flush as well. I quickly Googled around and my suspicions were confirmed that the Close() method would automatically do a Flush().
Response.Write(qdbXml);
Response.Flush();
Response.Close();
So while cleaning up some other code I removed the Flush() call. Then everything stopped working. I thought it was the other changes I made at first. Chrome gave this helpful message:
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
I restored the Flush() and everything worked great again. The Response object above is a System.Web.Mvc.Controller.Response object which doesn't necessarily work like some other stream objects and needs flushing before closing.
TIL not all stream objects behave alike and I can get in trouble by assuming hastily gathered Googled results apply to me.

Monday, March 21, 2011

AutoMapper for C#

I finally got around to using AutoMapper from fellow Austinite Jimmy Bogard. I watched Jimmy's helpful video and the rest was easy.
AutoMapper is a Data Transfer Object (DTO) helper framework that can map your domain objects to view objects.
In my case I wanted to add extra formatting to render my domain objects as HTML, but realized a "ToHtml()" method on the domain object doesn't smell so good. I created a View Model directly from the domain model via Automapper (with only the attributes I needed to display) and added the HTML rendering code there.
Is that the smell of a pine forest after a Spring rain?

Pine Forest by ®DS
Pine Forest a photo by ®DS on Flickr.

Thursday, February 28, 2008

Whinning about Microsoft's Inept Naming Schemes

While searching on O'Reilly's code search site this morning, I was reminded how Microsoft chooses unfortunate names for products. My initial problem was searching for code in C# relating to the ICollection interface. I entered the category as "C#":

cat:c# icollection

and got returned a bunch of code snippets on C, C++, and C#. What I needed to say was,

cat:csharp icollection


The problem with "C#" is that it doesn't really play well with search. I can see the cute progression of C, C++, and the the musical incrementation with C#, but it's a pain in search. I can understand a non-technical marketing person (with a degree in music) selecting the name, but a technical company? Sun did a nice job selecting "java" as the final name for the language - it's a real word, but a little obscure. Why couldn't Microsoft select something like "jasper" or some obscure tea name?

And selecting ".Net" as the name of a framework? Isn't ".net" a top level domain? And how do you search for something with a dot in front of it? Don't search engines strip out obscure characters?

And while I'm at it, what sense does it make to name your operating systems, Windows 3.1, Windows 95, Windows 98, Windows 2000, NT, XP, then Vista?
Please, use version numbers, or years, or code names, but don't mix them - it gives a sense of purposeless wandering.

Ok, I feel better now - back to ICollection.