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...

Comments (1) | TrackBacks (0)

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:...

Comments (2) | TrackBacks (1)

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...

Comments (2) | TrackBacks (0)

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...

Comments (2) | TrackBacks (1)

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...

Comments (0) | TrackBacks (0)

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; }...

Comments (0) | TrackBacks (0)

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 {...

Comments (3) | TrackBacks (1)

This Blog

  • Email Me
  • RSS
  • Atom
  • Entries - 102
  • Comments - 1276
  • Recent Comments

    • Chau wrote: Matt, I know its wrong to ask? Do you have black and gray version of the images? If would really h...
    • thombcoroemar wrote: Hi. Very interesting site! Thanks!...
    • ntulip wrote: i've followed your example and it seems that it doesn't work when your controls which expose the met...
    • Dave wrote: Anyone figure out the masterpage issue?...
    • rayzal wrote: Nice! i like it so much. Anybody here knows how to do it in PHP? Really appreciate any help :) thnks...
    • vitta wrote: Hi Matt.. I have the smillar requirement on navigating tabs on previous and next buttons. But I am...
    • Kabir wrote: Hi Matt I have been trying to implement this modal edit interface and i have been able to successful...
    • Gustavo Camps wrote: Excellent Blog!!!! is it possible to add Keyboard Navigation funcionality to vs2008 Lisview?...