* attribute.cs (GetMarshal): Work even if "DefineCustom" is
[mono.git] / mcs / class / corlib / System / MonoType.cs
index 9c04c9671dcd224a63996829859064a358fe4c0a..7c145c730d73245c98768a31966493c674c1dbc5 100644 (file)
@@ -8,11 +8,7 @@
 //     Gonzalo Paniagua (gonzalo@ximian.com)
 //
 // (c) 2001-2003 Ximian, Inc.
-// (c) 2003,2004 Novell, Inc. (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2003-2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
 using System.Reflection;
 using System.Runtime.CompilerServices;
-using System.Globalization;
 using System.Runtime.Serialization;
+using System.Security;
 
 namespace System
 {
@@ -90,7 +87,7 @@ namespace System
                        if (types == null) {
                                if (count > 1)
                                        throw new AmbiguousMatchException ();
-                               return found;
+                               return (ConstructorInfo) CheckMethodSecurity (found);
                        }
                        match = new MethodBase [count];
                        if (count == 1)
@@ -105,7 +102,7 @@ namespace System
                        }
                        if (binder == null)
                                binder = Binder.DefaultBinder;
-                       return (ConstructorInfo)binder.SelectMethod (bindingAttr, match, types, modifiers);
+                       return (ConstructorInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, match, types, modifiers));
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -203,7 +200,7 @@ namespace System
                                return null;
                        
                        if (count == 1 && typesLen == 0) 
-                               return found;
+                               return (MethodInfo) CheckMethodSecurity (found);
 
                        match = new MethodBase [count];
                        if (count == 1)
@@ -218,12 +215,33 @@ namespace System
                        }
                        
                        if (types == null) 
-                               return (MethodInfo) Binder.FindMostDerivedMatch (match);
+                               return (MethodInfo) CheckMethodSecurity (Binder.FindMostDerivedMatch (match));
 
                        if (binder == null)
                                binder = Binder.DefaultBinder;
                        
-                       return (MethodInfo)binder.SelectMethod (bindingAttr, match, types, modifiers);
+                       return (MethodInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, match, types, modifiers));
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
+
+               internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
+                {
+                        return GetCorrespondingInflatedMethod (fromNoninstanciated);
+                }
+
+               internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
+               {
+                        return GetCorrespondingInflatedConstructor (fromNoninstanciated);
+               }
+
+               internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
+               {
+                       return GetField (fromNoninstanciated.Name);
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -448,12 +466,12 @@ namespace System
 
                public override string AssemblyQualifiedName {
                        get {
-                               return getFullName (false) + ", " + Assembly.GetName ().ToString ();
+                               return getFullName (true, true);
                        }
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern string getFullName(bool full_name);
+               private extern string getFullName(bool full_name, bool assembly_qualified);
 
                public extern override Type BaseType {
                        [MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -462,7 +480,7 @@ namespace System
 
                public override string FullName {
                        get {
-                               return getFullName (false);
+                               return getFullName (true, false);
                        }
                }
 
@@ -543,7 +561,7 @@ namespace System
 
                public override string ToString()
                {
-                       return getFullName (true);
+                       return getFullName (false, false);
                }
 
 #if NET_2_0 || BOOTSTRAP_NET_2_0
@@ -583,5 +601,19 @@ namespace System
                        get;
                }
 #endif
+
+               private MethodBase CheckMethodSecurity (MethodBase mb)
+               {
+                       if (!SecurityManager.SecurityEnabled || (mb == null))
+                               return mb;
+
+                       // Sadly we have no way to know which kind of security action this is
+                       // so we must do it the hard way. Actually this isn't so bad 
+                       // because we can skip the (mb.Attributes & MethodAttributes.HasSecurity)
+                       // icall required (and do it ourselves)
+
+                       // this (unlike the Invoke step) is _and stays_ a LinkDemand (caller)
+                       return SecurityManager.ReflectedLinkDemandQuery (mb) ? mb : null;
+               }
        }
 }