Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Daniel O'Connell [C# MVP]" <onyxk...@--NOSPAM--comcast.net>
Date: Sat, 17 Jul 2004 16:17:45 -0500
Local: Sat, Jul 17 2004 5:17 pm
Subject: Re: .NET generics & the .NET framework: not generic enough?
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_...@msn.com> wrote in message > Andreas, Well, you *could* use dynamic methods, assuming you have the permissions: >> Implementing proxies is of course always an option but I think it is a >> really bad one. > I sincerely hope you did not mean "really bad one" as bad as it sounds. > :-| > I agree its not necessarily a good option. However! In light of not having > I would love to hear a "better" work around, that can implemented today, > A second alternative I've wondered how usable would be Generic Delegates, public delegate T Operator<T>(T a,T b); public static Operator<T> CreateAddOperator<T>() { DynamicMethod method = new DynamicMethod("AddMethod" + typeof(T).ToString(), typeof(T), new Type[] { typeof(T), typeof(T) }, typeof(OperatorFactory)); ILGenerator ilg = method.GetILGenerator(); ilg.Emit(OpCodes.Ldarg_0); ilg.Emit(OpCodes.Ldarg_1); if (typeof(T).IsPrimitive) { ilg.Emit(OpCodes.Add); } return (Operator<T>)method.CreateDelegate(typeof(Operator<T>)); I've only tested int and decimal, but it does work for those two. This You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||