[redland-dev] C# cleanup

Dave Beckett dave.beckett at bristol.ac.uk
Wed Jul 14 16:04:53 BST 2004


On Wed, 14 Jul 2004 15:14:05 +0100, Edd Dumbill <edd at usefulinc.com> wrote:

> On Wed, 2004-07-14 at 14:48 +0100, Dave Beckett wrote:
> > 
> > C# stylistically you did
> > 
> > -                       else if ((Object)uri == null)
> > +                       if (uri == (Uri) null)
> > 
> > which I probably do both ways elsewhere.  The reason I cast both of
> > them to null was to prevent a Uri.Equals method being called with a
> > null object (raises an exception) or a null parameter.  It seemed
> > easier to cast to Object and let Object.Equals(null, null) deal with
> > it.  Maybe?
> 
> Hmm, if this really was a problem then the constructor for Query would
> fail in your test.cs, which it doesn't.  In fact we don't need the (Uri)
> cast at all.  if (uri == null) will compile just fine.
> 
> So that change (removal of the cast) can be made in Parser.cs and Query.
> cs.

OK, I've made a test program:

------------------------------------------------------------
using Redland;
using System;

public class Test {
	
  public static void Main ()
    {
      Redland.Node node = null;

      if( node == null) {
        Console.WriteLine("the node is null");
      } else {
        Console.WriteLine("the node is not null");
      }
    }
}
------------------------------------------------------------

save as t.cs in the csharp dir, compile and run:

$ mcs -debug+ t.cs -target:exe -r:Redland.dll -out:t.exe
Compilation succeeded
$ mono t.exe
 
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
in <0x0000b> Redland.Node:op_Equality (Redland.Node,Redland.Node)
in <0x00018> Test:Main ()
 
$ mono --version
Mono JIT compiler version 1.0, (C) 2002-2004 Novell, Inc and Contributors. www.go-mono.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV      : normal
        Globalization: ICU
$

which is why I did:
   if( (Object)node == null)

Dave



More information about the redland-dev mailing list