More trivia than really important: Why no new() constraint on Activator.CreateInstance<T>() ?
Posted
by
flq
on Stack Overflow
See other posts from Stack Overflow
or by flq
Published on 2011-03-03T23:19:56Z
Indexed on
2011/03/03
23:24 UTC
Read the original article
Hit count: 268
I think there are people who may be able to answer this, this is a question out of curiosity:
The generic CreateInstance method from System.Activator, introduced in .NET v2 has no type constraints on the generic argument but does require a default constructor on the activated type, otherwise a MissingMethodException is thrown. To me it seems obvious that this method should have a type constraint like
Activator.CreateInstance<T>() where T : new() {
...
}
Just an omission or some anecdote lurking here?
© Stack Overflow or respective owner