10 November 2008

List<T>.Find()

I am going to try to document issues that I found not intuitive or easy to figure out (which may or may not be sleep deprivation induced), so here is my latest with an issue with List<T>.Find().

With the List<T>.Find method, you are supposed to supply a predicate, which is really just a delegate with a boolean function determining if a match happened.  So, when would this fail?

List<IItem> items = new List<IItem>();



if (items.Find(item => item.ItemId == smi.ItemId) == null) {


    items.Add(csFacade.GetItemByItemId(smi.ItemId));


}




Answer:  when items contains a null.  My assumption going into this was that I would always get a valid result from the method adding to the items list, but it may return null. 



So, to solve this, I would either need to evaluate the return from GetItemByItemId and only add if not null, or change my predicate to check for null before comparing the ItemIds.

08 November 2008

Setting up IIS7 for a Maverick.Net project

(Thanks to Paul Fox for these instructions)

  • Open IIS Manager by pressing "Windows Key" + R
  • Type "inetmgr" and press Enter
  • Expand the System and "Web Sites" nodes and click on "Default Web Site"
  • Click on "Handler Mappings"
  • Click "Add Script Map"
  • Add the following settings
    • Request Path: *.m
    • Executable: C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
    • Name: Maverick.Net
    • Click on "Request Restrictions" and uncheck "Invoke handler only if request is mapped to:"
    • Click OK.

image