How to use Reflection
4 posts
• Page 1 of 1
How to use Reflection
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,
⎕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,
-
PGilbert - Posts: 436
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: How to use Reflection
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
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: 413
- Joined: Wed Oct 01, 2008 9:39 am
Re: How to use Reflection
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.
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.
-
JohnD|Dyalog - Posts: 74
- Joined: Wed Oct 01, 2008 9:35 am
Re: How to use Reflection
Thanks John and Vince.
-
PGilbert - Posts: 436
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: Google [Bot] and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group