* attribute.cs (GetMarshal): Work even if "DefineCustom" is
[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 typesLen = (types != null) ? types.Length : 0;
189                         int count = 0;
190                         
191                         foreach (MethodInfo m in methods) {
192                                 // Under MS.NET, Standard|HasThis matches Standard...
193                                 if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
194                                         continue;
195                                 found = m;
196                                 count++;
197                         }
198
199                         if (count == 0)
200                                 return null;
201                         
202                         if (count == 1 && typesLen == 0) 
203                                 return (MethodInfo) CheckMethodSecurity (found);
204
205                         match = new MethodBase [count];
206                         if (count == 1)
207                                 match [0] = found;
208                         else {
209                                 count = 0;
210                                 foreach (MethodInfo m in methods) {
211                                         if (callConvention != CallingConventions.Any && ((m.CallingConvention & callConvention) != callConvention))
212                                                 continue;
213                                         match [count++] = m;
214                                 }
215                         }
216                         
217                         if (types == null) 
218                                 return (MethodInfo) CheckMethodSecurity (Binder.FindMostDerivedMatch (match));
219
220                         if (binder == null)
221                                 binder = Binder.DefaultBinder;
222                         
223                         return (MethodInfo) CheckMethodSecurity (binder.SelectMethod (bindingAttr, match, types, modifiers));
224                 }
225
226                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
227                 extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
228
229                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
230                 extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
231
232                 internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
233                 {
234                         return GetCorrespondingInflatedMethod (fromNoninstanciated);
235                 }
236
237                 internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
238                 {
239                         return GetCorrespondingInflatedConstructor (fromNoninstanciated);
240                 }
241
242                 internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
243                 {
244                         return GetField (fromNoninstanciated.Name);
245                 }
246
247                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
248                 public extern override Type GetNestedType (string name, BindingFlags bindingAttr);
249
250                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
251                 public extern override Type[] GetNestedTypes (BindingFlags bindingAttr);
252
253                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
254                 internal extern PropertyInfo[] GetPropertiesByName (string name, BindingFlags bindingAttr, bool icase, Type reflected_type);
255
256                 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
257                 {
258                         return GetPropertiesByName (null, bindingAttr, false, this);
259                 }
260
261                 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
262                                                                  Binder binder, Type returnType,
263                                                                  Type[] types,
264                                                                  ParameterModifier[] modifiers)
265                 {
266                         bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
267                         PropertyInfo [] props = GetPropertiesByName (name, bindingAttr, ignoreCase, this);
268                         int count = props.Length;
269                         if (count == 0)
270                                 return null;
271                         
272                         if (count == 1 && (types == null || types.Length == 0)) 
273                                 return props [0];
274
275                         if (binder == null)
276                                 binder = Binder.DefaultBinder;
277                         
278                         return binder.SelectProperty (bindingAttr, props, returnType, types, modifiers);
279                 }
280
281                 protected override bool HasElementTypeImpl ()
282                 {
283                         return IsArrayImpl() || IsByRefImpl() || IsPointerImpl ();
284                 }
285
286                 protected override bool IsArrayImpl ()
287                 {
288                         return Type.IsArrayImpl (this);
289                 }
290
291                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
292                 protected extern override bool IsByRefImpl ();
293
294                 protected override bool IsCOMObjectImpl ()
295                 {
296                         return false;
297                 }
298
299                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
300                 protected extern override bool IsPointerImpl ();
301
302                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
303                 protected extern override bool IsPrimitiveImpl ();
304
305                 protected override bool IsValueTypeImpl ()
306                 {
307                         return type_is_subtype_of (this, typeof (System.ValueType), false) &&
308                                 this != typeof (System.ValueType) &&
309                                 this != typeof (System.Enum);
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 ((invokeAttr & BindingFlags.SetField) != 0 && ((args == null) || args.Length != 1))
332                                 throw new ArgumentException ("invokeAttr");
333                         if ((namedParameters != null) && ((args == null) || args.Length < namedParameters.Length))
334                                 throw new ArgumentException ("namedParameters cannot be more than named arguments in number");
335
336                         /* set some defaults if none are provided :-( */
337                         if ((invokeAttr & (BindingFlags.Public|BindingFlags.NonPublic)) == 0)
338                                 invokeAttr |= BindingFlags.Public;
339                         if ((invokeAttr & (BindingFlags.Static|BindingFlags.Instance)) == 0)
340                                 invokeAttr |= BindingFlags.Static|BindingFlags.Instance;
341
342                         if (binder == null)
343                                 binder = Binder.DefaultBinder;
344                         if ((invokeAttr & BindingFlags.CreateInstance) != 0) {
345                                 /* the name is ignored */
346                                 invokeAttr |= BindingFlags.DeclaredOnly;
347                                 ConstructorInfo[] ctors = GetConstructors (invokeAttr);
348                                 object state = null;
349                                 MethodBase ctor = binder.BindToMethod (invokeAttr, ctors, ref args, modifiers, culture, namedParameters, out state);
350                                 if (ctor == null) {
351                                         if (this.IsValueType && args == null)
352                                                 return Activator.CreateInstanceInternal (this);
353                                         
354                                         throw new MissingMethodException ("Constructor on type '" + FullName + "' not found.");
355                                 }
356                                 object result = ctor.Invoke (target, invokeAttr, binder, args, culture);
357                                 binder.ReorderArgumentArray (ref args, state);
358                                 return result;
359                         }
360                         if (name == String.Empty && Attribute.IsDefined (this, typeof (DefaultMemberAttribute))) {
361                                 DefaultMemberAttribute attr = (DefaultMemberAttribute) Attribute.GetCustomAttribute (this, typeof (DefaultMemberAttribute));
362                                 name = attr.MemberName;
363                         }
364                         bool ignoreCase = (invokeAttr & BindingFlags.IgnoreCase) != 0;
365                         bool throwMissingMethodException = false;
366                         bool throwMissingFieldException = false;
367                         if ((invokeAttr & BindingFlags.InvokeMethod) != 0) {
368                                 MethodInfo[] methods = GetMethodsByName (name, invokeAttr, ignoreCase, this);
369                                 object state = null;
370                                 MethodBase m = binder.BindToMethod (invokeAttr, methods, ref args, modifiers, culture, namedParameters, out state);
371                                 if (m == null) {
372                                         throwMissingMethodException = true;
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                                 FieldInfo f = GetField (name, invokeAttr);
389                                 if (f != null) {
390                                         f.SetValue (target, args [0]);
391                                         return null;
392                                 } else if ((invokeAttr & BindingFlags.SetProperty) == 0) {
393                                         throwMissingFieldException = true;
394                                 }
395                                 /* try SetProperty */
396                         }
397                         if ((invokeAttr & BindingFlags.GetProperty) != 0) {
398                                 PropertyInfo[] properties = GetPropertiesByName (name, invokeAttr, ignoreCase, this);
399                                 object state = null;
400                                 int i, count = 0;
401                                 for (i = 0; i < properties.Length; ++i) {
402                                         if ((properties [i].GetGetMethod (true) != null))
403                                                 count++;
404                                 }
405                                 MethodBase[] smethods = new MethodBase [count];
406                                 count = 0;
407                                 for (i = 0; i < properties.Length; ++i) {
408                                         MethodBase mb = properties [i].GetGetMethod (true);
409                                         if (mb != null)
410                                                 smethods [count++] = mb;
411                                 }
412                                 MethodBase m = binder.BindToMethod (invokeAttr, smethods, ref args, modifiers, culture, namedParameters, out state);
413                                 if (m == null) {
414                                         throwMissingFieldException = true;
415                                 } else {
416                                         object result = m.Invoke (target, invokeAttr, binder, args, culture);
417                                         binder.ReorderArgumentArray (ref args, state);
418                                         return result;
419                                 }
420                         } else if ((invokeAttr & BindingFlags.SetProperty) != 0) {
421                                 PropertyInfo[] properties = GetPropertiesByName (name, invokeAttr, ignoreCase, this);
422                                 object state = null;
423                                 int i, count = 0;
424                                 for (i = 0; i < properties.Length; ++i) {
425                                         if (properties [i].GetSetMethod (true) != null)
426                                                 count++;
427                                 }
428                                 MethodBase[] smethods = new MethodBase [count];
429                                 count = 0;
430                                 for (i = 0; i < properties.Length; ++i) {
431                                         MethodBase mb = properties [i].GetSetMethod (true);
432                                         if (mb != null)
433                                                 smethods [count++] = mb;
434                                 }
435                                 MethodBase m = binder.BindToMethod (invokeAttr, smethods, ref args, modifiers, culture, namedParameters, out state);
436                                 if (m == null) {
437                                         throwMissingFieldException = true;
438                                 } else {
439                                         object result = m.Invoke (target, invokeAttr, binder, args, culture);
440                                         binder.ReorderArgumentArray (ref args, state);
441                                         return result;
442                                 }
443                         }
444                         if (throwMissingMethodException)
445                                 throw new MissingMethodException();
446                         if (throwMissingFieldException)
447                                 throw new MissingFieldException();
448
449                         return null;
450                 }
451
452                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
453                 public extern override Type GetElementType ();
454
455                 public override Type UnderlyingSystemType {
456                         get {
457                                 // This has _nothing_ to do with getting the base type of an enum etc.
458                                 return this;
459                         }
460                 }
461
462                 public extern override Assembly Assembly {
463                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
464                         get;
465                 }
466
467                 public override string AssemblyQualifiedName {
468                         get {
469                                 return getFullName (true, true);
470                         }
471                 }
472
473                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
474                 private extern string getFullName(bool full_name, bool assembly_qualified);
475
476                 public extern override Type BaseType {
477                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
478                         get;
479                 }
480
481                 public override string FullName {
482                         get {
483                                 return getFullName (true, false);
484                         }
485                 }
486
487                 public override Guid GUID {
488                         get {
489                                 return Guid.Empty;
490                         }
491                 }
492
493                 public override bool IsDefined (Type attributeType, bool inherit)
494                 {
495                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
496                 }
497
498                 public override object[] GetCustomAttributes (bool inherit)
499                 {
500                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
501                 }
502
503                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
504                 {
505                         if (attributeType == null)
506                         {
507                                 throw new ArgumentNullException("attributeType");
508                         }
509                         
510                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
511                 }
512
513                 public override MemberTypes MemberType {
514                         get {
515                                 if (DeclaringType != null)
516                                         return MemberTypes.NestedType;
517                                 else
518                                         return MemberTypes.TypeInfo;
519                         }
520                 }
521
522                 public extern override string Name {
523                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
524                         get;
525                 }
526
527                 public extern override string Namespace {
528                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
529                         get;
530                 }
531
532                 public extern override Module Module {
533                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
534                         get;
535                 }
536
537                 public extern override Type DeclaringType {
538                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
539                         get;
540                 }
541
542                 public override Type ReflectedType {
543                         get {
544                                 return DeclaringType;
545                         }
546                 }
547
548                 public override RuntimeTypeHandle TypeHandle {
549                         get {
550                                 return _impl;
551                         }
552                 }
553
554                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
555                 public extern override int GetArrayRank ();
556
557                 public void GetObjectData(SerializationInfo info, StreamingContext context)
558                 {
559                         UnitySerializationHolder.GetTypeData (this, info, context);
560                 }
561
562                 public override string ToString()
563                 {
564                         return getFullName (false, false);
565                 }
566
567 #if NET_2_0 || BOOTSTRAP_NET_2_0
568                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
569                 public extern override Type [] GetGenericArguments ();
570
571                 public extern override bool HasGenericArguments {
572                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
573                         get;
574                 }
575
576                 public override bool ContainsGenericParameters {
577                         get {
578                                 if (IsGenericParameter)
579                                         return true;
580
581                                 if (HasGenericArguments) {
582                                         foreach (Type arg in GetGenericArguments ())
583                                                 if (arg.ContainsGenericParameters)
584                                                         return true;
585                                 }
586
587                                 if (HasElementType)
588                                         return GetElementType ().ContainsGenericParameters;
589
590                                 return false;
591                         }
592                 }
593
594                 public extern override bool IsGenericParameter {
595                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
596                         get;
597                 }
598
599                 public extern override MethodInfo DeclaringMethod {
600                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
601                         get;
602                 }
603 #endif
604
605                 private MethodBase CheckMethodSecurity (MethodBase mb)
606                 {
607                         if (!SecurityManager.SecurityEnabled || (mb == null))
608                                 return mb;
609
610                         // Sadly we have no way to know which kind of security action this is
611                         // so we must do it the hard way. Actually this isn't so bad 
612                         // because we can skip the (mb.Attributes & MethodAttributes.HasSecurity)
613                         // icall required (and do it ourselves)
614
615                         // this (unlike the Invoke step) is _and stays_ a LinkDemand (caller)
616                         return SecurityManager.ReflectedLinkDemandQuery (mb) ? mb : null;
617                 }
618         }
619 }