0
我想弄清楚如何檢索存儲在Person類中的值。問題在於,在定義Person類的實例後,我不知道如何在IronRuby代碼中檢索它,因爲實例名稱位於.NET部分。在IronRuby中檢索訪問器
/*class Person
attr_accessor :name
def initialize(strname)
self.name=strname
end
end*/
//We start the DLR, in this case starting the Ruby version
ScriptEngine engine = IronRuby.Ruby.CreateEngine();
ScriptScope scope = engine.ExecuteFile("c:\\Users\\ron\\RubymineProjects\\untitled\\person.rb");
//We get the class type
object person = engine.Runtime.Globals.GetVariable("Person");
//We create an instance
object marcy = engine.Operations.CreateInstance(person, "marcy");