Grasshopper project system now uses csproj extension
[mono.git] / mcs / class / corlib / System / MonoType.cs
1 //
2 // System.MonoType
3 //
4 // Authors: 
5 //      Sean MacIsaac (macisaac@ximian.com)
6 //      Paolo Molaro (lupus@ximian.com)
7 //      Patrik Torstensson (patrik.torstensson@labs2.com)
8 //      Gonzalo Paniagua (gonzalo@ximian.com)
9 //
10 // (c) 2001-2003 Ximian, Inc.
11 // Copyright (C) 2003-2005 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System.Globalization;
34 using System.Reflection;
35 using System.Runtime.CompilerServices;
36 using System.Runtime.Serialization;
37 using System.Security;
38
39 namespace System
40 {
41         [Serializable]
42         internal class MonoType : Type, ISerializable
43         {
44
45                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
46                 private static extern void type_from_obj (MonoType type, Object obj);
47                 
48                 internal MonoType (Object obj)
49                 {
50                         // this should not be used - lupus
51                         type_from_obj (this, obj);
52                         
53                         throw new NotImplementedException ();
54                 }
55
56                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
57                 private static extern TypeAttributes get_attributes (Type type);
58         
59                 protected override TypeAttributes GetAttributeFlagsImpl ()
60                 {
61                         return get_attributes (this);
62                 }
63
64                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
65                                                                        Binder binder,
66                                                                        CallingConventions callConvention,
67                                                                        Type[] types,
68                                                                        ParameterModifier[] modifiers)
69                 {
70                         if (bindingAttr == BindingFlags.Default)
71                                 bindingAttr = BindingFlags.Public | BindingFlags.Instance;
72
73                         ConstructorInfo[] methods = GetConstructors (bindingAttr);
74                         ConstructorInfo found = null;
75                         MethodBase[] match;
76                         int count = 0;
77                         foreach (ConstructorInfo m in methods) {
78                                 // Under MS.NET, Standard|HasThis matches Standard...
79                                 if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
80                                         continue;
81                                 found = m;
82                                 count++;
83                         }
84                         if (count == 0)
85                                 return null;
86                         if (types == null) {
87                                 if (count > 1)
88                                         throw new AmbiguousMatchException ();
89                                 return (ConstructorInfo) CheckMethodSecurity (found);
90                         }
91                         match = new MethodBase [count];
92                         if (count == 1)
93                                 match [0] = found;
94                         else {
95                                 count = 0;
96                                 foreach (ConstructorInfo m in methods) {
97                                         if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
98                                                 continue;
99                                         match [count++] = m;
100                                 }
101                         }
102                         if (binder == null)
103                                 binder = Binder.DefaultBinder;
104                         return (ConstructorInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, match, types, modifiers));
105                 }
106
107                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
108                 internal extern ConstructorInfo[] GetConstructors_internal (BindingFlags bindingAttr, Type reflected_type);
109
110                 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
111                 {
112                         return GetConstructors_internal (bindingAttr, this);
113                 }
114
115                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
116                 extern EventInfo InternalGetEvent (string name, BindingFlags bindingAttr);
117
118                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
119                 {
120                         if (name == null)
121                                 throw new ArgumentNullException ("name");
122
123                         return InternalGetEvent (name, bindingAttr);
124                 }
125
126                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
127                 internal extern EventInfo[] GetEvents_internal (BindingFlags bindingAttr, Type reflected_type);
128
129                 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
130                 {
131                         return GetEvents_internal (bindingAttr, this);
132                 }
133
134                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
135                 public extern override FieldInfo GetField (string name, BindingFlags bindingAttr);
136
137                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
138                 internal extern FieldInfo[] GetFields_internal (BindingFlags bindingAttr, Type reflected_type);
139
140                 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
141                 {
142                         return GetFields_internal (bindingAttr, this);
143                 }
144                 
145                 public override Type GetInterface (string name, bool ignoreCase)
146                 {
147                         if (name == null)
148                                 throw new ArgumentNullException ();
149
150                         Type[] interfaces = GetInterfaces();
151
152                         foreach (Type type in interfaces) {
153                                 if (String.Compare (type.Name, name, ignoreCase, CultureInfo.InvariantCulture) == 0)
154                                         return type;
155                                 if (String.Compare (type.FullName, name, ignoreCase, CultureInfo.InvariantCulture) == 0)
156                                         return type;
157                         }
158
159                         return null;
160                 }
161
162                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
163                 public extern override Type[] GetInterfaces();
164                 
165                 public override MemberInfo[] GetMembers( BindingFlags bindingAttr)
166                 {
167                         return FindMembers (MemberTypes.All, bindingAttr, null, null);
168                 }
169
170                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
171                 internal extern MethodInfo [] GetMethodsByName (string name, BindingFlags bindingAttr, bool ignoreCase, Type reflected_type);
172
173                 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
174                 {
175                         return GetMethodsByName (null, bindingAttr, false, this);
176                 }
177
178                 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
179                                                              Binder binder,
180                                                              CallingConventions callConvention,
181                                                              Type[] types, ParameterModifier[] modifiers)
182                 {
183                         bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
184                         MethodInfo[] methods = GetMethodsByName (name, bindingAttr, ignoreCase, this);
185                         MethodInfo found = null;
186                         MethodBase[] match;
187                         int count = 0;
188                         
189                         foreach (MethodInfo m in methods) {
190                                 // Under MS.NET, Standard|HasThis matches Standard...
191                                 if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
192                                         continue;
193                                 found = m;
194                                 count++;
195                         }
196
197                         if (count == 0)
198                                 return null;
199                         
200                         if (count == 1 && types == null) 
201                                 return (MethodInfo) CheckMethodSecurity (found);
202
203                         match = new MethodBase [count];
204                         if (count == 1)
205                                 match [0] = found;
206                         else {
207                                 count = 0;
208                                 foreach (MethodInfo m in methods) {
209                                         if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
210                                                 continue;
211                                         match [count++] = m;
212                                 }
213                         }
214
215                         if (types == null) 
216                                 return (MethodInfo) CheckMethodSecurity (Binder.FindMostDerivedMatch (match));
217
218                         if (binder == null)
219                                 binder = Binder.DefaultBinder;
220                         
221                         return (MethodInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, match, types, modifiers));
222                 }
223
224                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
225                 extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
226
227                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
228                 extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
229
230                 internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
231                 {
232                         return GetCorrespondingInflatedMethod (fromNoninstanciated);
233                 }
234
235                 internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
236                 {
237                         return GetCorrespondingInflatedConstructor (fromNoninstanciated);
238                 }
239
240                 internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
241                 {
242                         /* create sensible flags from given FieldInfo */
243                         BindingFlags flags = fromNoninstanciated.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
244                         flags |= fromNoninstanciated.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
245                         return GetField (fromNoninstanciated.Name, flags);
246                 }
247
248                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
249                 public extern override Type GetNestedType (string name, BindingFlags bindingAttr);
250
251                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
252                 public extern override Type[] GetNestedTypes (BindingFlags bindingAttr);
253
254                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
255                 internal extern PropertyInfo[] GetPropertiesByName (string name, BindingFlags bindingAttr, bool icase, Type reflected_type);
256
257                 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
258                 {
259                         return GetPropertiesByName (null, bindingAttr, false, this);
260                 }
261
262                 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
263                                                                  Binder binder, Type returnType,
264                                                                  Type[] types,
265                                                                  ParameterModifier[] modifiers)
266                 {
267                         bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
268                         PropertyInfo [] props = GetPropertiesByName (name, bindingAttr, ignoreCase, this);
269                         int count = props.Length;
270                         if (count == 0)
271                                 return null;
272                         
273                         if (count == 1 && (types == null || types.Length == 0)) 
274                                 return props [0];
275
276                         if (binder == null)
277                                 binder = Binder.DefaultBinder;
278                         
279                         return binder.SelectProperty (bindingAttr, props, returnType, types, modifiers);
280                 }
281
282                 protected override bool HasElementTypeImpl ()
283                 {
284                         return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
285                 }
286
287                 protected override bool IsArrayImpl ()
288                 {
289                         return Type.IsArrayImpl (this);
290                 }
291
292                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
293                 protected extern override bool IsByRefImpl ();
294
295                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
296                 protected extern override bool IsCOMObjectImpl ();
297
298                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
299                 protected extern override bool IsPointerImpl ();
300
301                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
302                 protected extern override bool IsPrimitiveImpl ();
303
304                 public override bool IsSubclassOf (Type type)
305                 {
306                         if (type == null)
307                                 throw new ArgumentNullException ("type");
308
309                         return base.IsSubclassOf (type);
310                 }
311
312                 public override object InvokeMember (string name, BindingFlags invokeAttr,
313                                                      Binder binder, object target, object[] args,
314                                                      ParameterModifier[] modifiers,
315                                                      CultureInfo culture, string[] namedParameters)
316                 {
317
318                         if ((invokeAttr & BindingFlags.CreateInstance) != 0) {
319                                 if ((invokeAttr & (BindingFlags.GetField |
320                                                 BindingFlags.GetField | BindingFlags.GetProperty |
321                                                 BindingFlags.SetProperty)) != 0)
322                                         throw new ArgumentException ("invokeAttr");
323                         } else if (name == null)
324                                 throw new ArgumentNullException ("name");
325                         if ((invokeAttr & BindingFlags.GetField) != 0 && (invokeAttr & BindingFlags.SetField) != 0)
326                                 throw new ArgumentException ("invokeAttr");
327                         if ((invokeAttr & BindingFlags.GetProperty) != 0 && (invokeAttr & BindingFlags.SetProperty) != 0)
328                                 throw new ArgumentException ("invokeAttr");
329                         if ((invokeAttr & BindingFlags.InvokeMethod) != 0 && (invokeAttr & (BindingFlags.SetProperty|BindingFlags.SetField)) != 0)
330                                 throw new ArgumentException ("invokeAttr");
331                         if ((namedParameters != null) && ((args == null) || args.Length < namedParameters.Length))
332                                 throw new ArgumentException ("namedParameters cannot be more than named arguments in number");
333
334                         /* set some defaults if none are provided :-( */
335                         if ((invokeAttr & (BindingFlags.Public|BindingFlags.NonPublic)) == 0)
336                                 invokeAttr |= BindingFlags.Public;
337                         if ((invokeAttr & (BindingFlags.Static|BindingFlags.Instance)) == 0)
338                                 invokeAttr |= BindingFlags.Static|BindingFlags.Instance;
339
340                         if (binder == null)
341                                 binder = Binder.DefaultBinder;
342                         if ((invokeAttr & BindingFlags.CreateInstance) != 0) {
343                                 /* the name is ignored */
344                                 invokeAttr |= BindingFlags.DeclaredOnly;
345                                 ConstructorInfo[] ctors = GetConstructors (invokeAttr);
346                                 object state = null;
347                                 MethodBase ctor = binder.BindToMethod (invokeAttr, ctors, ref args, modifiers, culture, namedParameters, out state);
348                                 if (ctor == null) {
349                                         if (this.IsValueType && args == null)
350                                                 return Activator.CreateInstanceInternal (this);
351                                         
352                                         throw new MissingMethodException ("Constructor on type '" + FullName + "' not found.");
353                                 }
354                                 object result = ctor.Invoke (target, invokeAttr, binder, args, culture);
355                                 binder.ReorderArgumentArray (ref args, state);
356                                 return result;
357                         }
358                         if (name == String.Empty && Attribute.IsDefined (this, typeof (DefaultMemberAttribute))) {
359                                 DefaultMemberAttribute attr = (DefaultMemberAttribute) Attribute.GetCustomAttribute (this, typeof (DefaultMemberAttribute));
360                                 name = attr.MemberName;
361                         }
362                         bool ignoreCase = (invokeAttr & BindingFlags.IgnoreCase) != 0;
363                         string throwMissingMethodDescription = null;
364                         bool throwMissingFieldException = false;
365                         
366                         if ((invokeAttr & BindingFlags.InvokeMethod) != 0) {
367                                 MethodInfo[] methods = GetMethodsByName (name, invokeAttr, ignoreCase, this);
368                                 object state = null;
369                                 MethodBase m = binder.BindToMethod (invokeAttr, methods, ref args, modifiers, culture, namedParameters, out state);
370                                 if (m == null) {
371                                         if (methods.Length > 0)
372                                                 throwMissingMethodDescription = "The best match for method " + name + " has some invalid parameter.";
373                                         else
374                                                 throwMissingMethodDescription = "Cannot find method " + name + ".";
375                                 } else {
376                                         object result = m.Invoke (target, invokeAttr, binder, args, culture);
377                                         binder.ReorderArgumentArray (ref args, state);
378                                         return result;
379                                 }
380                         }
381                         if ((invokeAttr & BindingFlags.GetField) != 0) {
382                                 FieldInfo f = GetField (name, invokeAttr);
383                                 if (f != null) {
384                                         return f.GetValue (target);
385                                 } else if ((invokeAttr & BindingFlags.GetProperty) == 0) {
386                                         throwMissingFieldException = true;
387                                 }
388                                 /* try GetProperty */
389                         } else if ((invokeAttr & BindingFlags.SetField) != 0) {
390                                 if ((args == null) || args.Length != 1)
391                                         throw new ArgumentException ("invokeAttr");
392
393                                 FieldInfo f = GetField (name, invokeAttr);
394                                 if (f != null) {
395                                         f.SetValue (target, args [0]);
396                                         return null;
397                                 } else if ((invokeAttr & BindingFlags.SetProperty) == 0) {
398                                         throwMissingFieldException = true;
399                                 }
400                                 /* try SetProperty */
401                         }
402                         if ((invokeAttr & BindingFlags.GetProperty) != 0) {
403                                 PropertyInfo[] properties = GetPropertiesByName (name, invokeAttr, ignoreCase, this);
404                                 object state = null;
405                                 int i, count = 0;
406                                 for (i = 0; i < properties.Length; ++i) {
407                                         if ((properties [i].GetGetMethod (true) != null))
408                                                 count++;
409                                 }
410                                 MethodBase[] smethods = new MethodBase [count];
411                                 count = 0;
412                                 for (i = 0; i < properties.Length; ++i) {
413                                         MethodBase mb = properties [i].GetGetMethod (true);
414                                         if (mb != null)
415                                                 smethods [count++] = mb;
416                                 }
417                                 MethodBase m = binder.BindToMethod (invokeAttr, smethods, ref args, modifiers, culture, namedParameters, out state);
418                                 if (m == null) {
419                                         throwMissingFieldException = true;
420                                 } else {
421                                         object result = m.Invoke (target, invokeAttr, binder, args, culture);
422                                         binder.ReorderArgumentArray (ref args, state);
423                                         return result;
424                                 }
425                         } else if ((invokeAttr & BindingFlags.SetProperty) != 0) {
426                                 PropertyInfo[] properties = GetPropertiesByName (name, invokeAttr, ignoreCase, this);
427                                 object state = null;
428                                 int i, count = 0;
429                                 for (i = 0; i < properties.Length; ++i) {
430                                         if (properties [i].GetSetMethod (true) != null)
431                                                 count++;
432                                 }
433                                 MethodBase[] smethods = new MethodBase [count];
434                                 count = 0;
435                                 for (i = 0; i < properties.Length; ++i) {
436                                         MethodBase mb = properties [i].GetSetMethod (true);
437                                         if (mb != null)
438                                                 smethods [count++] = mb;
439                                 }
440                                 MethodBase m = binder.BindToMethod (invokeAttr, smethods, ref args, modifiers, culture, namedParameters, out state);
441                                 if (m == null) {
442                                         throwMissingFieldException = true;
443                                 } else {
444                                         object result = m.Invoke (target, invokeAttr, binder, args, culture);
445                                         binder.ReorderArgumentArray (ref args, state);
446                                         return result;
447                                 }
448                         }
449                         if (throwMissingMethodDescription != null)
450                                 throw new MissingMethodException(throwMissingMethodDescription);
451                         if (throwMissingFieldException)
452                                 throw new MissingFieldException("Cannot find variable " + name + ".");
453
454                         return null;
455                 }
456
457                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
458                 public extern override Type GetElementType ();
459
460                 public override Type UnderlyingSystemType {
461                         get {
462                                 // This has _nothing_ to do with getting the base type of an enum etc.
463                                 return this;
464                         }
465                 }
466
467                 public extern override Assembly Assembly {
468                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
469                         get;
470                 }
471
472                 public override string AssemblyQualifiedName {
473                         get {
474                                 return getFullName (true, true);
475                         }
476                 }
477
478                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
479                 private extern string getFullName(bool full_name, bool assembly_qualified);
480
481                 public extern override Type BaseType {
482                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
483                         get;
484                 }
485
486                 public override string FullName {
487                         get {
488                                 return getFullName (true, false);
489                         }
490                 }
491
492                 public override Guid GUID {
493                         get {
494                                 object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true);
495                                 if (att.Length == 0)
496                                         return Guid.Empty;
497                                 return new Guid(((System.Runtime.InteropServices.GuidAttribute)att[0]).Value);
498                         }
499                 }
500
501                 public override bool IsDefined (Type attributeType, bool inherit)
502                 {
503                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
504                 }
505
506                 public override object[] GetCustomAttributes (bool inherit)
507                 {
508                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
509                 }
510
511                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
512                 {
513                         if (attributeType == null)
514                         {
515                                 throw new ArgumentNullException("attributeType");
516                         }
517                         
518                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
519                 }
520
521                 public override MemberTypes MemberType {
522                         get {
523                                 if (DeclaringType != null)
524                                         return MemberTypes.NestedType;
525                                 else
526                                         return MemberTypes.TypeInfo;
527                         }
528                 }
529
530                 public extern override string Name {
531                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
532                         get;
533                 }
534
535                 public extern override string Namespace {
536                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
537                         get;
538                 }
539
540                 public extern override Module Module {
541                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
542                         get;
543                 }
544
545                 public extern override Type DeclaringType {
546                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
547                         get;
548                 }
549
550                 public override Type ReflectedType {
551                         get {
552                                 return DeclaringType;
553                         }
554                 }
555
556                 public override RuntimeTypeHandle TypeHandle {
557                         get {
558                                 return _impl;
559                         }
560                 }
561
562                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
563                 public extern override int GetArrayRank ();
564
565                 public void GetObjectData(SerializationInfo info, StreamingContext context)
566                 {
567                         UnitySerializationHolder.GetTypeData (this, info, context);
568                 }
569
570                 public override string ToString()
571                 {
572                         return getFullName (false, false);
573                 }
574
575 #if NET_2_0 || BOOTSTRAP_NET_2_0
576                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
577                 public extern override Type [] GetGenericArguments ();
578
579                 public override bool ContainsGenericParameters {
580                         get {
581                                 if (IsGenericParameter)
582                                         return true;
583
584                                 if (IsGenericType) {
585                                         foreach (Type arg in GetGenericArguments ())
586                                                 if (arg.ContainsGenericParameters)
587                                                         return true;
588                                 }
589
590                                 if (HasElementType)
591                                         return GetElementType ().ContainsGenericParameters;
592
593                                 return false;
594                         }
595                 }
596
597                 public extern override bool IsGenericParameter {
598                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
599                         get;
600                 }
601
602                 public extern override MethodBase DeclaringMethod {
603                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
604                         get;
605                 }
606 #endif
607
608                 private MethodBase CheckMethodSecurity (MethodBase mb)
609                 {
610                         if (!SecurityManager.SecurityEnabled || (mb == null))
611                                 return mb;
612
613                         // Sadly we have no way to know which kind of security action this is
614                         // so we must do it the hard way. Actually this isn't so bad 
615                         // because we can skip the (mb.Attributes & MethodAttributes.HasSecurity)
616                         // icall required (and do it ourselves)
617
618                         // this (unlike the Invoke step) is _and stays_ a LinkDemand (caller)
619                         return SecurityManager.ReflectedLinkDemandQuery (mb) ? mb : null;
620                 }
621         }
622 }