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