473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using GetType() inside a generic?

Can't I do some syntactic sugar like this?:

MyClass MyObject = new MyClass();
MyStaticClass.MyMethod<MyObject.GetType()>();

Thanks in advance.

--
Oct 4 '06 #1
2 2715
Ympostor wrote:
Can't I do some syntactic sugar like this?:

MyClass MyObject = new MyClass();
MyStaticClass.MyMethod<MyObject.GetType()>();
And what's wrong with...

MyClass MyObject = new MyClass();
MyStaticClass.MyMethod<MyClass>();

Remember that generic classes are built out when the code is JITed --
before it is run. If you don't know the type until runtime, you can't
use a generic.

Oct 4 '06 #2
ja**********@gmail.com wrote:
Remember that generic classes are built out when the code is JITed --
before it is run. If you don't know the type until runtime, you can't
use a generic.
You can with reflection:

http://msdn2.microsoft.com/en-us/lib...nerictype.aspx

--
Andreas Huber

When replying by private email, please remove the words spam and trap
from the address shown in the header.

Oct 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Douglass | last post by:
I'm confused about the program below. Based on my reading of the C# spec, I don't think it should compile, but it does when using Beta 1. Could somebody please explain the function selection...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
1
by: Hotlips | last post by:
I'm trying to use an SoapFormatter with a generic List (List<int>) (.NET 2.0) When I use it I get an exception that states that the collections from Generic-namespace cannot be used with the...
3
by: Joe Adams | last post by:
Hi All, How can I use GetType(<GenericType>).IsAssignableFrom(<MyType>) I need to now if the <MyType> is the same type of class as the <GenericType> without having to add the generic type...
0
by: crazyone | last post by:
I've got a gaming framework i'm building and i want to save myself the trouble of reading and writting the complete game data to a custom file and load/save it to an XML file but i'm getting...
4
by: Steph | last post by:
hello, i want to find the type from a generic... like : public static john<T>(object obj, T myControl) { ((myControl.getType())myControl).OnClientClick ="code"; } because my generic var can...
4
by: =?Utf-8?B?SGF5U2VlZA==?= | last post by:
Is there some way to use Generics in dynamic code using the Type.GetType("MyClassName") as an argument? List<Type.GetType("MyClassName") oList = new List<Type.GetType("MyClassName") > ...
1
by: Jon Slaughter | last post by:
Type asdf = Type.GetType(t.GetType().FullName); How come something like that returns a null type when t is a generic type? It works fine for non-generic types.
2
by: jon | last post by:
I'm trying to write a block of code that can create an instance of a generic object, with the Type coming in as a dynamic string. It isn't working yet. Any advice how I can dynamically create the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.