If I create a .Net Object for example here a Rectangle:
R←⎕NEW Rectangle (10,10,10,10)
How can I use the .GetType property to verify if it's a Rectangle Object programmatically ?
R.GetType
System.Drawing.Rectangle
⍝ How to make work the following line ?
'System.Drawing.Rectangle' ≡ R.GetType
0
Thanks in advance,
Pierre Gilbert
How to Use .GetType in a Function ?
Re: How to Use .GetType in a Function ?
In the wonderful world of .NET objects
R.GetType is again an instance of a .NET object with attendant properties and methods.
(R.GetType).GetType
System.RuntimeType ⍝ visible result coerced by application of its method ToString
R.GetType
System.Drawing.Rectangle ⍝ visible result coerced by application of its method ToString
'System.Drawing.Rectangle' ≡ R.GetType.ToString ⍝ explicit excavation to string
1
Never leave well enough alone, on to Moscow ---
you can simply leave off the quotes on the left hand side to specify a System.RuntimeType of System.Drawing.Rectangle
and test it for equivalence with the System.RuntimeType produced by R.GetType without harming or abusing any strings ...
System.Drawing.Rectangle ≡ R.GetType ⍝ explicit matching of System.RuntimeType(s)
Hope this helps
Ross Hale
R.GetType is again an instance of a .NET object with attendant properties and methods.
(R.GetType).GetType
System.RuntimeType ⍝ visible result coerced by application of its method ToString
R.GetType
System.Drawing.Rectangle ⍝ visible result coerced by application of its method ToString
'System.Drawing.Rectangle' ≡ R.GetType.ToString ⍝ explicit excavation to string
1
Never leave well enough alone, on to Moscow ---
you can simply leave off the quotes on the left hand side to specify a System.RuntimeType of System.Drawing.Rectangle
and test it for equivalence with the System.RuntimeType produced by R.GetType without harming or abusing any strings ...
System.Drawing.Rectangle ≡ R.GetType ⍝ explicit matching of System.RuntimeType(s)
Hope this helps
Ross Hale
Re: How to Use .GetType in a Function ?
Thanks RossHale for your answer, the .GetType.ToString is doing the trick for me.
I have this follow-up question: If R becomes NULL, when I do a .GetType I get a VALUE ERROR. What do I need to do to test if a .Net object is NULL ? ⎕null ≡ R does not work.
Pierre Gilbert
I have this follow-up question: If R becomes NULL, when I do a .GetType I get a VALUE ERROR. What do I need to do to test if a .Net object is NULL ? ⎕null ≡ R does not work.
Code: Select all
R
(NULL)
⎕null ≡ R
0
Pierre Gilbert
Re: How to Use .GetType in a Function ?
R
(NULL)
'(NULL)'≡⍕R
1
R←⎕new Rectangle (10 10 10 10)
'(NULL)'≡⍕R
0
I usually put guards or error trapping to handle this sort of thing, but this should fly.
Ross
(NULL)
'(NULL)'≡⍕R
1
R←⎕new Rectangle (10 10 10 10)
'(NULL)'≡⍕R
0
I usually put guards or error trapping to handle this sort of thing, but this should fly.
Ross
Re: How to Use .GetType in a Function ?
Many thanks again RossHale, '(NULL)'≡⍕R is what I was looking for.
Pierre Gilbert
Pierre Gilbert
Re: How to Use .GetType in a Function ?
In general, using thorn is the same as using the .ToString method.
Thus
'System.Drawing.Rectangle' ≡ R.GetType.ToString
is the same as
'System.Drawing.Rectangle' ≡ ⍕R.GetType
/Dan
Thus
'System.Drawing.Rectangle' ≡ R.GetType.ToString
is the same as
'System.Drawing.Rectangle' ≡ ⍕R.GetType
/Dan