generics question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PJ6

    #1

    generics question

    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


  • Tom Shelton

    #2
    Re: generics question

    On May 3, 8:53 am, "PJ6" <n...@nowhere.n etwrote:
    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
    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.Creat eInstance to work around the problem (since it
    can call non-public constructors :)

    --
    Tom Shelton

    Comment

    • PJ6

      #3
      Re: generics question

      "Tom Shelton" <tom_shelton@co mcast.netwrote in message
      news:1178207044 .372217.100600@ o5g2000hsb.goog legroups.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.Creat eInstance to work around the problem (since it
      can call non-public constructors :)
      Mmm, forgot about Activator.Creat eInstance.

      Thanks, that will do the trick as far as keeping my design the way I want it
      :)

      Paul


      Comment

      Working...