Exemple #1
0
        public void TestCreateType_2x()
        {
            // Create via factory
            InterceptorFactory.New <ISimpleTypeTest>();

            var testInterfaceType = typeof(ISimpleTypeTest);

            var typeName = testInterfaceType.Name + "Impl";

            // Remove "I" at the start
            if (typeName.StartsWith("I"))
            {
                typeName = typeName.Substring(1);
            }

            var fqTypeName = testInterfaceType.FullName.Replace(testInterfaceType.Name, typeName);

            var baseType = typeof(ExtensibleInterceptorImpl <>);

            // Make sure we have a non generic type, by filling in the "blanks"
            if (baseType.IsGenericType)
            {
                baseType = baseType.MakeGenericType(testInterfaceType);
            }

            // Create self
            var typeBuilder = IlTypeBuilder.CreateOrGet();

            typeBuilder.CreateType(fqTypeName, new[] { testInterfaceType }, baseType);
        }
Exemple #2
0
        public void TestSaveAssembly()
        {
            var typeBuilder = IlTypeBuilder.CreateOrGet(true, "Generated.Dapplo.InterfaceImpl.Tests");

            typeBuilder.CreateType("SimpleTypeTest", new[] { typeof(ISimpleTypeTest) });
            const string tmpFileName = "MySimpleType.dll";

            typeBuilder.SaveAssemblyDll(tmpFileName);
            Assert.True(File.Exists(tmpFileName));
            File.Delete(tmpFileName);
        }