Jul 31, 2008

No Dynamic Ports for Visual Studio 2005 Web Server

Ocassionally, having VS2005 create localhost using a random number can be a pain. To get around this, click the website "root" in Solution Explorer & then bring up the properties. In the properties pane, set "Use dynamic ports" to False & then set "Port number" to whatever value you want between 1024 and 5000.

Jul 21, 2008

Disable SuperFetch in Vista

In a comment on his Blog (Coding Horror), Jeff Atwood pointed out the command to temporarily turn off SuperFetch, Vista's new memory caching program. Some people have hinted that SuperFetch may cause slow-down or other issues. YMMV

Command:
net stop superfetch

*Note: This will come back after a restart, so if you want to kill it, disable the service.

Jul 10, 2008

Display all the properties in an Object

I've come across this problem before, sometimes when working with classes designed by different groups, other times when I'm being lazy & don't want to look through my code. Either way, it's sometimes handy to be able to iterate through the properties of an object. So, here's a "quickie" to dump the property names/values to an exception.

Definition:
public void showObjProperties( object myObject ) {
System.ComponentModel.PropertyDescriptorCollection objProperties = System.ComponentModel.TypeDescriptor.GetProperties( myObject );
string strTmp = "";
string strType = myObject.GetType( ).ToString( );
for ( int i = 0; i < objProperties.Count; i++ ) {
strTmp += strType + "." + objProperties[i].Name + Environment.NewLine;
//strTmp += strType + "." + objProperties[i].Name + ": " + objProperties[i].GetValue( myObject ).ToString( ) + Environment.NewLine;
}
throw new Exception( "Props: " + Environment.NewLine + strTmp );
}


Calling code:
String[] aryString = new String[] { "test1", "test2", "test3" };
showObjProperties( aryString );


Results:
Props: 
System.String[].Length
System.String[].SyncRoot
System.String[].Rank
System.String[].IsReadOnly
System.String[].IsFixedSize
System.String[].IsSynchronized
System.String[].LongLength

Jul 2, 2008

Comparing Custom Objects in C#

Once again I found myself trying to remember the specifics of how to compare specific attributes of a custom object when doing an Array Sort. The linked MS kb article has the specifics, but I'll copy some of that here, for longevity. ;)
private class sortYearAscendingHelper : IComparer
{
int IComparer.Compare(object a, object b)
{
car c1=(car)a;
car c2=(car)b;
if (c1.year > c2.year)
return 1;
if (c1.year < c2.year)
return -1;
else
return 0;
}
}

The key is you have to return one of three values:
  • -1 if the first object is less than the second
  • 1 if the first object is greater than the second
  • 0 if the values of the two objects are equal
Hope this helps someone,
Ian