October 2007 Blog Posts
XmlDocument fluent interface
I do a lot of backend programming for Flash frontends. That basically means a lot of ASPX pages that simply return some XML and accept some incoming XML for parameters. Most of the UI logic ends up getting cluttered with manual XML stringbuilding, so I saw this as an obvious opportunity to play around with a fluent interfaces. Now, here's an example of a typical boolean yes/no result from a Flash query: <?xml version="1.0" encoding="utf-8"?>
<root>
<result type="boolean">true</result>
</root>
I'd usually create this bit of XML using a simple StringBuilder like so:
StringBuilder output = new StringBuilder();
output.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
output.Append("<root>");
output.Append("<result type=\"boolean\">true</result>");
output.Append("</root>");
This has the advantage...
Accessing my privates
Recently I was developing a couple of simple ORM classes that had me confused. [Serializable]
public class Domain
{
// Read
private int domainID;
public int DomainID { get { return domainID; } }
private string domainName;
public string DomainName { get { return domainName; } }
// Read/Write
public int? CompanyID;
}
Take this simple object as an example. It represents a website domain, it has an ID from the database aswell as a read only domain name and a belonging CompanyID.
Now, I want to create a Load() function that given a domain ID will instantiate a new instance of a Domain object and populate its values from the...
Handling DBNulls
Reading and writing values to the DB has always been a bit cumbersome when you had to take care of nullable types and DBNull values. Here's a way to make it easy. Based on this post by Peter Johnson and this post by Adam Anderson I gathered a couple of ideas and combined them to make a completely generic class that will handle DBNulls for both reads and writes, as well as handling nullable types. Let me present the code, I'll go over it afterwards: public static class DBConvert
{
/// <summary>
/// Handles reading DBNull values from database in...
|