Missing behavior for dynamic??
Posted: Fri Jul 02, 2010 4:42 am
Hi Chuck and gang,
Hopefully this should illustrate what I'm trying to do. I'm expecting dynamic to do something that it doesn't. I want dynamic to be able to call statics on classes so that I don't have to use InvokeMethod to do it when using dynamically loaded types. Or there is another way??
Cheers.
PS: I've got my tabs=4 and the code block seems to not be indenting correctly. The three comments start "# Is not finding the method on" and the five parameters of invokeMember() should be vertically aligned.
PPS: I tried cobra tags and the tabs were expanded to 8 characters and the lines got chopped off. I guess I need to untabify.
Hopefully this should illustrate what I'm trying to do. I'm expecting dynamic to do something that it doesn't. I want dynamic to be able to call statics on classes so that I don't have to use InvokeMethod to do it when using dynamically loaded types. Or there is another way??
Cheers.
- Code: Select all
use System.Reflection
class Test
def method1
print '1'
def method2 is shared
print '2'
class Program
def main is shared
# As expected.
test1 as dynamic = Test()
test1.method1
test1.method2
# As expected.
Test.method2
# Silly looking, but a simple version of what I really want to do below.
test2 as dynamic = Test
expect Cobra.Lang.UnknownMemberException # Is not finding the method on Type,
test2.method2 # ok, but could/should it look for
# statics on Test as well??
# Using dynamically loaded assemblies...
mono = Assembly.load('Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756')
# ...this is what I really want to do... (minus the expect of course)
unixFileSystemInfo as dynamic? = mono.getType('Mono.Unix.UnixFileSystemInfo')
expect Cobra.Lang.UnknownMemberException
# UnixFileSystemInfo.GetFileSystemEntry() is static.
fileInfo as dynamic? = unixFileSystemInfo.getFileSystemEntry('/usr/local/bin/cobra')
# ...to avoid doing this...
unixFileSystemInfo2 as Type = mono.getType('Mono.Unix.UnixFileSystemInfo')
fileInfo as dynamic? = unixFileSystemInfo2.invokeMember('GetFileSystemEntry',
BindingFlags.Static | BindingFlags.InvokeMethod,
nil,
nil,
['/usr/local/bin/cobra'].toArray)
# Dynamic needs to search for BindingFlags.Static or something?
PS: I've got my tabs=4 and the code block seems to not be indenting correctly. The three comments start "# Is not finding the method on" and the five parameters of invokeMember() should be vertically aligned.
PPS: I tried cobra tags and the tabs were expanded to 8 characters and the lines got chopped off. I guess I need to untabify.