Re: Static property of type parameter - is this a CLR or C# limitation?
- From: "Ole Nielsby" <ole.nielsby@xxxxxxxxxxxx>
- Date: Sun, 14 May 2006 23:00:35 +0200
Barry Kelly <barry.j.kelly@xxxxxxxxx> wrote:
[...some insights in generics compilation...]
So, I would say it is a current architectural limitation of the CLR.
Thanks for a detailed explanation.
I'll go for a combination of reflection and static fields. Using
reflection in the class initializer will be faster than cluttering
the constructors with factory parameters, I think.
My SharedPetLover<T> gets a static field that is filled in by
using reflection to get the SharedPet<T> singleton. Or,
expanding on your version:
class A<T>
{
public static T Value
{
get { return default(T); }
}
}
class B<T,U>
where T : A<U>
{
public U Value
{
get { return value; }
}
private static U value =
(U)typeof(U).InvokeMember(
"Value", flags, null, null, null);
const flags =
BindingFlags.GetProperty
| BindingFlags.Public
| BindingFlags.Static
| BindingFlags.FlattenHierarchy;
}
This may complicate the initialization process a bit,
but once it's done I get fast object creation. (I'm
still slightly puzzled that it can't be done without
reflection or factories, but I'll take your words for
that.)
Regards/Ole N.
.
- Follow-Ups:
- Re: Static property of type parameter - is this a CLR or C# limitation?
- From: Barry Kelly
- Re: Static property of type parameter - is this a CLR or C# limitation?
- References:
- Static property of type parameter - is this a CLR or C# limitation?
- From: Ole Nielsby
- Re: Static property of type parameter - is this a CLR or C# limitation?
- From: Barry Kelly
- Static property of type parameter - is this a CLR or C# limitation?
- Prev by Date: Can i call an UDF (user defined function ) on an MSDE2000 server from code ?
- Next by Date: Re: Connection pooling
- Previous by thread: Re: Static property of type parameter - is this a CLR or C# limitation?
- Next by thread: Re: Static property of type parameter - is this a CLR or C# limitation?
- Index(es):