Beispiel #1
0
        public MethodImplAttributeTest()
        {
            //create a dynamic assembly with the required attribute
            //and check for the validity

            dynAsmName.Name = "TestAssembly";

            dynAssembly = Thread.GetDomain().DefineDynamicAssembly(
                dynAsmName, AssemblyBuilderAccess.Run
                );

            // Set the required Attribute of the assembly.
            Type            attribute = typeof(MethodImplAttribute);
            ConstructorInfo ctrInfo   = attribute.GetConstructor(
                new Type [] { typeof(MethodImplOptions) }
                );
            CustomAttributeBuilder attrBuilder =
                new CustomAttributeBuilder(ctrInfo, new object [1] {
                MethodImplOptions.InternalCall
            });

            dynAssembly.SetCustomAttribute(attrBuilder);
            object [] attributes = dynAssembly.GetCustomAttributes(true);
            attr = attributes [0] as MethodImplAttribute;
        }
Beispiel #2
0
        public void CtorTest()
        {
            var a = new MethodImplAttribute(MethodImplOptions.InternalCall);

            Assert.AreEqual(MethodImplOptions.InternalCall, a.Value);

            a = new MethodImplAttribute((short)1);
            Assert.AreEqual((MethodImplOptions)1, a.Value);

            a = new MethodImplAttribute();
            Assert.AreEqual((MethodImplOptions)0, a.Value);
        }
Beispiel #3
0
        public static void MethodImplAttributeTests()
        {
            var attr1 = new MethodImplAttribute();

            Assert.Equal(default(MethodImplOptions), attr1.Value);

            var attr2 = new MethodImplAttribute(-1);

            Assert.Equal((MethodImplOptions)(-1), attr2.Value);

            var attr3 = new MethodImplAttribute(MethodImplOptions.Unmanaged);

            Assert.Equal(MethodImplOptions.Unmanaged, attr3.Value);
        }
Beispiel #4
0
        public override object[] GetCustomAttributes(Type attributeType, bool inherit)
        {
            ArgumentNullException.ThrowIfNull(attributeType);

            if (attributeType.IsAssignableFrom(typeof(MethodImplAttribute)))
            {
                // avoid calling CreateInstance() in the common case where the type is Attribute
                object[] result = attributeType == typeof(Attribute) ? new Attribute[1] : (object[])Array.CreateInstance(attributeType, 1);
                result[0] = new MethodImplAttribute((MethodImplOptions)GetMethodImplementationFlags());
                return(result);
            }

            return((object[])Array.CreateInstance(attributeType.IsValueType || attributeType.ContainsGenericParameters ? typeof(object) : attributeType, 0));
        }
Beispiel #5
0
        public void Ctor_Enum()
        {
            var res = new MethodImplAttribute(MethodImplOptions.InternalCall);

            Assert.AreEqual(MethodImplOptions.InternalCall, res.Value);
        }
Beispiel #6
0
        public void Ctor_Short()
        {
            var res = new MethodImplAttribute(1);

            Assert.AreEqual((MethodImplOptions)1, res.Value);
        }
Beispiel #7
0
        public void FieldsTest()
        {
            var a = new MethodImplAttribute(MethodImplOptions.NoInlining);

            Assert.AreEqual(MethodCodeType.IL, a.MethodCodeType);
        }