| Servergeek |
| Mickey Williams' weblog |
|
My C# BookMicrosoft Press PageOn Amazon Racing LinksSlalomSkateboarder.comNCDSA slalom page 3dm Ick Sticks Pocket Pistols .NETScott GuthrieRob Howard .NET Notes BradA LonghornScobleChris Sells ServicesDon BoxChristian Weyer All Things Distributed Ingo Rammer Tim Ewald BlawgsBag and BaggageSCOTUS Blog EconArg MaxCapital Spectator OtherWilliam Gibson |
Friday, April 11, 2003
The Usual Pattern For... Creating a Strongly Typed CollectionPosted 12:48 PMUntil the next version of the .NET Framework (with generics) is released, you might think that you're stuck with framework collections that are typed for elements of type object. Which opens obvious doorways where buglets can slip through. It doesn't have to be that way - here's some basic boilerplate code for assembling a strongly-typed collection. In this case, a collection of Foo:
using System;
using System.Collections;
namespace Servergeek.Collections
{
[Serializable]
public class FooCollection: CollectionBase
{
public int Add(Foo aFoo)
{
return InnerList.Add(aFoo);
}
public void Remove(Foo aFoo)
{
InnerList.Remove(aFoo);
}
public Foo this[int index]
{
get { return (Foo)InnerList[index]; }
}
public void CopyTo(Foo[] target, int index)
{
InnerList.CopyTo(target, index);
}
public bool Contains(Foo element)
{
return InnerList.Contains(element);
}
public int IndexOf(Foo element)
{
return InnerList.IndexOf(element);
}
public void Insert(int index, Foo aFoo)
{
InnerList.Insert(index, aFoo);
}
}
}
Wednesday, April 09, 2003
Implementing Designers for ASP.NET Custom ControlsPosted 1:05 PMMaybe I was just a bit clueless, but when I first started developing custom web controls, I spent a lot of cycles trying to figure out how designers work. Here's the boilerplate example for a custom designer. First, derive a designer class from ControlDesigner. This is more or less what most of my custom control designers look like:
public class MyCtrlDesigner: ControlDesigner
{
internal DataModel GetDataModel()
{
DataModel dm = new DataModel();
// Fill in data model here...
return dm;
}
public override string GetDesignTimeHtml()
{
string result = null;
MyCtrl theCtrl = Component as MyCtrl
if(theCtrl != null)
{
// Render a table with dummy values using the properties
// from the control
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
DataModel model = GetDataModel();
MyCtrlView view = new MyCtrlView();
view.Render(theCtrl, htmlWriter, model);
htmlWriter.Flush();
result = stringWriter.ToString();
htmlWriter.Close();
stringWriter.Close();
}
return result;
}
}
[Designer(typeof(MyCtrlDesigner))]
public class MyCtrl : System.Web.UI.WebControls.WebControl,
IPostBackDataHandler, IPostBackEventHandler, INamingContainer
{
...
}
.NET Framework 1.1 Final is AvailablePosted 12:08 PMIt's here! The redistributable bits are here. As of a few minutes ago, you need to take care with links within the pages - they seem to point you to content that hasn't been updated since the beta.
Forcing a Runtime Version for ASP.NET Web AppsPosted 7:59 AMBrad, guy of .NET, is asking how to force an ASP.NET app to pick a specific version of the runtime. You do this by specifying the ASP.NET ISAPI filter that services your pages. If you pick the 1.0 version, the 1.0 version of the runtime handles your pages - if you pick the 1.X version, well, you get the idea. An article on MSDN describes the details. Tuesday, April 08, 2003
Rotor Community SitePosted 11:50 AMThe Rotor community site is online. [All things distributed] Yahoo! Monday, April 07, 2003
CSP OnlinePosted 9:54 AMTony Hoare's most excellent book, Communicating Sequential Processes is online as a PDF here. Via LtU.
On Repaving...Posted 6:45 AMNow Scoble really is turning into a developer - he had to repave his system, and spent more than a couple of hours getting his system back to par. I'm always loading new code and hardware on my systems, and I've just given up on expecting stability. If living with Alpha and Beta releases has taught me anything, it's that you should always save a checkpoint of your system's basic configuration. I use DeployCenter from PowerQuest - it takes me very little time to roll back to either a clean OS install or my basic configuration (XP, Word, etc.) It's brain-dead easy to use, reliable, quick, and stays the hell out of the way when I'm not using it. Very recommended.
|