private void SetMaster(SPWeb web, string masterpagePath, string custommasterpagePath)
{
web.CustomMasterUrl = masterpagePath;
web.MasterUrl = custommasterpagePath;
web.Update();
foreach(SPWeb child in web.Webs)
{
try {
SetMaster(child, masterpage, custommasterpage);
}
finally
{
if(child != null) child.Dispose();
}
}
}
Call this passing the SPSite.RootWeb, and specifying the path to your master pages. It'll recurse over all the sites below that rootweb in the site collection (i.e. all of them!)
Note that you may need to consider whether the sites below use different master pages as this can cause problems, particularly with Meeting Workspaces, but possibly others.
You may also need to consider storing the original master pages details in the property bag for the web so you can restore them later (e.g. feature deactivation)
And you may wish to make sure that themes are turned off and don't interfere with your look and feel.