|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
generics questionI just stumbled across an apparent generics limitation that I don't
understand. In a generic class's type list, why can't the compiler be made aware of the types' contructors? Right now the compiler can only pay attention to the New declaration to get its contructor logic, and as such, only call paramaterless constructors. It strikes me as unnecessarily restrictive, and I wonder what the reason behind that was. Paul On May 3, 8:53 am, "PJ6" <n***@nowhere.net> wrote: While I don't know the reason, I agree with you that it seems> I just stumbled across an apparent generics limitation that I don't > understand. In a generic class's type list, why can't the compiler be made > aware of the types' contructors? Right now the compiler can only pay > attention to the New declaration to get its contructor logic, and as such, > only call paramaterless constructors. It strikes me as unnecessarily > restrictive, and I wonder what the reason behind that was. > > Paul restrictive. Not only can it only call parameterless constructors, it can only call them if they are public. To be honest though, the couple of times that this has been an issue for me, I have been able to use Activator.CreateInstance to work around the problem (since it can call non-public constructors :) -- Tom Shelton "Tom Shelton" <tom_shel***@comcast.net> wrote in message Mmm, forgot about Activator.CreateInstance.news:1178207044.372217.100600@o5g2000hsb.googlegroups.com... > While I don't know the reason, I agree with you that it seems > restrictive. Not only can it only call parameterless constructors, it > can only call them if they are public. To be honest though, the > couple of times that this has been an issue for me, I have been able > to use Activator.CreateInstance to work around the problem (since it > can call non-public constructors :) Thanks, that will do the trick as far as keeping my design the way I want it :) Paul |
|||||||||||||||||||||||