August 12, 2007

How To: Get Your ASP.NET Questions Answered Fast

Ever run into one of those really tough technical problems at work?  The type of problem that persists through hours of googling.  The kind that remains unsolved even after downloading numerous CodeProject samples?  I think every developer has been there one time or another.  It comes with the territory, but there is a solution: Microsoft's MSDN Forum Website.  The MSDN Forums are patrolled around the clock by some of the most talented technical people in the industry.  If anyone is going to be able to help you solve your problem, it is one of these people.  The trick is that you need to craft your question in such a manner that it is appealing to answer.  If want your question answered first you need to make it stand out.  What makes a post attractive to other developers?  CODE SAMPLES!  Shame on you if you answered that incorrectly.  At some level, forum threads are similar...

Topics: ASP.NET , General .Net , Other

June 20, 2007

EventHandlerList - Declaring .Net Events that Conserve Memory

Ever heard of the EventHandlerList object that lives in the System.ComponentModel namespace of the .Net framework?  I hadn't until I disassembled the System.Windows.Forms.Control class while debugging the other day.  I did a few google searches and ended up on an MSDN page titled 'How to: Declare Events That Conserve Memory Use'.  I found the content rather interesting.  Typically, a class declares an event as follows:public class Book { public event EventHandler PagedChanged; public void TurnThePage() { if (this.PagedChanged != null) { this.PagedChanged(this, EventArgs.Empty); } } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color:...

May 15, 2007

Code Review Tool that integrates with Visual Source Safe

It has been over three years since I worked on a team that had any notion of a structured code review.  I previously worked for Microsoft and the team I was part of had a sophisticated process in place to ensure the stability of the code base.  This process included a 10 step checklist that a developer had to walk through before they were allowed to check changes into the repository.  It didn't matter if you changed only a single line of code, only added a few unit tests or completely rewrote the whole application, you still had to follow the same process before you changes could be committed.  One of the items on the checklist was for getting your code peer reviewed.  And it usually went something like this 1.  The developer sends out an email to 3 other developers and quality assurance members referencing the number of the bug/feature they were working on (no changes...

Topics: General .Net

April 25, 2007

Quick Tip: Use System.IO.Path.Combine instead of string concatenation

I came across a bug in our application the other day. The code at fault was very similar to the simple example below.  It assumed that the 'folderPath' argument the code in question was supplied with already had a trailing '\' character appended to the folder path.  Because this was not always the case, the code was failing.  The fix was simple – I replaced the string concatenation with a call to System.IO.Path.Combine. This method takes care of checking for this situation and handles it for you. The System.IO.Path class is loaded with other methods that are useful when doing common file system operations. using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] folderPaths = new string[] { @"c:\folder\folders", @"c:\folder\folders\" }; string fileName = "fileName.txt"; foreach (string folderPath in folderPaths) { Console.WriteLine(Program.SmartFileStringBuilder(folderPath, fileName)); Console.WriteLine(Program.LessSmartFileStringBuilder(folderPath, fileName)); } // both print the samething: c:\folder\folders\fileName.txt, one...

ObjectWriter<T>

A recent project I worked on required moving CSLA business objects to and from a sql server database through stored procs (no adhoc queries were allowed). Overtime, and after a few refactoring sessions trying to normalize some of the CSLA property/field to stored proc parameter mapping code, a nice little reusable component emerged that allowed us to write code as follows: Download code /// <summary> /// /// </summary> public void Insert() { using (SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["simple_orm_unit_test"].ConnectionString)) { using (SqlCommand command = new SqlCommand()) { // init the command command.Connection = connection; command.CommandText = "dbo.uspCustomer_Insert"; command.CommandType = CommandType.StoredProcedure; // open the connection command.Connection.Open(); using (ObjectWriter<Customer> writer = new ObjectWriter<Customer>( new SqlServer.SqlServerFieldInfoMap<Customer>(), new SqlServer.SqlServerSprocDataParamBuilder<Customer>())) { writer.Insert(this, command); } } } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem...

Topics: General .Net

ObjectReader<T>

A recent project I worked on required moving CSLA business objects to and from a sql server database through stored procs (no adhoc queries were allowed). Overtime, and after a few refactoring sessions trying to normalize some of the CSLA property/field to stored proc parameter mapping code, a nice little reusable component emerged that allowed us to write code as follows: Download code /// <summary> /// /// </summary> /// <returns></returns> public static Customer[] FindAll() { using (SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["simple_orm_unit_test"].ConnectionString)) { using (SqlCommand command = new SqlCommand()) { // init the command command.Connection = connection; command.CommandText = "dbo.uspCustomer_FindAll"; command.CommandType = CommandType.StoredProcedure; // open the connection command.Connection.Open(); using (ObjectReader<Customer> reader = new ObjectReader<Customer>( new SqlServer.SqlServerFieldInfoMap<Customer>(), command.ExecuteReader())) { return reader.ReadAll(); } } } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; }...

Topics: General .Net

April 24, 2007

Simple .Net Reflection Utility Class

st1\:*{behavior:url(#ieooui) } I find that at least once in a project, I am digging into the System.Reflection msdn help page trying to identify what method calls and BindingFlags I need to make to lookup a field, property or method on an object and invoke it. The last time I did this; I took the code and moved it into a class. Another advantage that I found of using the Reflector class is that it makes my code a little more more readable.  It is immediately obvious that Reflector.StaticGetProperty(typeof(Cusomter), "FullName") .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html {...

Topics: General .Net


Consulting Services

Yep - I also offer consulting services. And heck, I'll do just about anything. If you enjoy my blog just drop me an email describing the work you need done.

Recent Comments

  • TimothyP wrote: I work with tons of developers who haven't even got a clue what Twitter of Facebook is. In fact, it'...
  • Janko wrote: Yes it's strange that people think it's ok to blog at work but consider unethical to use facebook. P...
  • Kam Lagan wrote: Hi Matt, The numbers do seem a little "off" to what you perceived the community would be like. But...
  • Siderite wrote: You're kidding me! So the people that don't blog think it is ok to blog at work (maybe because they ...
  • Guy Harwood wrote: Good to see the results. one typo.... 'What best describes your current job title?' appears twice,...
  • sirrocco wrote: One problem with : DEV I DEV II DEV III was that I didn't know what it meant :( .(is it common ...
  • Jack wrote: How many person fill the survery? Blog is very common, so I don't think 71.5% is high. Maybe our bos...
  • Andy wrote: Done. The developer1, developer2 question - not sure how meaningful the results are going to be for ...