Ejemplo n.º 1
0
        public void AddCustomAttribute()
        {
            var classEmitter = new CustomClassEmitter(Scope, "AddCustomAttribute", typeof(object), Type.EmptyTypes, TypeAttributes.Public, true);

            classEmitter.AddCustomAttribute(new CustomAttributeBuilder(typeof(SimpleAttribute).GetConstructor(Type.EmptyTypes), new object[0],
                                                                       typeof(SimpleAttribute).GetFields(), new object[] { "value" }));

            Type builtType = classEmitter.BuildType();

            var attributes = (SimpleAttribute[])builtType.GetCustomAttributes(typeof(SimpleAttribute), false);

            Assert.That(attributes.Length, Is.EqualTo(1));
            Assert.That(attributes[0].S, Is.EqualTo("value"));
        }