Impacts of new() contraint in C#

“Disecting the new() constraint” is very instructive: new() constraint has a big performance impact and we must know its implementation to understand why ctor exceptions are wrapped to a TargetInvocationException.

Dissecting the new() constraint in C#: a perfect example of a leaky abstraction – Dissecting the code

By the way, in same blog post, I’ve discovered that some well known static functions can be custom replaceable. It means you can locally redefined them. System.Activator.CreateInstance<T> is replaced by a faster one.

Beware, this is a completly not documented behavior than can be theoretically remove any time. Just to mitigate previous remark, this undocumented behavior is so important survived the Roslyn transition.

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s