2 // decl.cs: Declaration base class for structs, classes, enums and interfaces.
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 // Marek Safar (marek.safar@seznam.cz)
7 // Licensed under the terms of the GNU GPL
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
11 // TODO: Move the method verification stuff from the class.cs and interface.cs here
15 using System.Collections;
16 using System.Globalization;
17 using System.Reflection.Emit;
18 using System.Reflection;
20 namespace Mono.CSharp {
22 public class MemberName {
24 public readonly MemberName Left;
26 public static readonly MemberName Null = new MemberName ("");
28 public MemberName (string name)
33 public MemberName (MemberName left, string name)
39 public MemberName (MemberName left, MemberName right)
40 : this (left, right.Name)
44 public string GetName ()
46 return GetName (false);
49 public string GetName (bool is_generic)
51 string name = is_generic ? Basename : Name;
53 return Left.GetName (is_generic) + "." + name;
58 public string GetFullName ()
61 return Left.GetFullName () + "." + Name;
66 public string GetTypeName ()
69 return Left.GetTypeName () + "." + Name;
74 public Expression GetTypeExpression (Location loc)
77 Expression lexpr = Left.GetTypeExpression (loc);
79 return new MemberAccess (lexpr, Name, loc);
81 return new SimpleName (Name, loc);
85 public MemberName Clone ()
88 return new MemberName (Left.Clone (), Name);
90 return new MemberName (Name);
93 public string Basename {
99 public override string ToString ()
101 return GetFullName ();
106 /// Base representation for members. This is used to keep track
107 /// of Name, Location and Modifier flags, and handling Attributes.
109 public abstract class MemberCore : Attributable {
115 // !(this is GenericMethod) && !(this is Method)
116 return MemberName.GetName (false);
120 public readonly MemberName MemberName;
123 /// Modifier flags that the user specified in the source code
127 public readonly TypeContainer Parent;
130 /// Location where this declaration happens
132 public readonly Location Location;
136 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
137 Obsolete = 1 << 1, // Type has obsolete attribute
138 ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
139 ClsCompliant = 1 << 3, // Type is CLS Compliant
140 CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
141 HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
142 HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
143 ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
144 Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
145 Excluded = 1 << 9, // Method is conditional
146 TestMethodDuplication = 1 << 10 // Test for duplication must be performed
150 /// MemberCore flags at first detected then cached
152 internal Flags caching_flags;
154 public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
161 caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
165 /// Tests presence of ObsoleteAttribute and report proper error
167 protected void CheckUsageOfObsoleteAttribute (Type type)
172 ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
173 if (obsolete_attr == null)
176 AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, Location);
179 public abstract bool Define ();
182 // Returns full member name for error message
184 public virtual string GetSignatureForError ()
190 /// Use this method when MethodBuilder is null
192 public virtual string GetSignatureForError (TypeContainer tc)
198 /// Base Emit method. This is also entry point for CLS-Compliant verification.
200 public virtual void Emit ()
202 // Hack with Parent == null is for EnumMember
203 if (Parent == null || (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent) == null))
204 VerifyObsoleteAttribute ();
206 if (!RootContext.VerifyClsCompliance)
209 VerifyClsCompliance (Parent);
212 public bool InUnsafe {
214 return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
219 // Whehter is it ok to use an unsafe pointer in this type container
221 public bool UnsafeOK (DeclSpace parent)
224 // First check if this MemberCore modifier flags has unsafe set
226 if ((ModFlags & Modifiers.UNSAFE) != 0)
229 if (parent.UnsafeContext)
232 Expression.UnsafeError (Location);
237 /// Returns instance of ObsoleteAttribute for this MemberCore
239 public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
241 // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
242 if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
246 caching_flags &= ~Flags.Obsolete_Undetected;
248 if (OptAttributes == null)
251 // TODO: remove this allocation
252 EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
253 null, null, ds.ModFlags, false);
255 Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
256 if (obsolete_attr == null)
259 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds);
260 if (obsolete == null)
263 caching_flags |= Flags.Obsolete;
268 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
270 public override bool IsClsCompliaceRequired (DeclSpace container)
272 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
273 return (caching_flags & Flags.ClsCompliant) != 0;
275 if (GetClsCompliantAttributeValue (container) && IsExposedFromAssembly (container)) {
276 caching_flags &= ~Flags.ClsCompliance_Undetected;
277 caching_flags |= Flags.ClsCompliant;
281 caching_flags &= ~Flags.ClsCompliance_Undetected;
286 /// Returns true when MemberCore is exposed from assembly.
288 protected bool IsExposedFromAssembly (DeclSpace ds)
290 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
293 DeclSpace parentContainer = ds;
294 while (parentContainer != null && parentContainer.ModFlags != 0) {
295 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
297 parentContainer = parentContainer.Parent;
303 /// Resolve CLSCompliantAttribute value or gets cached value.
305 bool GetClsCompliantAttributeValue (DeclSpace ds)
307 if (OptAttributes != null) {
308 EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
309 null, null, ds.ModFlags, false);
310 Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
311 if (cls_attribute != null) {
312 caching_flags |= Flags.HasClsCompliantAttribute;
313 return cls_attribute.GetClsCompliantAttributeValue (ds);
316 return ds.GetClsCompliantAttributeValue ();
320 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
322 protected bool HasClsCompliantAttribute {
324 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
330 /// The main virtual method for CLS-Compliant verifications.
331 /// The method returns true if member is CLS-Compliant and false if member is not
332 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
333 /// and add their extra verifications.
335 protected virtual bool VerifyClsCompliance (DeclSpace ds)
337 if (!IsClsCompliaceRequired (ds)) {
338 if ((RootContext.WarningLevel >= 2) && HasClsCompliantAttribute && !IsExposedFromAssembly (ds)) {
339 Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
344 if (!CodeGen.Assembly.IsClsCompliant) {
345 if (HasClsCompliantAttribute) {
346 Report.Error (3014, Location, "'{0}' cannot be marked as CLS-compliant because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
351 int index = Name.LastIndexOf ('.');
352 if (Name [index > 0 ? index + 1 : 0] == '_') {
353 Report.Error (3008, Location, "Identifier '{0}' is not CLS-compliant", GetSignatureForError () );
358 protected abstract void VerifyObsoleteAttribute ();
363 /// Base class for structs, classes, enumerations and interfaces.
366 /// They all create new declaration spaces. This
367 /// provides the common foundation for managing those name
370 public abstract class DeclSpace : MemberCore {
372 /// this points to the actual definition that is being
373 /// created with System.Reflection.Emit
375 public TypeBuilder TypeBuilder;
378 // This is the namespace in which this typecontainer
379 // was declared. We use this to resolve names.
381 public NamespaceEntry NamespaceEntry;
383 public Hashtable Cache = new Hashtable ();
385 public string Basename;
387 protected Hashtable defined_names;
389 static string[] attribute_targets = new string [] { "type" };
391 public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
392 Attributes attrs, Location l)
393 : base (parent, name, attrs, l)
396 Basename = name.Name;
397 defined_names = new Hashtable ();
401 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
403 protected bool AddToContainer (MemberCore symbol, bool is_method, string fullname, string basename)
405 if (basename == Basename) {
406 Report.SymbolRelatedToPreviousError (this);
407 Report.Error (542, "'{0}': member names cannot be the same as their enclosing type", symbol.Location, symbol.GetSignatureForError ());
411 MemberCore mc = (MemberCore)defined_names [fullname];
413 if (is_method && (mc is MethodCore || mc is IMethodData)) {
414 symbol.caching_flags |= Flags.TestMethodDuplication;
415 mc.caching_flags |= Flags.TestMethodDuplication;
420 Report.SymbolRelatedToPreviousError (mc);
421 Report.Error (102, symbol.Location, "The type '{0}' already contains a definition for '{1}'", GetSignatureForError (), basename);
425 defined_names.Add (fullname, symbol);
429 public void RecordDecl ()
431 if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
432 NamespaceEntry.DefineName (MemberName.Basename, this);
436 /// Returns the MemberCore associated with a given name in the declaration
437 /// space. It doesn't return method based symbols !!
440 public MemberCore GetDefinition (string name)
442 return (MemberCore)defined_names [name];
445 bool in_transit = false;
448 /// This function is used to catch recursive definitions
451 public bool InTransit {
462 /// Looks up the alias for the name
464 public string LookupAlias (string name)
466 if (NamespaceEntry != null)
467 return NamespaceEntry.LookupAlias (name);
473 // root_types contains all the types. All TopLevel types
474 // hence have a parent that points to `root_types', that is
475 // why there is a non-obvious test down here.
477 public bool IsTopLevel {
480 if (Parent.Parent == null)
487 public virtual void CloseType ()
489 if ((caching_flags & Flags.CloseTypeCreated) == 0){
491 TypeBuilder.CreateType ();
494 // The try/catch is needed because
495 // nested enumerations fail to load when they
498 // Even if this is the right order (enumerations
499 // declared after types).
501 // Note that this still creates the type and
502 // it is possible to save it
504 caching_flags |= Flags.CloseTypeCreated;
509 /// Should be overriten by the appropriate declaration space
511 public abstract TypeBuilder DefineType ();
514 /// Define all members, but don't apply any attributes or do anything which may
515 /// access not-yet-defined classes. This method also creates the MemberCache.
517 public abstract bool DefineMembers (TypeContainer parent);
520 // Whether this is an `unsafe context'
522 public bool UnsafeContext {
524 if ((ModFlags & Modifiers.UNSAFE) != 0)
527 return Parent.UnsafeContext;
532 public static string MakeFQN (string nsn, string name)
536 return String.Concat (nsn, ".", name);
539 EmitContext type_resolve_ec;
540 EmitContext GetTypeResolveEmitContext (TypeContainer parent, Location loc)
542 type_resolve_ec = new EmitContext (parent, this, loc, null, null, ModFlags, false);
543 type_resolve_ec.ResolvingTypeTree = true;
545 return type_resolve_ec;
549 // Looks up the type, as parsed into the expression `e'.
551 //[Obsolete ("This method is going away soon")]
552 public Type ResolveType (Expression e, bool silent, Location loc)
554 TypeExpr d = ResolveTypeExpr (e, silent, loc);
555 return d == null ? null : d.Type;
559 // Resolves the expression `e' for a type, and will recursively define
560 // types. This should only be used for resolving base types.
562 public TypeExpr ResolveTypeExpr (Expression e, bool silent, Location loc)
564 if (type_resolve_ec == null)
565 type_resolve_ec = GetTypeResolveEmitContext (Parent, loc);
566 type_resolve_ec.loc = loc;
567 type_resolve_ec.ContainerType = TypeBuilder;
569 return e.ResolveAsTypeTerminal (type_resolve_ec, silent);
572 public bool CheckAccessLevel (Type check_type)
574 if (check_type == TypeBuilder)
577 TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
580 // Broken Microsoft runtime, return public for arrays, no matter what
581 // the accessibility is for their underlying class, and they return
582 // NonPublic visibility for pointers
584 if (check_type.IsArray || check_type.IsPointer)
585 return CheckAccessLevel (TypeManager.GetElementType (check_type));
587 if (TypeBuilder == null)
588 // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
589 // However, this is invoked again later -- so safe to return true.
590 // May also be null when resolving top-level attributes.
594 case TypeAttributes.Public:
597 case TypeAttributes.NotPublic:
599 // This test should probably use the declaringtype.
601 return check_type.Assembly == TypeBuilder.Assembly;
603 case TypeAttributes.NestedPublic:
606 case TypeAttributes.NestedPrivate:
607 return NestedAccessible (check_type);
609 case TypeAttributes.NestedFamily:
610 return FamilyAccessible (check_type);
612 case TypeAttributes.NestedFamANDAssem:
613 return (check_type.Assembly == TypeBuilder.Assembly) &&
614 FamilyAccessible (check_type);
616 case TypeAttributes.NestedFamORAssem:
617 return (check_type.Assembly == TypeBuilder.Assembly) ||
618 FamilyAccessible (check_type);
620 case TypeAttributes.NestedAssembly:
621 return check_type.Assembly == TypeBuilder.Assembly;
624 Console.WriteLine ("HERE: " + check_attr);
629 protected bool NestedAccessible (Type check_type)
631 string check_type_name = check_type.FullName;
633 // At this point, we already know check_type is a nested class.
634 int cio = check_type_name.LastIndexOf ('+');
636 // Ensure that the string 'container' has a '+' in it to avoid false matches
637 string container = check_type_name.Substring (0, cio + 1);
639 // Ensure that type_name ends with a '+' so that it can match 'container', if necessary
640 string type_name = TypeBuilder.FullName + "+";
642 // If the current class is nested inside the container of check_type,
643 // we can access check_type even if it is private or protected.
644 return type_name.StartsWith (container);
647 protected bool FamilyAccessible (Type check_type)
649 Type declaring = check_type.DeclaringType;
650 if (TypeBuilder == declaring ||
651 TypeBuilder.IsSubclassOf (declaring))
654 return NestedAccessible (check_type);
657 // Access level of a type.
659 enum AccessLevel { // Each column represents `is this scope larger or equal to Blah scope'
660 // Public Assembly Protected
661 Protected = (0 << 0) | (0 << 1) | (X << 2),
662 Public = (X << 0) | (X << 1) | (X << 2),
663 Private = (0 << 0) | (0 << 1) | (0 << 2),
664 Internal = (0 << 0) | (X << 1) | (0 << 2),
665 ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
668 static AccessLevel GetAccessLevelFromModifiers (int flags)
670 if ((flags & Modifiers.INTERNAL) != 0) {
672 if ((flags & Modifiers.PROTECTED) != 0)
673 return AccessLevel.ProtectedOrInternal;
675 return AccessLevel.Internal;
677 } else if ((flags & Modifiers.PROTECTED) != 0)
678 return AccessLevel.Protected;
680 else if ((flags & Modifiers.PRIVATE) != 0)
681 return AccessLevel.Private;
684 return AccessLevel.Public;
687 // What is the effective access level of this?
689 AccessLevel EffectiveAccessLevel {
691 AccessLevel myAccess = GetAccessLevelFromModifiers (ModFlags);
692 if (!IsTopLevel && (Parent != null))
693 return myAccess & Parent.EffectiveAccessLevel;
699 // Return the access level for type `t'
700 static AccessLevel TypeEffectiveAccessLevel (Type t)
703 return AccessLevel.Public;
704 if (t.IsNestedPrivate)
705 return AccessLevel.Private;
707 return AccessLevel.Internal;
709 // By now, it must be nested
710 AccessLevel parentLevel = TypeEffectiveAccessLevel (t.DeclaringType);
712 if (t.IsNestedPublic)
714 if (t.IsNestedAssembly)
715 return parentLevel & AccessLevel.Internal;
716 if (t.IsNestedFamily)
717 return parentLevel & AccessLevel.Protected;
718 if (t.IsNestedFamORAssem)
719 return parentLevel & AccessLevel.ProtectedOrInternal;
720 if (t.IsNestedFamANDAssem)
721 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
723 // nested private is taken care of
725 throw new Exception ("I give up, what are you?");
729 // This answers `is the type P, as accessible as a member M which has the
730 // accessability @flags which is declared as a nested member of the type T, this declspace'
732 public bool AsAccessible (Type p, int flags)
735 // 1) if M is private, its accessability is the same as this declspace.
736 // we already know that P is accessible to T before this method, so we
740 if ((flags & Modifiers.PRIVATE) != 0)
743 while (p.IsArray || p.IsPointer || p.IsByRef)
744 p = TypeManager.GetElementType (p);
746 AccessLevel pAccess = TypeEffectiveAccessLevel (p);
747 AccessLevel mAccess = this.EffectiveAccessLevel &
748 GetAccessLevelFromModifiers (flags);
750 // for every place from which we can access M, we must
751 // be able to access P as well. So, we want
752 // For every bit in M and P, M_i -> P_1 == true
753 // or, ~ (M -> P) == 0 <-> ~ ( ~M | P) == 0
755 return ~ (~ mAccess | pAccess) == 0;
758 static DoubleHash dh = new DoubleHash (1000);
760 Type DefineTypeAndParents (DeclSpace tc)
762 DeclSpace container = tc.Parent;
764 if (container.TypeBuilder == null && container.Name != "")
765 DefineTypeAndParents (container);
767 return tc.DefineType ();
770 Type LookupInterfaceOrClass (string ns, string name, out bool error)
777 int p = name.LastIndexOf ('.');
779 if (dh.Lookup (ns, name, out r))
783 // If the type is not a nested type, we do not need `LookupType's processing.
784 // If the @name does not have a `.' in it, this cant be a nested type.
787 if (Namespace.IsNamespace (ns)) {
789 t = TypeManager.LookupType (ns + "." + name);
791 t = TypeManager.LookupTypeDirect (ns + "." + name);
795 t = TypeManager.LookupType (name);
797 t = TypeManager.LookupTypeDirect (name);
801 dh.Insert (ns, name, t);
806 // In case we are fed a composite name, normalize it.
810 ns = MakeFQN (ns, name.Substring (0, p));
811 name = name.Substring (p+1);
814 parent = RootContext.Tree.LookupByNamespace (ns, name);
815 if (parent == null) {
816 dh.Insert (ns, name, null);
820 t = DefineTypeAndParents (parent);
826 dh.Insert (ns, name, t);
830 public static void Error_AmbiguousTypeReference (Location loc, string name, Type t1, Type t2)
832 Report.Error (104, loc,
833 String.Format ("`{0}' is an ambiguous reference ({1} or {2}) ", name,
834 t1.FullName, t2.FullName));
838 /// GetType is used to resolve type names at the DeclSpace level.
839 /// Use this to lookup class/struct bases, interface bases or
840 /// delegate type references
844 /// Contrast this to LookupType which is used inside method bodies to
845 /// lookup types that have already been defined. GetType is used
846 /// during the tree resolution process and potentially define
847 /// recursively the type
849 public Type FindType (Location loc, string name)
855 // For the case the type we are looking for is nested within this one
856 // or is in any base class
858 DeclSpace containing_ds = this;
860 while (containing_ds != null){
861 Type container_type = containing_ds.TypeBuilder;
862 Type current_type = container_type;
864 while (current_type != null && current_type != TypeManager.object_type) {
865 string pre = current_type.FullName;
867 t = LookupInterfaceOrClass (pre, name, out error);
871 if ((t != null) && containing_ds.CheckAccessLevel (t))
874 current_type = current_type.BaseType;
876 containing_ds = containing_ds.Parent;
880 // Attempt to lookup the class on our namespace and all it's implicit parents
882 for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
883 t = LookupInterfaceOrClass (ns.FullName, name, out error);
892 // Attempt to do a direct unqualified lookup
894 t = LookupInterfaceOrClass ("", name, out error);
902 // Attempt to lookup the class on any of the `using'
906 for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.Parent){
908 t = LookupInterfaceOrClass (ns.FullName, name, out error);
915 if (name.IndexOf ('.') > 0)
918 string alias_value = ns.LookupAlias (name);
919 if (alias_value != null) {
920 t = LookupInterfaceOrClass ("", alias_value, out error);
929 // Now check the using clause list
932 foreach (Namespace using_ns in ns.GetUsingTable ()) {
933 match = LookupInterfaceOrClass (using_ns.Name, name, out error);
939 if (CheckAccessLevel (match)) {
940 Error_AmbiguousTypeReference (loc, name, t, match);
953 //Report.Error (246, Location, "Can not find type `"+name+"'");
958 /// This function is broken and not what you're looking for. It should only
959 /// be used while the type is still being created since it doesn't use the cache
960 /// and relies on the filter doing the member name check.
962 public abstract MemberList FindMembers (MemberTypes mt, BindingFlags bf,
963 MemberFilter filter, object criteria);
966 /// If we have a MemberCache, return it. This property may return null if the
967 /// class doesn't have a member cache or while it's still being created.
969 public abstract MemberCache MemberCache {
973 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
976 TypeBuilder.SetCustomAttribute (cb);
977 } catch (System.ArgumentException e) {
978 Report.Warning (-21, a.Location,
979 "The CharSet named property on StructLayout\n"+
980 "\tdoes not work correctly on Microsoft.NET\n"+
981 "\tYou might want to remove the CharSet declaration\n"+
982 "\tor compile using the Mono runtime instead of the\n"+
983 "\tMicrosoft .NET runtime\n"+
984 "\tThe runtime gave the error: " + e);
989 /// Goes through class hierarchy and get value of first CLSCompliantAttribute that found.
990 /// If no is attribute exists then return assembly CLSCompliantAttribute.
992 public bool GetClsCompliantAttributeValue ()
994 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
995 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
997 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
999 if (OptAttributes != null) {
1000 EmitContext ec = new EmitContext (Parent, this, Location,
1001 null, null, ModFlags, false);
1002 Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
1003 if (cls_attribute != null) {
1004 caching_flags |= Flags.HasClsCompliantAttribute;
1005 if (cls_attribute.GetClsCompliantAttributeValue (this)) {
1006 caching_flags |= Flags.ClsCompliantAttributeTrue;
1013 if (Parent == null) {
1014 if (CodeGen.Assembly.IsClsCompliant) {
1015 caching_flags |= Flags.ClsCompliantAttributeTrue;
1021 if (Parent.GetClsCompliantAttributeValue ()) {
1022 caching_flags |= Flags.ClsCompliantAttributeTrue;
1028 public override string[] ValidAttributeTargets {
1030 return attribute_targets;
1036 /// This is a readonly list of MemberInfo's.
1038 public class MemberList : IList {
1039 public readonly IList List;
1043 /// Create a new MemberList from the given IList.
1045 public MemberList (IList list)
1050 this.List = new ArrayList ();
1055 /// Concatenate the ILists `first' and `second' to a new MemberList.
1057 public MemberList (IList first, IList second)
1059 ArrayList list = new ArrayList ();
1060 list.AddRange (first);
1061 list.AddRange (second);
1066 public static readonly MemberList Empty = new MemberList (new ArrayList ());
1069 /// Cast the MemberList into a MemberInfo[] array.
1072 /// This is an expensive operation, only use it if it's really necessary.
1074 public static explicit operator MemberInfo [] (MemberList list)
1076 Timer.StartTimer (TimerType.MiscTimer);
1077 MemberInfo [] result = new MemberInfo [list.Count];
1078 list.CopyTo (result, 0);
1079 Timer.StopTimer (TimerType.MiscTimer);
1091 public bool IsSynchronized {
1093 return List.IsSynchronized;
1097 public object SyncRoot {
1099 return List.SyncRoot;
1103 public void CopyTo (Array array, int index)
1105 List.CopyTo (array, index);
1110 public IEnumerator GetEnumerator ()
1112 return List.GetEnumerator ();
1117 public bool IsFixedSize {
1123 public bool IsReadOnly {
1129 object IList.this [int index] {
1131 return List [index];
1135 throw new NotSupportedException ();
1139 // FIXME: try to find out whether we can avoid the cast in this indexer.
1140 public MemberInfo this [int index] {
1142 return (MemberInfo) List [index];
1146 public int Add (object value)
1148 throw new NotSupportedException ();
1151 public void Clear ()
1153 throw new NotSupportedException ();
1156 public bool Contains (object value)
1158 return List.Contains (value);
1161 public int IndexOf (object value)
1163 return List.IndexOf (value);
1166 public void Insert (int index, object value)
1168 throw new NotSupportedException ();
1171 public void Remove (object value)
1173 throw new NotSupportedException ();
1176 public void RemoveAt (int index)
1178 throw new NotSupportedException ();
1183 /// This interface is used to get all members of a class when creating the
1184 /// member cache. It must be implemented by all DeclSpace derivatives which
1185 /// want to support the member cache and by TypeHandle to get caching of
1186 /// non-dynamic types.
1188 public interface IMemberContainer {
1190 /// The name of the IMemberContainer. This is only used for
1191 /// debugging purposes.
1198 /// The type of this IMemberContainer.
1205 /// Returns the IMemberContainer of the parent class or null if this
1206 /// is an interface or TypeManger.object_type.
1207 /// This is used when creating the member cache for a class to get all
1208 /// members from the parent class.
1210 IMemberContainer ParentContainer {
1215 /// Whether this is an interface.
1222 /// Returns all members of this class with the corresponding MemberTypes
1223 /// and BindingFlags.
1226 /// When implementing this method, make sure not to return any inherited
1227 /// members and check the MemberTypes and BindingFlags properly.
1228 /// Unfortunately, System.Reflection is lame and doesn't provide a way to
1229 /// get the BindingFlags (static/non-static,public/non-public) in the
1230 /// MemberInfo class, but the cache needs this information. That's why
1231 /// this method is called multiple times with different BindingFlags.
1233 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1236 /// Return the container's member cache.
1238 MemberCache MemberCache {
1244 /// The MemberCache is used by dynamic and non-dynamic types to speed up
1245 /// member lookups. It has a member name based hash table; it maps each member
1246 /// name to a list of CacheEntry objects. Each CacheEntry contains a MemberInfo
1247 /// and the BindingFlags that were initially used to get it. The cache contains
1248 /// all members of the current class and all inherited members. If this cache is
1249 /// for an interface types, it also contains all inherited members.
1251 /// There are two ways to get a MemberCache:
1252 /// * if this is a dynamic type, lookup the corresponding DeclSpace and then
1253 /// use the DeclSpace.MemberCache property.
1254 /// * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1255 /// TypeHandle instance for the type and then use TypeHandle.MemberCache.
1257 public class MemberCache {
1258 public readonly IMemberContainer Container;
1259 protected Hashtable member_hash;
1260 protected Hashtable method_hash;
1263 /// Create a new MemberCache for the given IMemberContainer `container'.
1265 public MemberCache (IMemberContainer container)
1267 this.Container = container;
1269 Timer.IncrementCounter (CounterType.MemberCache);
1270 Timer.StartTimer (TimerType.CacheInit);
1274 // If we have a parent class (we have a parent class unless we're
1275 // TypeManager.object_type), we deep-copy its MemberCache here.
1276 if (Container.IsInterface) {
1279 if (Container.ParentContainer != null)
1280 parent = Container.ParentContainer.MemberCache;
1282 parent = TypeHandle.ObjectType.MemberCache;
1283 member_hash = SetupCacheForInterface (parent);
1284 } else if (Container.ParentContainer != null)
1285 member_hash = SetupCache (Container.ParentContainer.MemberCache);
1287 member_hash = new Hashtable ();
1289 // If this is neither a dynamic type nor an interface, create a special
1290 // method cache with all declared and inherited methods.
1291 Type type = container.Type;
1292 if (!(type is TypeBuilder) && !type.IsInterface) {
1293 method_hash = new Hashtable ();
1297 // Add all members from the current class.
1298 AddMembers (Container);
1300 Timer.StopTimer (TimerType.CacheInit);
1304 /// Bootstrap this member cache by doing a deep-copy of our parent.
1306 Hashtable SetupCache (MemberCache parent)
1308 Hashtable hash = new Hashtable ();
1310 IDictionaryEnumerator it = parent.member_hash.GetEnumerator ();
1311 while (it.MoveNext ()) {
1312 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1320 /// Add the contents of `new_hash' to `hash'.
1322 void AddHashtable (Hashtable hash, MemberCache cache)
1324 Hashtable new_hash = cache.member_hash;
1325 IDictionaryEnumerator it = new_hash.GetEnumerator ();
1326 while (it.MoveNext ()) {
1327 ArrayList list = (ArrayList) hash [it.Key];
1329 hash [it.Key] = list = new ArrayList ();
1331 foreach (CacheEntry entry in (ArrayList) it.Value) {
1332 if (entry.Container != cache.Container)
1340 /// Bootstrap the member cache for an interface type.
1341 /// Type.GetMembers() won't return any inherited members for interface types,
1342 /// so we need to do this manually. Interfaces also inherit from System.Object.
1344 Hashtable SetupCacheForInterface (MemberCache parent)
1346 Hashtable hash = SetupCache (parent);
1347 TypeExpr [] ifaces = TypeManager.GetInterfaces (Container.Type);
1349 foreach (TypeExpr iface in ifaces) {
1350 Type itype = iface.Type;
1352 IMemberContainer iface_container =
1353 TypeManager.LookupMemberContainer (itype);
1355 MemberCache iface_cache = iface_container.MemberCache;
1357 AddHashtable (hash, iface_cache);
1364 /// Add all members from class `container' to the cache.
1366 void AddMembers (IMemberContainer container)
1368 // We need to call AddMembers() with a single member type at a time
1369 // to get the member type part of CacheEntry.EntryType right.
1370 AddMembers (MemberTypes.Constructor, container);
1371 AddMembers (MemberTypes.Field, container);
1372 AddMembers (MemberTypes.Method, container);
1373 AddMembers (MemberTypes.Property, container);
1374 AddMembers (MemberTypes.Event, container);
1375 // Nested types are returned by both Static and Instance searches.
1376 AddMembers (MemberTypes.NestedType,
1377 BindingFlags.Static | BindingFlags.Public, container);
1378 AddMembers (MemberTypes.NestedType,
1379 BindingFlags.Static | BindingFlags.NonPublic, container);
1382 void AddMembers (MemberTypes mt, IMemberContainer container)
1384 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1385 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1386 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1387 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1391 /// Add all members from class `container' with the requested MemberTypes and
1392 /// BindingFlags to the cache. This method is called multiple times with different
1393 /// MemberTypes and BindingFlags.
1395 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1397 MemberList members = container.GetMembers (mt, bf);
1399 foreach (MemberInfo member in members) {
1400 string name = member.Name;
1402 // We use a name-based hash table of ArrayList's.
1403 ArrayList list = (ArrayList) member_hash [name];
1405 list = new ArrayList ();
1406 member_hash.Add (name, list);
1409 // When this method is called for the current class, the list will
1410 // already contain all inherited members from our parent classes.
1411 // We cannot add new members in front of the list since this'd be an
1412 // expensive operation, that's why the list is sorted in reverse order
1413 // (ie. members from the current class are coming last).
1414 list.Add (new CacheEntry (container, member, mt, bf));
1419 /// Add all declared and inherited methods from class `type' to the method cache.
1421 void AddMethods (Type type)
1423 AddMethods (BindingFlags.Static | BindingFlags.Public |
1424 BindingFlags.FlattenHierarchy, type);
1425 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1426 BindingFlags.FlattenHierarchy, type);
1427 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1428 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1431 void AddMethods (BindingFlags bf, Type type)
1433 MemberInfo [] members = type.GetMethods (bf);
1435 Array.Reverse (members);
1437 foreach (MethodBase member in members) {
1438 string name = member.Name;
1440 // We use a name-based hash table of ArrayList's.
1441 ArrayList list = (ArrayList) method_hash [name];
1443 list = new ArrayList ();
1444 method_hash.Add (name, list);
1447 // Unfortunately, the elements returned by Type.GetMethods() aren't
1448 // sorted so we need to do this check for every member.
1449 BindingFlags new_bf = bf;
1450 if (member.DeclaringType == type)
1451 new_bf |= BindingFlags.DeclaredOnly;
1453 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1460 /// Compute and return a appropriate `EntryType' magic number for the given
1461 /// MemberTypes and BindingFlags.
1463 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1465 EntryType type = EntryType.None;
1467 if ((mt & MemberTypes.Constructor) != 0)
1468 type |= EntryType.Constructor;
1469 if ((mt & MemberTypes.Event) != 0)
1470 type |= EntryType.Event;
1471 if ((mt & MemberTypes.Field) != 0)
1472 type |= EntryType.Field;
1473 if ((mt & MemberTypes.Method) != 0)
1474 type |= EntryType.Method;
1475 if ((mt & MemberTypes.Property) != 0)
1476 type |= EntryType.Property;
1477 // Nested types are returned by static and instance searches.
1478 if ((mt & MemberTypes.NestedType) != 0)
1479 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1481 if ((bf & BindingFlags.Instance) != 0)
1482 type |= EntryType.Instance;
1483 if ((bf & BindingFlags.Static) != 0)
1484 type |= EntryType.Static;
1485 if ((bf & BindingFlags.Public) != 0)
1486 type |= EntryType.Public;
1487 if ((bf & BindingFlags.NonPublic) != 0)
1488 type |= EntryType.NonPublic;
1489 if ((bf & BindingFlags.DeclaredOnly) != 0)
1490 type |= EntryType.Declared;
1496 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1497 /// denote multiple member types. Returns true if the given flags value denotes a
1498 /// single member types.
1500 public static bool IsSingleMemberType (MemberTypes mt)
1503 case MemberTypes.Constructor:
1504 case MemberTypes.Event:
1505 case MemberTypes.Field:
1506 case MemberTypes.Method:
1507 case MemberTypes.Property:
1508 case MemberTypes.NestedType:
1517 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
1518 /// number to speed up the searching process.
1521 protected enum EntryType {
1526 MaskStatic = Instance|Static,
1530 MaskProtection = Public|NonPublic,
1534 Constructor = 0x020,
1541 MaskType = Constructor|Event|Field|Method|Property|NestedType
1544 protected struct CacheEntry {
1545 public readonly IMemberContainer Container;
1546 public readonly EntryType EntryType;
1547 public readonly MemberInfo Member;
1549 public CacheEntry (IMemberContainer container, MemberInfo member,
1550 MemberTypes mt, BindingFlags bf)
1552 this.Container = container;
1553 this.Member = member;
1554 this.EntryType = GetEntryType (mt, bf);
1559 /// This is called each time we're walking up one level in the class hierarchy
1560 /// and checks whether we can abort the search since we've already found what
1561 /// we were looking for.
1563 protected bool DoneSearching (ArrayList list)
1566 // We've found exactly one member in the current class and it's not
1567 // a method or constructor.
1569 if (list.Count == 1 && !(list [0] is MethodBase))
1573 // Multiple properties: we query those just to find out the indexer
1576 if ((list.Count > 0) && (list [0] is PropertyInfo))
1583 /// Looks up members with name `name'. If you provide an optional
1584 /// filter function, it'll only be called with members matching the
1585 /// requested member name.
1587 /// This method will try to use the cache to do the lookup if possible.
1589 /// Unlike other FindMembers implementations, this method will always
1590 /// check all inherited members - even when called on an interface type.
1592 /// If you know that you're only looking for methods, you should use
1593 /// MemberTypes.Method alone since this speeds up the lookup a bit.
1594 /// When doing a method-only search, it'll try to use a special method
1595 /// cache (unless it's a dynamic type or an interface) and the returned
1596 /// MemberInfo's will have the correct ReflectedType for inherited methods.
1597 /// The lookup process will automatically restart itself in method-only
1598 /// search mode if it discovers that it's about to return methods.
1600 ArrayList global = new ArrayList ();
1601 bool using_global = false;
1603 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1605 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1606 MemberFilter filter, object criteria)
1609 throw new Exception ();
1611 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1612 bool method_search = mt == MemberTypes.Method;
1613 // If we have a method cache and we aren't already doing a method-only search,
1614 // then we restart a method search if the first match is a method.
1615 bool do_method_search = !method_search && (method_hash != null);
1617 ArrayList applicable;
1619 // If this is a method-only search, we try to use the method cache if
1620 // possible; a lookup in the method cache will return a MemberInfo with
1621 // the correct ReflectedType for inherited methods.
1623 if (method_search && (method_hash != null))
1624 applicable = (ArrayList) method_hash [name];
1626 applicable = (ArrayList) member_hash [name];
1628 if (applicable == null)
1629 return emptyMemberInfo;
1632 // 32 slots gives 53 rss/54 size
1633 // 2/4 slots gives 55 rss
1635 // Strange: from 25,000 calls, only 1,800
1636 // are above 2. Why does this impact it?
1639 using_global = true;
1641 Timer.StartTimer (TimerType.CachedLookup);
1643 EntryType type = GetEntryType (mt, bf);
1645 IMemberContainer current = Container;
1648 // `applicable' is a list of all members with the given member name `name'
1649 // in the current class and all its parent classes. The list is sorted in
1650 // reverse order due to the way how the cache is initialy created (to speed
1651 // things up, we're doing a deep-copy of our parent).
1653 for (int i = applicable.Count-1; i >= 0; i--) {
1654 CacheEntry entry = (CacheEntry) applicable [i];
1656 // This happens each time we're walking one level up in the class
1657 // hierarchy. If we're doing a DeclaredOnly search, we must abort
1658 // the first time this happens (this may already happen in the first
1659 // iteration of this loop if there are no members with the name we're
1660 // looking for in the current class).
1661 if (entry.Container != current) {
1662 if (declared_only || DoneSearching (global))
1665 current = entry.Container;
1668 // Is the member of the correct type ?
1669 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1672 // Is the member static/non-static ?
1673 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1676 // Apply the filter to it.
1677 if (filter (entry.Member, criteria)) {
1678 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method)
1679 do_method_search = false;
1680 global.Add (entry.Member);
1684 Timer.StopTimer (TimerType.CachedLookup);
1686 // If we have a method cache and we aren't already doing a method-only
1687 // search, we restart in method-only search mode if the first match is
1688 // a method. This ensures that we return a MemberInfo with the correct
1689 // ReflectedType for inherited methods.
1690 if (do_method_search && (global.Count > 0)){
1691 using_global = false;
1693 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1696 using_global = false;
1697 MemberInfo [] copy = new MemberInfo [global.Count];
1698 global.CopyTo (copy);
1702 // find the nested type @name in @this.
1703 public Type FindNestedType (string name)
1705 ArrayList applicable = (ArrayList) member_hash [name];
1706 if (applicable == null)
1709 for (int i = applicable.Count-1; i >= 0; i--) {
1710 CacheEntry entry = (CacheEntry) applicable [i];
1711 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1712 return (Type) entry.Member;
1719 // This finds the method or property for us to override. invocationType is the type where
1720 // the override is going to be declared, name is the name of the method/property, and
1721 // paramTypes is the parameters, if any to the method or property
1723 // Because the MemberCache holds members from this class and all the base classes,
1724 // we can avoid tons of reflection stuff.
1726 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1728 ArrayList applicable;
1729 if (method_hash != null && !is_property)
1730 applicable = (ArrayList) method_hash [name];
1732 applicable = (ArrayList) member_hash [name];
1734 if (applicable == null)
1737 // Walk the chain of methods, starting from the top.
1739 for (int i = applicable.Count - 1; i >= 0; i--) {
1740 CacheEntry entry = (CacheEntry) applicable [i];
1742 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1745 PropertyInfo pi = null;
1746 MethodInfo mi = null;
1747 FieldInfo fi = null;
1748 Type [] cmpAttrs = null;
1751 if ((entry.EntryType & EntryType.Field) != 0) {
1752 fi = (FieldInfo)entry.Member;
1754 // TODO: For this case we ignore member type
1755 //fb = TypeManager.GetField (fi);
1756 //cmpAttrs = new Type[] { fb.MemberType };
1758 pi = (PropertyInfo) entry.Member;
1759 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1762 mi = (MethodInfo) entry.Member;
1763 cmpAttrs = TypeManager.GetArgumentTypes (mi);
1767 // TODO: Almost duplicate !
1769 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1770 case FieldAttributes.Private:
1772 // A private method is Ok if we are a nested subtype.
1773 // The spec actually is not very clear about this, see bug 52458.
1775 if (invocationType != entry.Container.Type &
1776 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1780 case FieldAttributes.FamANDAssem:
1781 case FieldAttributes.Assembly:
1783 // Check for assembly methods
1785 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1789 return entry.Member;
1793 // Check the arguments
1795 if (cmpAttrs.Length != paramTypes.Length)
1798 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1799 if (paramTypes [j] != cmpAttrs [j])
1803 // get one of the methods because this has the visibility info.
1806 mi = pi.GetGetMethod (true);
1808 mi = pi.GetSetMethod (true);
1814 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1815 case MethodAttributes.Private:
1817 // A private method is Ok if we are a nested subtype.
1818 // The spec actually is not very clear about this, see bug 52458.
1820 if (invocationType == entry.Container.Type ||
1821 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1822 return entry.Member;
1825 case MethodAttributes.FamANDAssem:
1826 case MethodAttributes.Assembly:
1828 // Check for assembly methods
1830 if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1831 return entry.Member;
1836 // A protected method is ok, because we are overriding.
1837 // public is always ok.
1839 return entry.Member;
1849 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1850 /// We handle two cases. The first is for types without parameters (events, field, properties).
1851 /// The second are methods, indexers and this is why ignore_complex_types is here.
1852 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1854 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1856 ArrayList applicable = null;
1858 if (method_hash != null)
1859 applicable = (ArrayList) method_hash [name];
1861 if (applicable != null) {
1862 for (int i = applicable.Count - 1; i >= 0; i--) {
1863 CacheEntry entry = (CacheEntry) applicable [i];
1864 if ((entry.EntryType & EntryType.Public) != 0)
1865 return entry.Member;
1869 if (member_hash == null)
1871 applicable = (ArrayList) member_hash [name];
1873 if (applicable != null) {
1874 for (int i = applicable.Count - 1; i >= 0; i--) {
1875 CacheEntry entry = (CacheEntry) applicable [i];
1876 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1877 if (ignore_complex_types) {
1878 if ((entry.EntryType & EntryType.Method) != 0)
1881 // Does exist easier way how to detect indexer ?
1882 if ((entry.EntryType & EntryType.Property) != 0) {
1883 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1884 if (arg_types.Length > 0)
1888 return entry.Member;
1895 Hashtable locase_table;
1898 /// Builds low-case table for CLS Compliance test
1900 public Hashtable GetPublicMembers ()
1902 if (locase_table != null)
1903 return locase_table;
1905 locase_table = new Hashtable ();
1906 foreach (DictionaryEntry entry in member_hash) {
1907 ArrayList members = (ArrayList)entry.Value;
1908 for (int ii = 0; ii < members.Count; ++ii) {
1909 CacheEntry member_entry = (CacheEntry) members [ii];
1911 if ((member_entry.EntryType & EntryType.Public) == 0)
1914 // TODO: Does anyone know easier way how to detect that member is internal ?
1915 switch (member_entry.EntryType & EntryType.MaskType) {
1916 case EntryType.Constructor:
1919 case EntryType.Field:
1920 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
1924 case EntryType.Method:
1925 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1929 case EntryType.Property:
1930 PropertyInfo pi = (PropertyInfo)member_entry.Member;
1931 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
1935 case EntryType.Event:
1936 EventInfo ei = (EventInfo)member_entry.Member;
1937 MethodInfo mi = ei.GetAddMethod ();
1938 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1942 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
1943 locase_table [lcase] = member_entry.Member;
1947 return locase_table;
1950 public Hashtable Members {
1957 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
1959 public void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
1961 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
1963 for (int i = 0; i < al.Count; ++i) {
1964 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
1967 if (entry.Member == this_builder)
1970 if ((entry.EntryType & tested_type) != tested_type)
1973 MethodBase method_to_compare = (MethodBase)entry.Member;
1974 if (AttributeTester.AreOverloadedMethodParamsClsCompliant (method.ParameterTypes, TypeManager.GetArgumentTypes (method_to_compare)))
1977 IMethodData md = TypeManager.GetMethod (method_to_compare);
1979 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
1980 // However it is exactly what csc does.
1981 if (md != null && !md.IsClsCompliaceRequired (method.Parent))
1984 Report.SymbolRelatedToPreviousError (entry.Member);
1985 Report.Error (3006, method.Location, "Overloaded method '{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());