Re: Generic type converter class. Cant call static method of type T.
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: 8 May 2007 06:18:09 -0700
On May 8, 2:14 pm, Steve Richter <StephenRich...@xxxxxxxxx> wrote:
On May 8, 1:53 am, Jon Skeet [C# MVP] <s...@xxxxxxxxx> wrote:
Steve Richter <StephenRich...@xxxxxxxxx> wrote:
in a generic class, can I code the class so that I can call a static
method of the generic class T?
No. There's nothing you can do which will guarantee that there will be
a static Parse method in T, so the compiler won't let you call it.
darn! I thought that is what generics/templates were all about? The
compiler plugs in the actual type and then compiles the code.
That's what C++ templates are about - .NET generics aren't the same as
templates. The IL is only generated for the parameterised form of the
type, and then the JIT converts that into native code when it needs to
(roughly speaking, once per value type and once for *all* reference
types).
Couldn't there be a where T: constraint that specifies the static
methods the using class must implement?
It's not inconceivable that it could be in a future version of .NET,
but it's not available now, certainly.
Jon
.
- References:
- Generic type converter class. Cant call static method of type T.
- From: Steve Richter
- Re: Generic type converter class. Cant call static method of type T.
- From: Jon Skeet [C# MVP]
- Re: Generic type converter class. Cant call static method of type T.
- From: Steve Richter
- Generic type converter class. Cant call static method of type T.
- Prev by Date: Re: Does that RegExp makes sense to you, people?
- Next by Date: Re: Repost: VS2005 - is DataGrid.IsSelected( ) broken ? (still an MS 'managed' group?)
- Previous by thread: Re: Generic type converter class. Cant call static method of type T.
- Next by thread: Re: Generic type converter class. Cant call static method of type T.
- Index(es):
Relevant Pages
|