Wednesday, April 30, 2014

Make an auto-incrementing number appear in the rows of an Excel column within an otherwise consistent entry.

Manually make the first two rows with the values "foo1" and "foo2" while substituting what you need for "foo" itself. Then select the two cells, release the mouse, and move the pointer over the lower right corner of your selection like this:

 
 

Next: Click and drag downwards.

 
 

Finally: Just let go!

If an object has a friend in C++...

...the friend may see the object's private methods and members.

Thread.Sleep(1000);

...is a one second pause in C#.

Did you know that when StructureMap maps a class to an interface that when the class gets instantiated that the constructor with the most parameters will get called?

What's that? You say you've never seen parameters passed in in the mappings and thus this doesn't make sense? I've never seen this either, but you may specify at the constructor in these scenarios other interfaces which are also hydrated (given dance partners in the form of classes) by StructureMap and StructureMap should "fill in the gaps" so to speak. When undertaking this sort of trickery, you will be golden provided you do not create a circular reference.

Bonus: There is a NuGet package, and it might be StructureMap.MVC4 (not sure), which allows for the interfaces to be handed in and hydrated at the constructor signatures of MVC controllers!

Tuesday, April 29, 2014

Override ToString() on a object in C# to make it easier to debug!

Consider this Person class.

using System;
namespace Testing.Models
{
   public class Person
   {
      public string Name { get; set; }
      public DateTime Birthdate { get; set; }
      public int ZipCode { get; set; }
      public bool IsEligibleForRetirement { get; set; }
   }
}

 
 

Now consider debugging a dictionary where the key values are of the Person type like so:

 
 

A lot of the drilldown "heartache" may be alleviated by temporarily shoving in a ToString override.

using System;
namespace Testing.Models
{
   public class Person
   {
      public string Name { get; set; }
      public DateTime Birthdate { get; set; }
      public int ZipCode { get; set; }
      public bool IsEligibleForRetirement { get; set; }
      
      public override string ToString()
      {
         return Name;
      }
   }
}

 
 

Debugging gets easier and easier to read.

If you revert something you should not have with TortoiseSVN...

...look for the item in your Recycle Bin in Windows 7.

Ctrl-K followed by Ctrl-D

...in Visual Studio 2013 will autoformat the indentions.

 
 

Addendum 6/20/2016: Ctrl-K-D seems to be legit for this too.