Developmentor's Conference.NET quotes (Don Box)

Brian A. LaMacchia bal@farcaster.com
Mon, 13 Aug 2001 19:01:53 -0700


----- Original Message -----
From: "Rohit Khare" <Rohit@KnowNow.com>
To: <FoRK@xent.com>
Cc: <fielding@ebuilt.com>; <dbox@develop.com>
Sent: Monday, August 13, 2001 2:19 PM
Subject: Developmentor's Conference.NET quotes (Don Box)


> A runtime initalizer cannot call a member function. Is this a good or
> bad thing? I don't know.
> By which he means that in C# you can't have:
>
> public class Bob {
> public int x = g();
> int g() {return 3;}
> }

Note, however, that you can do this with static fields and methods; they'll
be run by the static class initializer at some point before the first access
to an instance of the object.  So

public class Bob {
    public static int x = g();
    static int g() { return 3; }
    public int foo() {
        return x;
    }
}

is valid C#.

> Another point on namespaces. In Java, the com.sun.foo stuff was both
> used as a disambiguator of foos AND an encapsulator for packaging
> instances.

Another point that sometimes confuses folks is that namespace in C# are
completely orthogonal to assemblies, which are the code distribution units.
There's no enforced mapping between namespaces, file layout on disk, and
assembly contents.  The type name in your C# code ends up being compiled
into a cryptographically-strong reference to an assembly/type combination.
This is why a fully-qualified reference to a Type (such as something you'd
pass to Type.GetType) shows up as something like:

"System.Security.Cryptography.Xml.XmlDsigC14NTransform, System.Security,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null,
Version=1.0.3210.0"

which is a namespace-qualified type name
(System.Security.Cryptography.Xml/XmlDsigC14NTransform) followed by a
pointer to a strongly-named assembly (System.Security.dll, signed w/ key
with token b0...3a, with culture & version as specified).  A little awkward
to type, perhaps, but you know you're getting what you asked for...

                    --bal