From: Aleksey Kliger Date: Tue, 13 Dec 2016 17:27:13 +0000 (-0500) Subject: [sre] Implement DynamicMethod.GetCustomAttributes() and IsDefined () X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=789fb679beb9ed9e729833c946585ea4d096ee98;p=mono.git [sre] Implement DynamicMethod.GetCustomAttributes() and IsDefined () Per .NET documentation, DynamicMethod does not support custom attributes exception the MethodImplAttribute pseudo-custom attribute. Also change GetMethodImplementationFlags to include NoInlining as on .NET Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=49686 --- diff --git a/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs b/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs index e3c30a4e4b2..24e02528cec 100644 --- a/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs +++ b/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs @@ -210,15 +210,20 @@ namespace System.Reflection.Emit { return this; } - [MonoTODO("Not implemented")] public override object[] GetCustomAttributes (bool inherit) { - throw new NotImplementedException (); + // support for MethodImplAttribute PCA + return new Object[] { new MethodImplAttribute(GetMethodImplementationFlags()) }; } - [MonoTODO("Not implemented")] public override object[] GetCustomAttributes (Type attributeType, - bool inherit) { - throw new NotImplementedException (); + bool inherit) { + if (attributeType == null) + throw new ArgumentNullException ("attributeType"); + + if (attributeType.IsAssignableFrom (typeof (MethodImplAttribute))) + return new Object[] { new MethodImplAttribute (GetMethodImplementationFlags()) }; + else + return EmptyArray.Value; } public DynamicILInfo GetDynamicILInfo () { @@ -244,7 +249,7 @@ namespace System.Reflection.Emit { } public override MethodImplAttributes GetMethodImplementationFlags () { - return MethodImplAttributes.IL | MethodImplAttributes.Managed; + return MethodImplAttributes.IL | MethodImplAttributes.Managed | MethodImplAttributes.NoInlining; } public override ParameterInfo[] GetParameters () @@ -298,9 +303,14 @@ namespace System.Reflection.Emit { } } - [MonoTODO("Not implemented")] public override bool IsDefined (Type attributeType, bool inherit) { - throw new NotImplementedException (); + if (attributeType == null) + throw new ArgumentNullException ("attributeType"); + + if (attributeType.IsAssignableFrom (typeof (MethodImplAttribute))) + return true; + else + return false; } public override string ToString () {