How to use Reflection

Using (or providing) Microsoft.NET Classes

How to use Reflection

Postby PGilbert on Mon Dec 01, 2014 1:27 am

Looks like there is 3 ways to obtain information on a .net object using reflection:

⎕using←'' 'System' 'System.Reflection' 'System.Windows.Controls,WPF/PresentationFramework.dll'
dt←⎕NEW DateTime ⎕ts


Method no 1: System.Object.GetType

(dt.GetType.GetProperties ⍬).Name
Date Day DayOfWeek DayOfYear Hour Kind Millisecond Minute Month Now UtcNow Second Ticks TimeOfDay Today Year

This method seems to work all the time for classes that have been instantiated (⎕NC=9.2)

Method no 2: System.Type.GetType

((System.Type.GetType(⊂'System.DateTime')).GetProperties ⍬).Name
Date Day DayOfWeek DayOfYear Hour Kind Millisecond Minute Month Now UtcNow Second Ticks TimeOfDay Today Year

This method seems to work for classes not instantiated (⎕NC=9.6). However it does not work for a Button:

((System.Type.GetType(⊂'System.Windows.Controls.Button')).GetProperties ⍬).Name
VALUE ERROR: No result was provided when the context expected one
((System.Type.GetType(⊂'System.Windows.Controls.Button')).GetProperties ⍬).Name


Method no 3: typeof C# operator

Question 1: Does anyone knows why method #2 does not work all time ?

Question 2: Is there an equivalent of the typeof C# operator in Dyalog Apl ?

Thanks in advance,
User avatar
PGilbert
 
Posts: 361
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to use Reflection

Postby Vince|Dyalog on Mon Dec 01, 2014 3:44 pm

Hi Pierre,

I'll ask my colleague to have a look at your question when he returns and we will get back to you.

Regards,

Vince
Vince|Dyalog
 
Posts: 276
Joined: Wed Oct 01, 2008 9:39 am

Re: How to use Reflection

Postby JohnD|Dyalog on Wed Dec 03, 2014 9:34 am

As per:

http://msdn.microsoft.com/en-us/library/w3f99sx1(v=vs.110).aspx

For the typeName parameter:

"The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace."

The currently executing assembly will be our bridge assembly. So I reckon it will work for those types in mscorlib.dll (and our bridge), but not elsewhere. For types in other assemblies you'll need the full "AssemblyQualifiedName".

Best Regards
John Daintree.
User avatar
JohnD|Dyalog
 
Posts: 60
Joined: Wed Oct 01, 2008 9:35 am

Re: How to use Reflection

Postby PGilbert on Thu Dec 04, 2014 5:57 pm

Thanks John and Vince.
User avatar
PGilbert
 
Posts: 361
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest