Example #1
0
        public void GetCustomAttributes()
        {
            var method = new DynamicMethod("method", typeof(void), new Type [] { });

            var methodImplAttrType = typeof(MethodImplAttribute);

            Assert.IsTrue(method.IsDefined(methodImplAttrType, true), "MethodImplAttribute is defined");

            // According to the spec, MethodImplAttribute is the
            // only custom attr that's present on a DynamicMethod.
            // And it's always a managed method with no inlining.
            var a1 = method.GetCustomAttributes(true);

            Assert.AreEqual(a1.Length, 1, "a1.Length == 1");
            Assert.AreEqual(a1[0].GetType(), methodImplAttrType, "a1[0] is a MethodImplAttribute");
            var options = (a1[0] as MethodImplAttribute).Value;

            Assert.IsTrue((options & MethodImplOptions.NoInlining) != 0, "NoInlining is set");
            Assert.IsTrue((options & MethodImplOptions.Unmanaged) == 0, "Unmanaged isn't set");


            // any other custom attribute type
            var extensionAttrType = typeof(ExtensionAttribute);

            Assert.IsFalse(method.IsDefined(extensionAttrType, true));
            Assert.AreEqual(Array.Empty <object>(), method.GetCustomAttributes(extensionAttrType, true));
        }
 public override bool IsDefined(Type attributeType, bool inherit) =>
 m_owner.IsDefined(attributeType, inherit);
Example #3
0
 public override bool IsDefined(Type attributeType, bool inherit)
 {
     return(_dynamicMethod.IsDefined(attributeType, inherit));
 }