public void DefineAndCallFuncMethod() { IMethod method = new FuncMethod(null, (obj, context, args) => ((string)obj).Length); Assert.IsNull(method.Type); Assert.AreEqual(3, method.Call("foo", null, null)); }
public void RaiseIfMethodIsAlreadyDefined() { IClass type = new BaseClass("String", null); IClass klass = new BaseClass("MyClass", null); IMethod getname = new FuncMethod(type, (obj, context, arguments) => ((IObject)obj).GetValue("name")); klass.DefineMethod("getName", getname); Assert.Throws <InvalidOperationException>(() => klass.DefineMethod("getName", getname)); }
public void Setup() { IClass type = new BaseClass("String", null); this.type = new BaseClass("MyClass", null); IMethod getname = new FuncMethod(null, (obj, context, arguments) => ((IObject)obj).GetValue("name")); this.type.DefineVariable("name", type); this.type.DefineMethod("getName", getname); }
public void GenericSimpleTest4() { GenericMethods2 genericMethods2 = new GenericMethods2(); BeethovenFactory beethovenFactory = new BeethovenFactory(); IGenericMethods instance = beethovenFactory.Generate <IGenericMethods>( FuncMethod.Create("Simple", genericMethods2.SimpleString), FuncMethod.Create("Simple", genericMethods2.SimpleInt), genericMethods2); Assert.AreEqual(5, instance.Simple <int>()); Assert.AreEqual("abcd", instance.Simple <string>()); }
public void GenericSimpleTest2() { BeethovenFactory beethovenFactory = new BeethovenFactory(); IGenericMethods instance = beethovenFactory.Generate <IGenericMethods>( FuncMethod.Create("Simple", () => "abcd"), FuncMethod.Create("Simple", () => 5), FuncMethod.Create("Simple", () => (short)0)); Assert.AreEqual(5, instance.Simple <int>()); Assert.AreEqual(0, instance.Simple <short>()); Assert.AreEqual("abcd", instance.Simple <string>()); }
public void DefineMethod() { IClass type = new BaseClass("String", null); IClass klass = new BaseClass("MyClass", null); IMethod getname = new FuncMethod(type, (obj, context, arguments) => ((IObject)obj).GetValue("name")); klass.DefineMethod("getName", getname); var result = klass.GetMethod("getName"); Assert.IsNotNull(result); Assert.AreEqual(type, result.Type); }
public void TestMethodFallbackMethod1() { int callCount = 0; ITestMethods test = TypeDefinition <ITestMethods> .Create( ActionMethod.Create("Simple", () => callCount++).CreateFallback(), FuncMethod.Create("ReturnValue", () => 5) ) .CreateNew(); Assert.AreEqual(5, test.ReturnValue()); Assert.AreEqual(0, callCount); test.Simple(); Assert.AreEqual(1, callCount); }
internal void WriteCombinedBody(IndentedTextWriter2 writer, ShortTypeNameGenerator sng) { if (PredicateMethod != null) { PredicateMethod.Write(writer, sng); } FactoryObjectMethod.Write(writer, sng); FuncMethod.Write(writer, sng); if (DisposeMethod != null) { DisposeMethod.Write(writer, sng); } }