[sre] Implement DynamicMethod.GetCustomAttributes() and IsDefined ()
authorAleksey Kliger <aleksey@xamarin.com>
Tue, 13 Dec 2016 17:27:13 +0000 (12:27 -0500)
committerAleksey Kliger <aleksey@xamarin.com>
Tue, 13 Dec 2016 21:34:18 +0000 (16:34 -0500)
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

mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs

index e3c30a4e4b2532b3789cea91fcf0d5e7da696aac..24e02528cec093ddc2dbb9b4e63eaf82316b60ff 100644 (file)
@@ -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<Object>.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 () {