Esempio n. 1
0
        public void TestLateLibrarybind()
        {
            dynamic tBigIntType =
                new DynamicObjects.LateType(
                    "System.Numerics.BigInteger, System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            if (tBigIntType.IsAvailable)
            {

                var one = [email protected](1);
                var two = [email protected](2);

                Assert.IsFalse(one.IsEven);
                Assert.AreEqual(true, two.IsEven);

                var tParsed = tBigIntType.Parse("4");

                Assert.AreEqual(true, tParsed.IsEven);

            }
            else
            {

                Assert.Fail("Big Int Didn't Load");

            }
        }
Esempio n. 2
0
        public void TestCodeDomLateTypeBind()
        {
            // http://stackoverflow.com/questions/16918612/dynamically-use-runtime-compiled-assemlby/16920438#16920438
            string code = @"
                namespace CodeInjection
                {
                    public static class DynConcatenateString
                    {
                        public static string Concatenate(string s1, string s2){
                            return s1 + "" ! "" + s2;
                        }
                    }
                }";

            var codeProvider = new CSharpCodeProvider();

            var parameters = new CompilerParameters {GenerateExecutable = false, GenerateInMemory = true};

            CompilerResults cr = codeProvider.CompileAssemblyFromSource(parameters,code);

            dynamic DynConcatenateString = new DynamicObjects.LateType(cr.CompiledAssembly, "CodeInjection.DynConcatenateString");

            Assert.That("1 ! 2", Is.EqualTo(DynConcatenateString.Concatenate("1","2")));
        }