About Monkey 2 › Forums › Monkey 2 Programming Help › TypeInfo
Tagged: TypeInfo
This topic contains 4 replies, has 2 voices, and was last updated by
abakobo
1 year, 9 months ago.
-
AuthorPosts
-
June 25, 2017 at 2:35 pm #8913
I can’t figure out how to use TypeInfo. I’ve seen the reflexion test but…
How would i get the kind the kind or array element or…. here is a look at my failing attemts
[/crayon]Monkey123456789101112[crayon-5cba1668c55e3893931268 inline="true" ]Namespace myapp#Import "<std>"#Import "<reflection>"Using std..Function Main()Local i:=2Print i.TypeInfo.Kind()Print TypeInfo.GetType( "myapp.i" ).Kind()EndJune 25, 2017 at 10:18 pm #8921Have you looked at the reflection section in the language manual? This shows the correct use of TypeOf and TypeInfo.
(you may need to grab the latest github develop branch, this may have only recently been added).
June 26, 2017 at 10:34 am #8937I only see how to do it with user defined types..
TypeInfo also includes functions for inspecting all user defined types:
Function TypeInfo.GetType( name:String )
Returns the TypeInfo for a named type. A named type is a namespace or class declared by your app – it does not include primitive types, pointer types, array types etc. Class names must be prefixed by the namespace they are declared in.
To get an array of ALL named types:
Function TypeInfo.GetTypes:TypeInfo[]()
But can we have type info for simple pointers, array…? Some public properties (ArrayRank, PointeeType,..) let me think so but maybe TypeInfo is for user defined only.
June 27, 2017 at 12:34 am #8943But can we have type info for simple pointers, array…?
Still not sure what you mean – this works (as per docs):
Monkey12345Print Typeof< Int[] >Local p:Int PtrPrint Typeof( p )What are you trying to do is the 64k Q?
June 27, 2017 at 10:11 am #8954My bad. I though Typeof was just returning a string.. Was missing the first lines of the reflexion docs.
what I was looking for was:
[/crayon]Monkey123456789101112131415[crayon-5cba1668d1097011479080 inline="true" ]Namespace myapp#Import "<std>"#Import "<reflection>"Using std..Function Main()Local arr:=New Int[15,25]Local typ:=Typeof (arr)Print typ.ArrayRankEnd -
AuthorPosts
You must be logged in to reply to this topic.