Thom Lawrence

Entries tagged as ‘.net’

XNA Studio 3.0 under Parallels

September 28, 2008 · No Comments

Still no joy with the new beta. Any VMWare Fusion peeps have any luck?

Categories: Gaming · Programming
Tagged: , , ,

Perfidy: Performance Testing In NUnit

September 17, 2006 · No Comments

Unsatisfied with calling QueryPerformanceCounter and being done with it, I spent today coming up with a fluent interface for performance testing in NUnit:

using (At.Most(5).Seconds)
{
    // Stuff that should take under 5 seconds
}

using (At.Most(1).Minute.GiveOrTake(10).Seconds)
{
    // Stuff that should take under 70 seconds
}

Using.At.Most(10).Seconds.For(1000).Iterations.Do(delegate()
{
    // Stuff that should take under 10 seconds for 1000 iterations
});

Using.At.Most(5).Seconds.For(20).Threads.Do(delegate()
{
    // Stuff that should take under 5 seconds when run inside
    // 20 parallel threads
});

It’s basically a wrapper around NUnit’s Assert.Less() and I call it Perfidy (which I thought was a good word for code that treacherously refuses to pass its tests). You can grab a very rough version here: Perfidy.zip

I suppose this kind of thing doesn’t really qualify as unit testing, and it’s not deterministic. But if you’re fairly generous with the limits and get your tests up and running early in a project, you at least know vaguely where you’re going to suffer.

I’ve not included any tests for the tests. I wasn’t sure if NUnit gives you a way to say ‘give me a green bar if this test fails’, and to test everything takes a fair coffee break, as there are lots of Thread.Sleep()s around. If anyone spots anything obviously wrong, or knows of another library that does the same sort of thing, I’d love to hear about it. Especially if it has pretty syntax. :)

Categories: C# · Code · Programming
Tagged: , , , ,

NHibernate-friendly Types

September 11, 2006 · No Comments

It’s probably a combination of laziness and plain bad form to try and map too many BCL types to your database, but if you’re interested, I’ve gone through a few important assemblies and compiled a list of classes that:

  • Are visible outside their assembly
  • Are neither abstract nor sealed
  • Are non-generic
  • Have a public or protected parameterless constructor

My assumptions might be wrong here, but I expect this to be enough for NHibernate to be able to save objects of those classes, and more importantly load and proxy them.

This is the list: PersistableTypes.txt. And here’s the code:

class Program
{
        static void Main(string[] args)
        {
            foreach(string assemblyName in GetAssemblyNames())
            {
                Assembly assembly = Assembly.Load(assemblyName);
                Type[] types = assembly.GetTypes();
                foreach (Type t in types)
                {
                    if (IsProxiable(t))
                        Console.WriteLine(t.FullName);
                }
            }
        }

        private static string[] GetAssemblyNames()
        {
            return new string[]
            {
                "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
                "System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
                "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
                "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            };
        }

        private static bool IsProxiable(Type t)
        {
            return !t.IsAbstract && !t.IsSealed && t.IsVisible && !t.IsGenericType
                && HasProxiableInitializer(t);
        }

        private static bool HasProxiableInitializer(Type t)
        {
            return Array.Exists(t.GetConstructors(),
                IsProxiableInitializer);
        }

        private static bool IsProxiableInitializer(ConstructorInfo ctor)
        {
            return ctor.GetParameters().Length == 0 &&
                (ctor.IsPublic || ctor.IsFamily);
        }
    }

Should be some fun stuff in there - I wonder if a Web Form and the complete hierarchy of its controls can be persisted nicely?

Categories: C# · Code · Programming
Tagged: , , ,

ObjectSpaces Xml Documentation

September 11, 2006 · No Comments

Does anyone else have System.Data.ObjectSpaces.xml in their Framework\v2.0.50727 directory?

I’ve never had the ObjectSpaces bits on this machine, so I assume this is just a standard bit of cruft that comes with the framework.

Anyhow, I know Paul Wilson drew a lot of inspiration from ObjectSpaces, and while the documentation’s mostly filler text, I thought I’d attach it here just incase nobody’s noticed this historical footnote hanging around on their machine.

System.Data.ObjectSpaces.xml

Categories: Programming
Tagged: ,

We Don’t Sell Software, We Sell Experiences! (Currently in Beta)

April 19, 2005 · No Comments

Amidst all the excitement, it’s easy to forget that anybody in Microsoft’s vast, sprawling EMEA Region won’t be able to get Beta 2 until April 25th. Unless you have an MSDN Universal subscription, of course. Which most of you do, you tarts.

What I’ve seen of Whidbey is great. I saw Scott Guthrie on his whistle-stop European tour a few months ago and some of the productivity stuff is like black magic. People will moan that they should be able to have an MSDN Maximum Extreme edition that gets them not only every possible configuration of Visual Studio, but also access on a deep, quantum level, to the inner workings of Microsoft’s best minds, enterprise programmers will continue much as they have before. But what’s a real crime is that the Express products won’t be free. There’s no real reason to give them away, I suppose. They’re great products. I’m not even convinced that my Enterprise Developer edition of 2003 is any better than the Web, C# and SQL products combined. But I can only image how exciting it would have been to see hobbyists everywhere rediscovering programming. I’m still amazed by the number of communities that remain interested in Microsoft’s last free development environment, QBasic. Sure, most people with their copies of Design Patterns and Code Complete vomit a little every time they think of QBasic and Visual Basic and having FUN while programming. But unless the Express Editions get bundled as a throwaway extra with your new laptop (like OneNote), most people are never going to use them (like OneNote). And I think that’s a huge opportunity missed.

Categories: Programming
Tagged: ,

Dispatch .NET And Ajax To Bring Back His Body

April 15, 2005 · No Comments

Ajax.NET looks fun, but he who wishes to share code only with partners must obfuscate his work.

Categories: Programming
Tagged: ,