I’ve now written 4 cms’ and have decided as a personal project to create a core system that can easily be adapted to many tasks. Over the past 4 cms’ I’ve used the same code a lot and created a central core of utils (imaginatively called Gist!) but I want to go a step further and have a central system I can use straight off.
Read more…
Found this is microsoft official line on creating a singleton, much simpler than the normal GOF way
// .NET Singleton
sealed class Singleton
{
private Singleton() {}
public static readonly Singleton Instance = new Singleton();
}
In my cms’ I usually have the option of creating controls from the database. This is just a simple use for reflection but allows me to add controls to page just by adding a new row. If its one of my controls it supports a persistance system that allows the control to save and restore itself easily.
Read more…
Keeping tree data in a database can be a nightmare. There are a number of techniques to achieve it but they are all either unwieldy on the sql side (multiple joins) or on the data side (binary trees). I needed an easy way to render a tree out in a single read from the db.
I achieved this by just having a path field in the table, ordering by it and then dumping it out with the following routine. Needs more work but ok for the mo
Would need to change to writer instead of StringBuilder and I need to sort out the items that appear at the top (would appear under the folders in a treeview) Read more…
This is one of those things that is so obvious I wonder why it never occured to me before! If you declare a member as static the compiler only creates one member instance across all class instances.
class ClassWideStatic
{
protected static int NoOfInstances;
public ClassWideStatic()
{
//setting NoOfInstances here will set it on ALL instances
//effectively resetting it, but modifying it is fine
NoOfInstances += 1;
}
static ClassWideStatic()
{
//This is a special constructor that is only called when
//the first instance is created
NoOfInstances = 1;
}
}
When we create a class we get given a default blank constructor which is provided by the framework. Its equivalent to
We can create constructors with different parameters:
public ClassName(int One)
{
this.One = One;
}
public ClassName(int One, string Two)
{
this.One = One;
this.Two = Two;
}
Read more…