|
You could always use a Func here. For instance:
GenericMethod<Func<T, TResult>>();
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks Pete,
And what exactly would this Func be or do?
Thanks again!
|
|
|
|
|
This[^] article should help. This type of functionality is the mojo behind Linq.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Good link Pete, very concise.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks Pete, I read your link and it seems this particular feature it's not for C# 2.0, which is preciselly the version i'm working
|
|
|
|
|
What kind of expression that evaluates to a type would you have there? Something with reflection? You could probably use reflection to invoke the method with an expression of the type Type , but I'm not actually sure. Reflection can do a lot though, so why not..
edit: If all else fails, there is still the possibility to compile and run a piece of code that has been generated at runtime. But I wouldn't use that except in emergencies. It's not exactly fast, or a clean design.
|
|
|
|
|
A method which may prove useful is Type.MakeGenericType[^]. I don't fully understand it, but it seems to be a step in the right direction - getting the type of a generic type (without the type specifiers), then calling MakeGenericType on the result to get a dynamically set Type
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Man thanks a lot, it did worked:
Type cons = typeof(List<>).MakeGenericType(Tipo);
object _list = cons.Assembly.CreateInstance(cons.FullName);
+1 for you!
|
|
|
|
|
This code creates a generic type and instatiate an object of that type in runtime using MakeGenericType as Computafreak mentioned. I was going to post it last night but I forgot and fell asleep. But now I know you want it in .net 2.0 I have to remove var and new[]
static void Main(string[] args)
{
Type t = typeof(List<> );
Type gt = t.MakeGenericType(GetTypes());
object gtObj = Activator.CreateInstance(gt);
}
private static Type[] GetTypes()
{
return new Type[] { typeof(int) };
}
But gtObj is returned as an object (but it is a List<int>). The problem is that you will probably have to use reflection.
Eslam Afifi
|
|
|
|
|
|
You're welcome. I read your other post[^] and you don't have to use the FullName of the Type, you can just pass the Type directly which is faster IMHO.
Eslam Afifi
|
|
|
|
|
Yes indeed! I have corrected my code to use the Activator.
Thanks again!
|
|
|
|
|
i am looking for a way to list all the share on a given computer and also list all groups on users who have access and what access they have
|
|
|
|
|
Here[^] you go. There is an article right here[^] at CP.
For the other part, I guess this[^] would help.
|
|
|
|
|
what i am really looking to do is check the total right a users has to a share do i have to find out all the groups they are in and get all the rights for each group and calulate it my self or is there and easier way?
|
|
|
|
|
Hi All,
I accedentailly deleted a Sql Table .Can you give me an Idea how to recover it?
Thanks
|
|
|
|
|
Wrong forum.
Restore the back up if you have taken it.
|
|
|
|
|
I am not good in Sql ? Can you please get me a little bit of hint?
|
|
|
|
|
All i have is a Database.dat file ? is it the one i have to pick up.
|
|
|
|
|
|
How can i restore a database from a *.dat file?
|
|
|
|
|
When you reply to yourself do you get an email saying you have sent yourself a message?
Life goes very fast. Tomorrow, today is already yesterday.
modified on Friday, September 25, 2009 5:14 AM
|
|
|
|
|
Only if you checked the "Send me an e-mail if someone replies to this message" checkbox. You should know that by now.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Huh, I don't think I have ever looked at those option before
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
If a reply falls in a forest do we, existentially, care?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|