Re: Opposite of typeof /GetType()
- From: "pipo" <nomail@xxxxxx>
- Date: Mon, 10 Mar 2008 17:03:46 +0100
Sorry, if I misunderstood your question.
public class Foo<T>
where T : new()
{
protected T bar()
{
return new T();
}
}
public class SuperFoo : Foo<SuperFoo>
{
//Class code
}
SuperFoo super = new Foo<SuperFoo>().bar();
"Ade" <madge@xxxxxxxxxxx> schreef in bericht
news:b0046e01-9c4e-4cba-8bb6-5eb02cf9dd16@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Whereas typeof gets a Type from a class, I need to get a class from a
Type so that I may create the type at runtime.
Imagine if you wil
class foo
{
public foo bar()
{
foo newFoo = new GetType();
// Some magic goes here
return newFoo;
}
}
What would be the syntactically-correct way to do this? I want to
create, from the base class, a new instance of whatever type the
instance of foo is. eg calling bar() on
class superfoo : foo
will give me something unboxable to a superfoo.
.
- References:
- Opposite of typeof /GetType()
- From: Ade
- Opposite of typeof /GetType()
- Prev by Date: IEnumerator in a Struct
- Next by Date: Re: IEnumerator in a Struct
- Previous by thread: Re: Opposite of typeof /GetType()
- Next by thread: Translate to C#
- Index(es):
Relevant Pages
|