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 && !(this is Interface)) {
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, bool setup_inherited_interfaces)
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;
1283 member_hash = SetupCacheForInterface (parent, setup_inherited_interfaces);
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 ();
1312 IDictionaryEnumerator it = parent.member_hash.GetEnumerator ();
1313 while (it.MoveNext ()) {
1314 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1322 /// Add the contents of `new_hash' to `hash'.
1324 void AddHashtable (Hashtable hash, MemberCache cache)
1326 Hashtable new_hash = cache.member_hash;
1327 IDictionaryEnumerator it = new_hash.GetEnumerator ();
1328 while (it.MoveNext ()) {
1329 ArrayList list = (ArrayList) hash [it.Key];
1331 hash [it.Key] = list = new ArrayList ();
1333 foreach (CacheEntry entry in (ArrayList) it.Value) {
1334 if (entry.Container != cache.Container)
1342 /// Bootstrap the member cache for an interface type.
1343 /// Type.GetMembers() won't return any inherited members for interface types,
1344 /// so we need to do this manually. Interfaces also inherit from System.Object.
1346 Hashtable SetupCacheForInterface (MemberCache parent, bool deep_setup)
1348 Hashtable hash = SetupCache (parent);
1353 TypeExpr [] ifaces = TypeManager.GetInterfaces (Container.Type);
1355 foreach (TypeExpr iface in ifaces) {
1356 Type itype = iface.Type;
1358 IMemberContainer iface_container =
1359 TypeManager.LookupMemberContainer (itype);
1361 MemberCache iface_cache = iface_container.MemberCache;
1363 AddHashtable (hash, iface_cache);
1370 /// Add all members from class `container' to the cache.
1372 void AddMembers (IMemberContainer container)
1374 // We need to call AddMembers() with a single member type at a time
1375 // to get the member type part of CacheEntry.EntryType right.
1376 if (!container.IsInterface) {
1377 AddMembers (MemberTypes.Constructor, container);
1378 AddMembers (MemberTypes.Field, container);
1380 AddMembers (MemberTypes.Method, container);
1381 AddMembers (MemberTypes.Property, container);
1382 AddMembers (MemberTypes.Event, container);
1383 // Nested types are returned by both Static and Instance searches.
1384 AddMembers (MemberTypes.NestedType,
1385 BindingFlags.Static | BindingFlags.Public, container);
1386 AddMembers (MemberTypes.NestedType,
1387 BindingFlags.Static | BindingFlags.NonPublic, container);
1390 void AddMembers (MemberTypes mt, IMemberContainer container)
1392 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1393 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1394 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1395 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1399 /// Add all members from class `container' with the requested MemberTypes and
1400 /// BindingFlags to the cache. This method is called multiple times with different
1401 /// MemberTypes and BindingFlags.
1403 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1405 MemberList members = container.GetMembers (mt, bf);
1407 foreach (MemberInfo member in members) {
1408 string name = member.Name;
1410 // We use a name-based hash table of ArrayList's.
1411 ArrayList list = (ArrayList) member_hash [name];
1413 list = new ArrayList ();
1414 member_hash.Add (name, list);
1417 // When this method is called for the current class, the list will
1418 // already contain all inherited members from our parent classes.
1419 // We cannot add new members in front of the list since this'd be an
1420 // expensive operation, that's why the list is sorted in reverse order
1421 // (ie. members from the current class are coming last).
1422 list.Add (new CacheEntry (container, member, mt, bf));
1427 /// Add all declared and inherited methods from class `type' to the method cache.
1429 void AddMethods (Type type)
1431 AddMethods (BindingFlags.Static | BindingFlags.Public |
1432 BindingFlags.FlattenHierarchy, type);
1433 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1434 BindingFlags.FlattenHierarchy, type);
1435 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1436 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1439 void AddMethods (BindingFlags bf, Type type)
1441 MemberInfo [] members = type.GetMethods (bf);
1443 Array.Reverse (members);
1445 foreach (MethodBase member in members) {
1446 string name = member.Name;
1448 // We use a name-based hash table of ArrayList's.
1449 ArrayList list = (ArrayList) method_hash [name];
1451 list = new ArrayList ();
1452 method_hash.Add (name, list);
1455 // Unfortunately, the elements returned by Type.GetMethods() aren't
1456 // sorted so we need to do this check for every member.
1457 BindingFlags new_bf = bf;
1458 if (member.DeclaringType == type)
1459 new_bf |= BindingFlags.DeclaredOnly;
1461 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1468 /// Compute and return a appropriate `EntryType' magic number for the given
1469 /// MemberTypes and BindingFlags.
1471 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1473 EntryType type = EntryType.None;
1475 if ((mt & MemberTypes.Constructor) != 0)
1476 type |= EntryType.Constructor;
1477 if ((mt & MemberTypes.Event) != 0)
1478 type |= EntryType.Event;
1479 if ((mt & MemberTypes.Field) != 0)
1480 type |= EntryType.Field;
1481 if ((mt & MemberTypes.Method) != 0)
1482 type |= EntryType.Method;
1483 if ((mt & MemberTypes.Property) != 0)
1484 type |= EntryType.Property;
1485 // Nested types are returned by static and instance searches.
1486 if ((mt & MemberTypes.NestedType) != 0)
1487 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1489 if ((bf & BindingFlags.Instance) != 0)
1490 type |= EntryType.Instance;
1491 if ((bf & BindingFlags.Static) != 0)
1492 type |= EntryType.Static;
1493 if ((bf & BindingFlags.Public) != 0)
1494 type |= EntryType.Public;
1495 if ((bf & BindingFlags.NonPublic) != 0)
1496 type |= EntryType.NonPublic;
1497 if ((bf & BindingFlags.DeclaredOnly) != 0)
1498 type |= EntryType.Declared;
1504 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1505 /// denote multiple member types. Returns true if the given flags value denotes a
1506 /// single member types.
1508 public static bool IsSingleMemberType (MemberTypes mt)
1511 case MemberTypes.Constructor:
1512 case MemberTypes.Event:
1513 case MemberTypes.Field:
1514 case MemberTypes.Method:
1515 case MemberTypes.Property:
1516 case MemberTypes.NestedType:
1525 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
1526 /// number to speed up the searching process.
1529 protected internal enum EntryType {
1534 MaskStatic = Instance|Static,
1538 MaskProtection = Public|NonPublic,
1542 Constructor = 0x020,
1549 MaskType = Constructor|Event|Field|Method|Property|NestedType
1552 protected internal struct CacheEntry {
1553 public readonly IMemberContainer Container;
1554 public readonly EntryType EntryType;
1555 public readonly MemberInfo Member;
1557 public CacheEntry (IMemberContainer container, MemberInfo member,
1558 MemberTypes mt, BindingFlags bf)
1560 this.Container = container;
1561 this.Member = member;
1562 this.EntryType = GetEntryType (mt, bf);
1567 /// This is called each time we're walking up one level in the class hierarchy
1568 /// and checks whether we can abort the search since we've already found what
1569 /// we were looking for.
1571 protected bool DoneSearching (ArrayList list)
1574 // We've found exactly one member in the current class and it's not
1575 // a method or constructor.
1577 if (list.Count == 1 && !(list [0] is MethodBase))
1581 // Multiple properties: we query those just to find out the indexer
1584 if ((list.Count > 0) && (list [0] is PropertyInfo))
1591 /// Looks up members with name `name'. If you provide an optional
1592 /// filter function, it'll only be called with members matching the
1593 /// requested member name.
1595 /// This method will try to use the cache to do the lookup if possible.
1597 /// Unlike other FindMembers implementations, this method will always
1598 /// check all inherited members - even when called on an interface type.
1600 /// If you know that you're only looking for methods, you should use
1601 /// MemberTypes.Method alone since this speeds up the lookup a bit.
1602 /// When doing a method-only search, it'll try to use a special method
1603 /// cache (unless it's a dynamic type or an interface) and the returned
1604 /// MemberInfo's will have the correct ReflectedType for inherited methods.
1605 /// The lookup process will automatically restart itself in method-only
1606 /// search mode if it discovers that it's about to return methods.
1608 ArrayList global = new ArrayList ();
1609 bool using_global = false;
1611 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1613 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1614 MemberFilter filter, object criteria)
1617 throw new Exception ();
1619 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1620 bool method_search = mt == MemberTypes.Method;
1621 // If we have a method cache and we aren't already doing a method-only search,
1622 // then we restart a method search if the first match is a method.
1623 bool do_method_search = !method_search && (method_hash != null);
1625 ArrayList applicable;
1627 // If this is a method-only search, we try to use the method cache if
1628 // possible; a lookup in the method cache will return a MemberInfo with
1629 // the correct ReflectedType for inherited methods.
1631 if (method_search && (method_hash != null))
1632 applicable = (ArrayList) method_hash [name];
1634 applicable = (ArrayList) member_hash [name];
1636 if (applicable == null)
1637 return emptyMemberInfo;
1640 // 32 slots gives 53 rss/54 size
1641 // 2/4 slots gives 55 rss
1643 // Strange: from 25,000 calls, only 1,800
1644 // are above 2. Why does this impact it?
1647 using_global = true;
1649 Timer.StartTimer (TimerType.CachedLookup);
1651 EntryType type = GetEntryType (mt, bf);
1653 IMemberContainer current = Container;
1656 // `applicable' is a list of all members with the given member name `name'
1657 // in the current class and all its parent classes. The list is sorted in
1658 // reverse order due to the way how the cache is initialy created (to speed
1659 // things up, we're doing a deep-copy of our parent).
1661 for (int i = applicable.Count-1; i >= 0; i--) {
1662 CacheEntry entry = (CacheEntry) applicable [i];
1664 // This happens each time we're walking one level up in the class
1665 // hierarchy. If we're doing a DeclaredOnly search, we must abort
1666 // the first time this happens (this may already happen in the first
1667 // iteration of this loop if there are no members with the name we're
1668 // looking for in the current class).
1669 if (entry.Container != current) {
1670 if (declared_only || DoneSearching (global))
1673 current = entry.Container;
1676 // Is the member of the correct type ?
1677 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1680 // Is the member static/non-static ?
1681 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1684 // Apply the filter to it.
1685 if (filter (entry.Member, criteria)) {
1686 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method)
1687 do_method_search = false;
1688 global.Add (entry.Member);
1692 Timer.StopTimer (TimerType.CachedLookup);
1694 // If we have a method cache and we aren't already doing a method-only
1695 // search, we restart in method-only search mode if the first match is
1696 // a method. This ensures that we return a MemberInfo with the correct
1697 // ReflectedType for inherited methods.
1698 if (do_method_search && (global.Count > 0)){
1699 using_global = false;
1701 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1704 using_global = false;
1705 MemberInfo [] copy = new MemberInfo [global.Count];
1706 global.CopyTo (copy);
1710 // find the nested type @name in @this.
1711 public Type FindNestedType (string name)
1713 ArrayList applicable = (ArrayList) member_hash [name];
1714 if (applicable == null)
1717 for (int i = applicable.Count-1; i >= 0; i--) {
1718 CacheEntry entry = (CacheEntry) applicable [i];
1719 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1720 return (Type) entry.Member;
1727 // This finds the method or property for us to override. invocationType is the type where
1728 // the override is going to be declared, name is the name of the method/property, and
1729 // paramTypes is the parameters, if any to the method or property
1731 // Because the MemberCache holds members from this class and all the base classes,
1732 // we can avoid tons of reflection stuff.
1734 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1736 ArrayList applicable;
1737 if (method_hash != null && !is_property)
1738 applicable = (ArrayList) method_hash [name];
1740 applicable = (ArrayList) member_hash [name];
1742 if (applicable == null)
1745 // Walk the chain of methods, starting from the top.
1747 for (int i = applicable.Count - 1; i >= 0; i--) {
1748 CacheEntry entry = (CacheEntry) applicable [i];
1750 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1753 PropertyInfo pi = null;
1754 MethodInfo mi = null;
1755 FieldInfo fi = null;
1756 Type [] cmpAttrs = null;
1759 if ((entry.EntryType & EntryType.Field) != 0) {
1760 fi = (FieldInfo)entry.Member;
1762 // TODO: For this case we ignore member type
1763 //fb = TypeManager.GetField (fi);
1764 //cmpAttrs = new Type[] { fb.MemberType };
1766 pi = (PropertyInfo) entry.Member;
1767 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1770 mi = (MethodInfo) entry.Member;
1771 cmpAttrs = TypeManager.GetArgumentTypes (mi);
1775 // TODO: Almost duplicate !
1777 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1778 case FieldAttributes.Private:
1780 // A private method is Ok if we are a nested subtype.
1781 // The spec actually is not very clear about this, see bug 52458.
1783 if (invocationType != entry.Container.Type &
1784 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1788 case FieldAttributes.FamANDAssem:
1789 case FieldAttributes.Assembly:
1791 // Check for assembly methods
1793 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1797 return entry.Member;
1801 // Check the arguments
1803 if (cmpAttrs.Length != paramTypes.Length)
1806 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1807 if (paramTypes [j] != cmpAttrs [j])
1811 // get one of the methods because this has the visibility info.
1814 mi = pi.GetGetMethod (true);
1816 mi = pi.GetSetMethod (true);
1822 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1823 case MethodAttributes.Private:
1825 // A private method is Ok if we are a nested subtype.
1826 // The spec actually is not very clear about this, see bug 52458.
1828 if (invocationType == entry.Container.Type ||
1829 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1830 return entry.Member;
1833 case MethodAttributes.FamANDAssem:
1834 case MethodAttributes.Assembly:
1836 // Check for assembly methods
1838 if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1839 return entry.Member;
1844 // A protected method is ok, because we are overriding.
1845 // public is always ok.
1847 return entry.Member;
1857 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1858 /// We handle two cases. The first is for types without parameters (events, field, properties).
1859 /// The second are methods, indexers and this is why ignore_complex_types is here.
1860 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1862 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1864 ArrayList applicable = null;
1866 if (method_hash != null)
1867 applicable = (ArrayList) method_hash [name];
1869 if (applicable != null) {
1870 for (int i = applicable.Count - 1; i >= 0; i--) {
1871 CacheEntry entry = (CacheEntry) applicable [i];
1872 if ((entry.EntryType & EntryType.Public) != 0)
1873 return entry.Member;
1877 if (member_hash == null)
1879 applicable = (ArrayList) member_hash [name];
1881 if (applicable != null) {
1882 for (int i = applicable.Count - 1; i >= 0; i--) {
1883 CacheEntry entry = (CacheEntry) applicable [i];
1884 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1885 if (ignore_complex_types) {
1886 if ((entry.EntryType & EntryType.Method) != 0)
1889 // Does exist easier way how to detect indexer ?
1890 if ((entry.EntryType & EntryType.Property) != 0) {
1891 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1892 if (arg_types.Length > 0)
1896 return entry.Member;
1903 Hashtable locase_table;
1906 /// Builds low-case table for CLS Compliance test
1908 public Hashtable GetPublicMembers ()
1910 if (locase_table != null)
1911 return locase_table;
1913 locase_table = new Hashtable ();
1914 foreach (DictionaryEntry entry in member_hash) {
1915 ArrayList members = (ArrayList)entry.Value;
1916 for (int ii = 0; ii < members.Count; ++ii) {
1917 CacheEntry member_entry = (CacheEntry) members [ii];
1919 if ((member_entry.EntryType & EntryType.Public) == 0)
1922 // TODO: Does anyone know easier way how to detect that member is internal ?
1923 switch (member_entry.EntryType & EntryType.MaskType) {
1924 case EntryType.Constructor:
1927 case EntryType.Field:
1928 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
1932 case EntryType.Method:
1933 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1937 case EntryType.Property:
1938 PropertyInfo pi = (PropertyInfo)member_entry.Member;
1939 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
1943 case EntryType.Event:
1944 EventInfo ei = (EventInfo)member_entry.Member;
1945 MethodInfo mi = ei.GetAddMethod ();
1946 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1950 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
1951 locase_table [lcase] = member_entry.Member;
1955 return locase_table;
1958 public Hashtable Members {
1965 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
1967 public void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
1969 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
1971 for (int i = 0; i < al.Count; ++i) {
1972 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
1975 if (entry.Member == this_builder)
1978 if ((entry.EntryType & tested_type) != tested_type)
1981 MethodBase method_to_compare = (MethodBase)entry.Member;
1982 if (AttributeTester.AreOverloadedMethodParamsClsCompliant (method.ParameterTypes, TypeManager.GetArgumentTypes (method_to_compare)))
1985 IMethodData md = TypeManager.GetMethod (method_to_compare);
1987 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
1988 // However it is exactly what csc does.
1989 if (md != null && !md.IsClsCompliaceRequired (method.Parent))
1992 Report.SymbolRelatedToPreviousError (entry.Member);
1993 Report.Error (3006, method.Location, "Overloaded method '{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());