Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NETLink Q: How Create Array of specified Type?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47662] Re: NETLink Q: How Create Array of specified Type?
  • From: Todd Gayley <tgayley at wolfram.com>
  • Date: Wed, 21 Apr 2004 05:23:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

At 07:57 PM 4/19/2004, ToolmakerSteve wrote:
>Todd,
>
>NetLink version 1.0 automatically creates arrays of primitive types:
>
>MakeNETObject[ {11, 22, 33} ]
>=> NETObject[System.Int32[]]
>
>but I haven't found a way to specify the type of an array,
>so I can fill that array with values.
>
>Need to do this, so that I can invoke some advanced methods in CodeDOM,
>with parameters of arrays of particular CodeDOM types.
>
>Ironically, I couldn't use Reflection on class Array to work around this,
>because to locate the CreateInstance method I needed an array of Types.
>A "circular" difficulty!
>
>I can do this:
>MakeNETObject[ {GetTypeObject[ LoadNETType[ "System.Type" ] ],
>     GetTypeObject[ LoadNETType[ "System.Int32" ] ]} ]
>
>=> NETObject[System.Object[]]
>
>Now how do I turn this into a
>
>NETObject[System.Type[]]


Steve,

MakeNETObject allows you to specify the type of the resulting .NET object 
by supplying a type specification as the second argument. Here is an 
example for your integer array:

In[1]:= MakeNETObject[{11, 22, 33}, "System.Byte[]"]  (* default is 
Int32[], but we want Byte[] *)

Out[1]= <<NETObject[System.Byte[]]>>


Here is how it looks for your Type array:

In[2]:= MakeNETObject[ {GetTypeObject[ LoadNETType[ "System.Type" ] ],
              GetTypeObject[ LoadNETType[ "System.Int32" ] ]} 
,  "System.Type[]"]

Out[2]= <<NETObject[System.Type[]]>>


Just for the record, you can also do this manually (although MakeNETObject 
is specifically designed to relieve programmers of this tedium):

In[3]:= arr = MakeNETObject["System.Type[]", 2];

In[4]:= arr@SetValue[GetTypeObject[ LoadNETType["System.Type"], 0];

In[5]:= arr@SetValue[GetTypeObject[ LoadNETType["System.Int32"], 1];



Todd Gayley
Wolfram Research







  • Prev by Date: Re: Max Consecutive Occurrence.
  • Next by Date: Re: How to convert a flat scan of a 3D object, into a 3D picture in cylindrical coordinates?
  • Previous by thread: Re: NETLink Q: How Create Array of specified Type?
  • Next by thread: How to convert a flat scan of a 3D object, into a 3D picture in cylindrical coordinates?