public void TestBoxExtensionIronRuby() { NovaClass strb = global::Nova.Nova.Box(typeof(StringBuilder)); var engine = GetRuntime().GetEngine("Nova"); var defsource = engine.CreateScriptSourceFromString( "def AppendFromNova() { self.Append('Appending from Nova extension method!'); };"); var defscope = engine.CreateScope(); defsource.Execute(defscope); NovaClass.AddMethod(strb.InstanceMethods, defscope.GetVariable("AppendFromNova")); var scope = engine.CreateScope(); scope.SetVariable("StringBuilder", strb); var str = new StringBuilder("Hello world! "); var strx = global::Nova.Nova.Box(str, new NovaScope(scope)); var rubyengine = GetRuntime().GetEngine("IronRuby"); var rubysource = rubyengine.CreateScriptSourceFromString("strx.AppendFromNova(); strx.ToString();"); var rubyscope = rubyengine.CreateScope(); rubyscope.SetVariable("strx", strx); Assert.That((string)rubysource.Execute(rubyscope), Is.EqualTo("Hello world! Appending from Nova extension method!")); }
public void TestCSharpClassExtend() { NovaClass strb = global::Nova.Nova.Box(typeof(StringBuilder)); var engine = GetRuntime().GetEngine("Nova"); var defsource = engine.CreateScriptSourceFromString( "def AppendFromNova() { self.Append('Appending from Nova extension method!'); };"); var defscope = engine.CreateScope(); defsource.Execute(defscope); NovaClass.AddMethod(strb.InstanceMethods, defscope.GetVariable("AppendFromNova")); var source = engine.CreateScriptSourceFromString( "str.AppendFormat('{0} world! ','hello'); str.AppendFromNova(); str.ToString();"); var scope = engine.CreateScope(); scope.SetVariable("str", new StringBuilder()); scope.SetVariable("StringBuilder", strb); Assert.That(source.Execute(scope), Is.EqualTo("hello world! Appending from Nova extension method!")); }