Skip to content

{ Monthly Archives } May 2009

XAttribute and null values

It turns out that for whatever the reason to the constructor for XAttribute does not accept null values for the value parameter. I think this makes sense even though the XElement constructor will accept null values for the value parameter – mostly because it can still function; a null value for an attribute would be nothing not ‘attributeName=”"‘.

The quick and dirty: there’s an easy solution, use an extension method.
[code lang="csharp"] public static class AddXAttribute
{
public static XElement NewXAttribute(this XElement xa, XName name, Object value)
{
if (xa != null && value != null)
{
xa.Add(new XAttribute(name, value));
}
return xa;
}
}[/code]

VirtualPathProvider for Assemblies

The VirtualPathProvider class provides some options when building websites. One of the most common is to be able to server ASPX/ASCX requests from embedded resources in an assembly. A good place to start is from a CodeProject article that address this issue. First, instead of using hardcode assemblies/paths/etc, a few properties were attached. #region Properties [...]