Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

What is the typeof() an array of a Type?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Shemitz - 28 Dec 2004 03:43 GMT
Suppose you have a dynamically loaded assembly, Assembly. Suppose you
enumerate all the types in Assembly with Assembly.GetExportedTypes().
Suppose you are working with

 Type ExportedType;

which you got from Assembly.GetExportedTypes(). What is the type of an
array of elements of the type ExportedType?

(That is, imagine that within the dynamically loaded assembly, there
is a type BaseType, and ExportedType == typeof(BaseType). How do you
get typeof(BaseType[]) if you only have the ExportedType value?)

I have

 internal static Type TypeOfArrayOf(Type AnyType)
 {
   Array A = Array.CreateInstance(AnyType, 0);
   return A.GetType();
 }

- is there anything better?

Signature

programmer, author  http://www.midnightbeach.com
and father          http://www.midnightbeach.com/hs

Jon Skeet [C# MVP] - 28 Dec 2004 10:46 GMT
> Suppose you have a dynamically loaded assembly, Assembly. Suppose you
> enumerate all the types in Assembly with Assembly.GetExportedTypes().
[quoted text clipped - 18 lines]
>
> - is there anything better?

I believe you can get the "normal" type name, put "[]" on the end and
use Type.GetType. Both are very unsatisfactory, of course. Fortunately
in .NET 2.0, there'll be a method called MakeArrayType which is exactly
what you want, but for the moment I think one of the options above is
your only way :(

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jon Shemitz - 28 Dec 2004 20:31 GMT
> >   internal static Type TypeOfArrayOf(Type AnyType)
> >   {
[quoted text clipped - 9 lines]
> what you want, but for the moment I think one of the options above is
> your only way :(

Thanks, Jon. That probably would work, too. You're right that neither
is very nice; I suspect (based on what I remember from the last time I
visited this sort of problem) that the CreateInstance approach is
actually faster than string formatting and GetType.

Signature

programmer, author  http://www.midnightbeach.com
and father          http://www.midnightbeach.com/hs


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.