Re: Cast generic IFoo<T> : last level (I hope)



On Fri, 25 Jul 2008 05:29:01 -0700, Alphapage <Alphapage@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hello again,

My last question which opened a big debate about casting such a generic
interface learned me a lot, but I can't find a way because of my particular
generic interface.
I will shown you my code, but when you will answer my post, don't write:
- he is stupid (I already know)
- this is not Object Oriented
- generic is not made for that ...

Okay, I won't. :) Especially the first...I try very hard to never write things like that even when I know them to be true, and there's nothing here to suggest it is.

On the other two points, I guess it just remains to be seen. As Jon says, I don't think this code example clears things up much, if at all. In addition to his comment, I'll point out that I've never seen correct code where the type parameter is constrained to inherit the type in which it's being used.

It's possible that there's some esoteric use of generics that I'm unfamiliar with where it comes up, but the few times I've played around with that construct myself, I've gotten nowhere and coded myself into logical impossibilities. If you're sure that that's the right tack to take, you need to at least elaborate on _why_ you're declaring your generic classes that way.

Pete
.



Relevant Pages

  • Re: Fun with generics
    ... description of the purpose of generics. ... so what you need to communicate is the type parameter to ... public interface Table ... using ArrayList is that if someone wants to create a Foo that only works ...
    (comp.lang.java.programmer)
  • Re: how to find the type of an object represented by an interface
    ... Simplifying, generics are strictly linked to compilation, not runtime. ... template parameter T must implement particular interface i.e. IDisposable: ... Readonly property MaximumRange() as Integer ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: .NET 2.0 to be launched on Nov 8
    ... Generics in .NET don't need interfaces to work, ... >> and probably Delphi for Win32 RSN. ... > - I also wonder if you can parameterise a template with an interface. ...
    (borland.public.delphi.non-technical)
  • RE: Generics in .NET 2.0 SUCK
    ... The reason Generics in .NET 2.0 SUCK? ... when you specify a type parameter without ... probably there is a way to specify a method constraint for T ... > My second thought was that there might be some interface like IArithmetic. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Casting Generic Classes - Possible Solution
    ... It leaves me with the open option to use generics or not when I ... This works as saying "accept a store of anything that are Record ... public class Record { ... So I tried adding an interface into the structure: ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast