Пример #1
0
        public void DefineReadOnlyProperty_Adds_Methods_And_Property()
        {
            var moduleScope    = new ModuleScope();
            var generator      = new ProxyGenerator(moduleScope);
            var typeDefinition = generator.GetTypeDefinition(typeof(EmpyType), null, null);

            TypeBuilder typeBulder = moduleScope.Module.DefineType(typeDefinition.FullName, typeDefinition.TypeAttributes);

            var proxyScope = new ProxyScope(moduleScope, typeBulder, typeDefinition);

            proxyScope.DefineTypeAndMembers();

            Assert.AreEqual(0, proxyScope.Properties.Count);
            Assert.AreEqual(0, proxyScope.Methods.Count);

            FieldBuilder field = proxyScope.DefineField("_myProperty", typeof(EventHandler), FieldAttributes.Private);

            var p = proxyScope.DefineReadOnlyProperty("MyProperty", PropertyAttributes.None, typeof(void), new Type[0], MethodAttributes.Public, field);

            Assert.AreEqual(1, proxyScope.Properties.Count);
            Assert.AreEqual("MyProperty", proxyScope.Properties[0].Name);

            Assert.AreEqual(1, proxyScope.Methods.Count);
            Assert.AreEqual("get_MyProperty", proxyScope.Methods[0].Name);
        }