Does anyone have a code sample showing how you reflect upon a random c# class from an arbitrary .NET assembly using IronRuby? I am most interested in listing the public methods and properties from a random C# class and .NET assembly.
I have tried to load "System.Reflection" from IronRuby. I can't seem to find a good code sample for doing this.
I know that Ruby can explore the meta data related to a class as well. I, however, can't seem to load my test assembly. (i.e. Test.dll)
Any help that you can offer would be helpful.
In order to load your Test.dll you will just need to
require 'Test'
assuming its visible to your script.You can use the built-in Ruby method
public_instance_methods
but this will include those from Ruby's Object class, e.g.:If you are only interested in the methods of your CLR type then you can access the Type of a given object through the IronRuby
to_clr_type
method. This gives you access to all the reflection methods that System.Type offers. For example, the following script will list all the public instance methods of a class Test.MyClass in Test.dll: