Merge pull request #3059 from lateralusX/jlorenss/win-x64-dyncall-gsharedvt-support
[mono.git] / mcs / class / corlib / System.Reflection / MonoMethod.cs
index 111387296cedafea98868ca522b631c8ff3bfdbe..c93233dfffb57af19d0eaa9cc7092a2125e01739 100644 (file)
@@ -118,6 +118,12 @@ namespace System.Reflection {
                        }
                }
 
+               public override Module Module {
+                       get {
+                               return GetRuntimeModule ();
+                       }
+               }
+
                RuntimeType ReflectedTypeInternal {
                        get {
                                return (RuntimeType) ReflectedType;
@@ -143,11 +149,26 @@ namespace System.Reflection {
             return sbName.ToString();
         }
 
+               public override Delegate CreateDelegate (Type delegateType)
+               {
+                       return Delegate.CreateDelegate (delegateType, this);
+               }
+
+               public override Delegate CreateDelegate (Type delegateType, object target)
+               {
+                       return Delegate.CreateDelegate (delegateType, target, this);
+               }
+
         public override String ToString() 
         {
             return ReturnType.FormatTypeName() + " " + FormatNameAndSig(false);
         }
 
+               internal RuntimeModule GetRuntimeModule ()
+               {
+                       return ((RuntimeType)DeclaringType).GetRuntimeModule();
+               }
+
         #region ISerializable Implementation
         public void GetObjectData(SerializationInfo info, StreamingContext context)
         {
@@ -271,15 +292,6 @@ namespace System.Reflection {
                        ParameterInfo[] pinfo = GetParametersInternal ();
                        ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
 
-#if !NET_2_1
-                       if (SecurityManager.SecurityEnabled) {
-                               // sadly Attributes doesn't tell us which kind of security action this is so
-                               // we must do it the hard way - and it also means that we can skip calling
-                               // Attribute (which is another an icall)
-                               SecurityManager.ReflectedLinkDemandInvoke (this);
-                       }
-#endif
-
                        if (ContainsGenericParameters)
                                throw new InvalidOperationException ("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
 
@@ -382,7 +394,7 @@ namespace System.Reflection {
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               internal static extern DllImportAttribute GetDllImportAttribute (IntPtr mhandle);
+               internal extern void GetPInvoke (out PInvokeAttributes flags, out string entryPoint, out string dllName);
 
                internal object[] GetPseudoCustomAttributes ()
                {
@@ -404,10 +416,7 @@ namespace System.Reflection {
                        if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
                                attrs [count ++] = new PreserveSigAttribute ();
                        if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
-                               DllImportAttribute attr = GetDllImportAttribute (mhandle);
-                               if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
-                                       attr.PreserveSig = true;
-                               attrs [count ++] = attr;
+                               attrs [count ++] = DllImportAttribute.GetCustomAttribute (this);
                        }
 
                        return attrs;
@@ -429,7 +438,7 @@ namespace System.Reflection {
                        foreach (Type type in methodInstantiation) {
                                if (type == null)
                                        throw new ArgumentNullException ();
-                               if (!(type is MonoType))
+                               if (!(type is RuntimeType))
                                        hasUserType = true;
                        }
 
@@ -493,9 +502,16 @@ namespace System.Reflection {
                        return CustomAttributeData.GetCustomAttributes (this);
                }
 
+#if MOBILE
+               static int get_core_clr_security_level ()
+               {
+                       return 1;
+               }
+#else
                //seclevel { transparent = 0, safe-critical = 1, critical = 2}
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                public extern int get_core_clr_security_level ();
+#endif
 
                public override bool IsSecurityTransparent {
                        get { return get_core_clr_security_level () == 0; }
@@ -626,15 +642,6 @@ namespace System.Reflection {
 
                        MonoMethod.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
 
-#if !NET_2_1
-                       if (SecurityManager.SecurityEnabled) {
-                               // sadly Attributes doesn't tell us which kind of security action this is so
-                               // we must do it the hard way - and it also means that we can skip calling
-                               // Attribute (which is another an icall)
-                               SecurityManager.ReflectedLinkDemandInvoke (this);
-                       }
-#endif
-
                        if (obj == null && DeclaringType.ContainsGenericParameters)
                                throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
 
@@ -751,5 +758,27 @@ namespace System.Reflection {
                public override IList<CustomAttributeData> GetCustomAttributesData () {
                        return CustomAttributeData.GetCustomAttributes (this);
                }
+
+#if MOBILE
+               static int get_core_clr_security_level ()
+               {
+                       return 1;
+               }
+#else
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               public extern int get_core_clr_security_level ();
+#endif
+
+               public override bool IsSecurityTransparent {
+                       get { return get_core_clr_security_level () == 0; }
+               }
+
+               public override bool IsSecurityCritical {
+                       get { return get_core_clr_security_level () > 0; }
+               }
+
+               public override bool IsSecuritySafeCritical {
+                       get { return get_core_clr_security_level () == 1; }
+               }
        }
 }