Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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>());
        }
Exemplo n.º 5
0
        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>());
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
            }
        }