Home > Posts > Why I don’t see static extension support for constructors in C# coming

Why I don’t see static extension support for constructors in C# coming

I was hoping C# would someday add static extension support for constructors too (apart from classic methods), that would help a lot in source-level compatibility layers (for example at my WPF_Compatibility project for WPF syntax in Silverlight, which one can find under the ClipFlair source base).

However, according to :

http://mrpmorris.blogspot.gr/​2007/01/​net-calling-base-constructors-i​n-c.html

Anders Hejlsberg (father of Delphi and C#) said in an e-mail:

The problem with Delphi’s model allowing constructors to be called on an already constructed object) is that it makes it impossible to have provably immutable objects. Immutability is an important concept because it allows applications to hand objects to an external party without first copying those objects and still have a guarantee that the objects won’t be modified. If constructors can be called on already constructed objects it obviously isn’t possible to make such guarantees. In Delphi’s case that may be ok since Delphi doesn’t really make type safety guarantees anyway (you can cast any object reference to a pointer-to-something and start poking away), but .NET goes further with type safety and this would be a big hole.

He was replying on why one can’t call an ancestor’s constructor directly in C#, but I guess this covers the case of injecting more constructors into ancestors via the static extension method mechanism of recent C# versions.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: