[class question] - get parent object typeof()

Monkey Forums/Monkey Programming/[class question] - get parent object typeof()

GC-Martijn(Posted 2011) [#1]
In C# I can use typeof() or better something like this:
if(myObject is Int32){

}

Now look at this example, what i'm trying to do.
Class A and C are normal, but inside B I want to do more.
I want that B can handle or do things when the parent class is a typeof something.

Class A
	Field child:B
	Field test:String = "hello I am A"
	Method New()
		child = New B()
	End
End

Class C
	Field child:B
	Field somethingElse:String = "hello I am C"
	Method New()
		child = New B()
	End
	Method Bla:Void()
	 print "hi"
	End
End



Class B
	Field parent:Object
	Method New(Aparent:Object)
		parent=Aparent
		If parent is B
		  Print parent.test
		Endif
		If parent is C
		  Print parent.somethingElse
		  parent.Bla()
		Endif

                If parent == typeof(B)
		  Print parent.test
		Endif
	End
End


is this possible in monkey, or do I think wrong ?


Jesse(Posted 2011) [#2]
I believe is like this:
if b(parent)
   print parent.test
endif



GC-Martijn(Posted 2011) [#3]
I see, but that din't work but did does
if b(parent)
   print b(parent).test
endif


thanks


Skn3(Posted 2011) [#4]
You should use a temporary local pointer as each time you do class(object) it has to do a look up.

Eg
local point := b(parent)
If point point.test()



Samah(Posted 2011) [#5]
@Skn3 I assume you meant:
local point := B(parent)
If point point.test()

;)


Skn3(Posted 2011) [#6]
hahah yes i did.. correcting now!


GC-Martijn(Posted 2011) [#7]
yes working, thanks