Beispiel #1
0
        public void MethodWithParameters()
        {
            var type   = module.GetType("Com.Mypackage.Foo");
            var @class = CecilApiImporter.CreateClass(type, options);
            var method = CecilApiImporter.CreateMethod(@class, type.Methods.First(m => m.Name == "BarWithParams"));

            Assert.IsTrue(method.Validate(new CodeGenerationOptions(), new GenericParameterDefinitionList(), new CodeGeneratorContext()), "method.Validate failed!");
            Assert.AreEqual("(ZID)Ljava/lang/String;", method.JniSignature);
            Assert.AreEqual("java.lang.String", method.Return);
            Assert.AreEqual("System.String", method.ManagedReturn);

            var parameter = method.Parameters [0];

            Assert.AreEqual("a", parameter.Name);
            Assert.AreEqual("bool", parameter.Type);
            Assert.AreEqual("boolean", parameter.JavaType);
            Assert.AreEqual("Z", parameter.JniType);

            parameter = method.Parameters [1];
            Assert.AreEqual("b", parameter.Name);
            Assert.AreEqual("int", parameter.Type);
            Assert.AreEqual("int", parameter.JavaType);
            Assert.AreEqual("I", parameter.JniType);

            parameter = method.Parameters [2];
            Assert.AreEqual("c", parameter.Name);
            Assert.AreEqual("double", parameter.Type);
            Assert.AreEqual("double", parameter.JavaType);
            Assert.AreEqual("D", parameter.JniType);
        }
Beispiel #2
0
        public void Method_Matches_True()
        {
            var type         = module.GetType("Com.Mypackage.Foo");
            var @class       = CecilApiImporter.CreateClass(type, options);
            var unknownTypes = type.Methods.First(m => m.Name == "UnknownTypes");
            var methodA      = CecilApiImporter.CreateMethod(@class, unknownTypes);
            var methodB      = CecilApiImporter.CreateMethod(@class, unknownTypes);

            Assert.IsTrue(methodA.Matches(methodB), "Methods should match!");
        }
Beispiel #3
0
        public void Method_Matches_False()
        {
            var type          = module.GetType("Com.Mypackage.Foo");
            var @class        = CecilApiImporter.CreateClass(type, options);
            var unknownTypesA = type.Methods.First(m => m.Name == "UnknownTypes");
            var unknownTypesB = type.Methods.First(m => m.Name == "UnknownTypesReturn");

            unknownTypesB.Name = "UnknownTypes";
            var methodA = CecilApiImporter.CreateMethod(@class, unknownTypesA);
            var methodB = CecilApiImporter.CreateMethod(@class, unknownTypesB);

            //Everything the same besides return type
            Assert.IsFalse(methodA.Matches(methodB), "Methods should not match!");
        }
Beispiel #4
0
        public void Method()
        {
            var type   = module.GetType("Com.Mypackage.Foo");
            var @class = CecilApiImporter.CreateClass(type, options);
            var method = CecilApiImporter.CreateMethod(@class, type.Methods.First(m => m.Name == "Bar"));

            Assert.IsTrue(method.Validate(new CodeGenerationOptions(), new GenericParameterDefinitionList(), new CodeGeneratorContext()), "method.Validate failed!");

            Assert.AreEqual("public", method.Visibility);
            Assert.AreEqual("void", method.Return);
            Assert.AreEqual("System.Void", method.ReturnType);
            Assert.AreEqual("Bar", method.Name);
            Assert.AreEqual("bar", method.JavaName);
            Assert.AreEqual("()V", method.JniSignature);
            Assert.IsFalse(method.IsAbstract);
            Assert.IsFalse(method.IsFinal);
            Assert.IsFalse(method.IsStatic);
            Assert.IsNull(method.Deprecated);
        }