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)
10 // (C) 2004 Novell, Inc
12 // TODO: Move the method verification stuff from the class.cs and interface.cs here
16 using System.Collections;
17 using System.Globalization;
18 using System.Reflection.Emit;
19 using System.Reflection;
21 #if BOOTSTRAP_WITH_OLDLIB
22 using XmlElement = System.Object;
27 namespace Mono.CSharp {
29 public class MemberName {
30 public readonly string Name;
31 public readonly MemberName Left;
33 public static readonly MemberName Null = new MemberName ("");
35 public MemberName (string name)
40 public MemberName (MemberName left, string name)
46 public MemberName (MemberName left, MemberName right)
49 Left = (right.Left == null) ? left : new MemberName (left, right.Left);
52 static readonly char [] dot_array = { '.' };
54 public static MemberName FromDotted (string name)
56 string [] elements = name.Split (dot_array);
57 int count = elements.Length;
59 MemberName n = new MemberName (elements [i++]);
61 n = new MemberName (n, elements [i++]);
65 public string GetName ()
67 return GetName (false);
70 public string GetName (bool is_generic)
72 string name = is_generic ? Basename : Name;
74 return Left.GetName (is_generic) + "." + name;
80 /// This returns exclusively the name as seen on the source code
81 /// it is not the fully qualifed type after resolution
83 public string GetPartialName ()
86 return Left.GetPartialName () + "." + Name;
91 public string GetTypeName ()
94 return Left.GetTypeName () + "." + Name;
99 public Expression GetTypeExpression (Location loc)
102 Expression lexpr = Left.GetTypeExpression (loc);
104 return new MemberAccess (lexpr, Name, loc);
106 return new SimpleName (Name, loc);
110 public MemberName Clone ()
113 return new MemberName (Left.Clone (), Name);
115 return new MemberName (Name);
118 public string Basename {
124 public override string ToString ()
127 return Left + "." + Name;
132 public override bool Equals (object other)
134 return Equals (other as MemberName);
137 public bool Equals (MemberName other)
141 if (other == null || Name != other.Name)
144 if (TypeArguments == null)
145 return other.TypeArguments == null;
147 if (other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count)
151 return other.Left == null;
153 return Left.Equals (other.Left);
156 public override int GetHashCode ()
158 int hash = Name.GetHashCode ();
159 for (MemberName n = Left; n != null; n = n.Left)
160 hash ^= n.Name.GetHashCode ();
163 if (TypeArguments != null)
164 hash ^= TypeArguments.Count << 5;
167 return hash & 0x7FFFFFFF;
172 /// Base representation for members. This is used to keep track
173 /// of Name, Location and Modifier flags, and handling Attributes.
175 public abstract class MemberCore : Attributable {
180 protected string cached_name;
183 if (cached_name == null)
184 cached_name = MemberName.GetName (false);
189 // Is not readonly because of IndexerName attribute
190 private MemberName member_name;
191 public MemberName MemberName {
192 get { return member_name; }
196 /// Modifier flags that the user specified in the source code
200 public /*readonly*/ TypeContainer Parent;
203 /// Location where this declaration happens
205 public readonly Location Location;
208 /// XML documentation comment
210 public string DocComment;
213 /// Represents header string for documentation comment
214 /// for each member types.
216 public abstract string DocCommentHeader { get; }
220 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
221 Obsolete = 1 << 1, // Type has obsolete attribute
222 ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
223 ClsCompliant = 1 << 3, // Type is CLS Compliant
224 CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
225 HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
226 HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
227 ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
228 Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
229 Excluded = 1 << 9, // Method is conditional
230 TestMethodDuplication = 1 << 10, // Test for duplication must be performed
232 IsAssigned = 1 << 12 // Field is assigned
236 /// MemberCore flags at first detected then cached
238 internal Flags caching_flags;
240 public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
244 if (parent is PartialContainer && !(this is PartialContainer))
245 throw new InternalErrorException ("A PartialContainer cannot be the direct parent of a member");
250 caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
253 protected virtual void SetMemberName (MemberName new_name)
255 member_name = new_name;
260 /// Tests presence of ObsoleteAttribute and report proper error
262 protected void CheckUsageOfObsoleteAttribute (Type type)
267 ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
268 if (obsolete_attr == null)
271 AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, Location);
274 public abstract bool Define ();
277 // Returns full member name for error message
279 public virtual string GetSignatureForError ()
281 if (Parent == null || Parent.Parent == null)
284 return String.Concat (Parent.GetSignatureForError (), '.', Name);
288 /// Base Emit method. This is also entry point for CLS-Compliant verification.
290 public virtual void Emit ()
292 // Hack with Parent == null is for EnumMember
293 if (Parent == null || (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent) == null))
294 VerifyObsoleteAttribute ();
296 if (!RootContext.VerifyClsCompliance)
299 VerifyClsCompliance (Parent);
302 public bool InUnsafe {
304 return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
308 public virtual bool IsUsed {
310 return (caching_flags & Flags.IsUsed) != 0;
314 public void SetMemberIsUsed ()
316 caching_flags |= Flags.IsUsed;
320 // Whehter is it ok to use an unsafe pointer in this type container
322 public bool UnsafeOK (DeclSpace parent)
325 // First check if this MemberCore modifier flags has unsafe set
327 if ((ModFlags & Modifiers.UNSAFE) != 0)
330 if (parent.UnsafeContext)
333 Expression.UnsafeError (Location);
338 /// Returns instance of ObsoleteAttribute for this MemberCore
340 public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
342 // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
343 if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
347 caching_flags &= ~Flags.Obsolete_Undetected;
349 if (OptAttributes == null)
352 Attribute obsolete_attr = OptAttributes.Search (
353 TypeManager.obsolete_attribute_type, ds.EmitContext);
354 if (obsolete_attr == null)
357 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds.EmitContext);
358 if (obsolete == null)
361 caching_flags |= Flags.Obsolete;
366 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
368 public override bool IsClsCompliaceRequired (DeclSpace container)
370 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
371 return (caching_flags & Flags.ClsCompliant) != 0;
373 if (GetClsCompliantAttributeValue (container) && IsExposedFromAssembly (container)) {
374 caching_flags &= ~Flags.ClsCompliance_Undetected;
375 caching_flags |= Flags.ClsCompliant;
379 caching_flags &= ~Flags.ClsCompliance_Undetected;
384 /// Returns true when MemberCore is exposed from assembly.
386 public bool IsExposedFromAssembly (DeclSpace ds)
388 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
391 DeclSpace parentContainer = ds;
392 while (parentContainer != null && parentContainer.ModFlags != 0) {
393 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
395 parentContainer = parentContainer.Parent;
401 /// Resolve CLSCompliantAttribute value or gets cached value.
403 bool GetClsCompliantAttributeValue (DeclSpace ds)
405 if (OptAttributes != null) {
406 Attribute cls_attribute = OptAttributes.Search (
407 TypeManager.cls_compliant_attribute_type, ds.EmitContext);
408 if (cls_attribute != null) {
409 caching_flags |= Flags.HasClsCompliantAttribute;
410 return cls_attribute.GetClsCompliantAttributeValue (ds.EmitContext);
413 return ds.GetClsCompliantAttributeValue ();
417 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
419 protected bool HasClsCompliantAttribute {
421 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
426 /// It helps to handle error 102 & 111 detection
428 public virtual bool MarkForDuplicationCheck ()
434 /// The main virtual method for CLS-Compliant verifications.
435 /// The method returns true if member is CLS-Compliant and false if member is not
436 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
437 /// and add their extra verifications.
439 protected virtual bool VerifyClsCompliance (DeclSpace ds)
441 if (!IsClsCompliaceRequired (ds)) {
442 if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
443 if (!IsExposedFromAssembly (ds))
444 Report.Warning (3019, Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
445 if (!CodeGen.Assembly.IsClsCompliant)
446 Report.Warning (3021, Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
451 if (!CodeGen.Assembly.IsClsCompliant) {
452 if (HasClsCompliantAttribute) {
453 Report.Error (3014, Location,
454 "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
455 GetSignatureForError ());
460 if (member_name.Name [0] == '_') {
461 Report.Error (3008, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
466 protected abstract void VerifyObsoleteAttribute ();
469 // Raised (and passed an XmlElement that contains the comment)
470 // when GenerateDocComment is writing documentation expectedly.
472 internal virtual void OnGenerateDocComment (DeclSpace ds, XmlElement intermediateNode)
477 // Returns a string that represents the signature for this
478 // member which should be used in XML documentation.
480 public virtual string GetDocCommentName (DeclSpace ds)
482 if (ds == null || this is DeclSpace)
483 return DocCommentHeader + Name;
485 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
489 // Generates xml doc comments (if any), and if required,
490 // handle warning report.
492 internal virtual void GenerateDocComment (DeclSpace ds)
494 DocUtil.GenerateDocComment (this, ds);
499 /// Base class for structs, classes, enumerations and interfaces.
502 /// They all create new declaration spaces. This
503 /// provides the common foundation for managing those name
506 public abstract class DeclSpace : MemberCore {
508 /// This points to the actual definition that is being
509 /// created with System.Reflection.Emit
511 public TypeBuilder TypeBuilder;
514 // This is the namespace in which this typecontainer
515 // was declared. We use this to resolve names.
517 public NamespaceEntry NamespaceEntry;
519 private Hashtable Cache = new Hashtable ();
521 public string Basename;
523 protected Hashtable defined_names;
525 // The emit context for toplevel objects.
526 protected EmitContext ec;
528 public EmitContext EmitContext {
532 static string[] attribute_targets = new string [] { "type" };
534 public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
535 Attributes attrs, Location l)
536 : base (parent, name, attrs, l)
539 Basename = name.Name;
540 defined_names = new Hashtable ();
544 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
546 protected bool AddToContainer (MemberCore symbol, string name)
548 if (name == Basename && !(this is Interface) && !(this is Enum)) {
549 Report.SymbolRelatedToPreviousError (this);
550 Report.Error (542, symbol.Location, "`{0}': member names cannot be the same as their enclosing type", symbol.GetSignatureForError ());
554 MemberCore mc = (MemberCore) defined_names [name];
557 defined_names.Add (name, symbol);
561 if (symbol.MarkForDuplicationCheck () && mc.MarkForDuplicationCheck ())
564 Report.SymbolRelatedToPreviousError (mc);
565 if (symbol is PartialContainer || mc is PartialContainer) {
566 Report.Error (260, symbol.Location,
567 "Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
572 if (this is RootTypes) {
573 Report.Error (101, symbol.Location,
574 "The namespace `{0}' already contains a definition for `{1}'",
575 ((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
577 Report.Error (102, symbol.Location, "The type `{0}' already contains a definition for `{1}'",
578 GetSignatureForError (), symbol.MemberName.Name);
584 /// Returns the MemberCore associated with a given name in the declaration
585 /// space. It doesn't return method based symbols !!
588 public MemberCore GetDefinition (string name)
590 return (MemberCore)defined_names [name];
594 // root_types contains all the types. All TopLevel types
595 // hence have a parent that points to `root_types', that is
596 // why there is a non-obvious test down here.
598 public bool IsTopLevel {
599 get { return (Parent != null && Parent.Parent == null); }
602 public virtual void CloseType ()
604 if ((caching_flags & Flags.CloseTypeCreated) == 0){
606 TypeBuilder.CreateType ();
609 // The try/catch is needed because
610 // nested enumerations fail to load when they
613 // Even if this is the right order (enumerations
614 // declared after types).
616 // Note that this still creates the type and
617 // it is possible to save it
619 caching_flags |= Flags.CloseTypeCreated;
623 protected virtual TypeAttributes TypeAttr {
624 get { return CodeGen.Module.DefaultCharSetType; }
628 /// Should be overriten by the appropriate declaration space
630 public abstract TypeBuilder DefineType ();
633 /// Define all members, but don't apply any attributes or do anything which may
634 /// access not-yet-defined classes. This method also creates the MemberCache.
636 public virtual bool DefineMembers (TypeContainer parent)
638 if (((ModFlags & Modifiers.NEW) != 0) && IsTopLevel) {
639 Report.Error (1530, Location, "Keyword `new' is not allowed on namespace elements");
645 public override string GetSignatureForError ()
647 // Parent.GetSignatureForError
652 // Whether this is an `unsafe context'
654 public bool UnsafeContext {
656 if ((ModFlags & Modifiers.UNSAFE) != 0)
659 return Parent.UnsafeContext;
664 EmitContext type_resolve_ec;
665 protected EmitContext TypeResolveEmitContext {
667 if (type_resolve_ec == null) {
668 // FIXME: I think this should really be one of:
670 // a. type_resolve_ec = Parent.EmitContext;
671 // b. type_resolve_ec = new EmitContext (Parent, Parent, loc, null, null, ModFlags, false);
673 // However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
675 type_resolve_ec = new EmitContext (Parent, this, Location.Null, null, null, ModFlags, false);
677 return type_resolve_ec;
682 // Resolves the expression `e' for a type, and will recursively define
683 // types. This should only be used for resolving base types.
685 public TypeExpr ResolveBaseTypeExpr (Expression e, bool silent, Location loc)
687 TypeResolveEmitContext.loc = loc;
688 TypeResolveEmitContext.ContainerType = TypeBuilder;
690 return e.ResolveAsTypeTerminal (TypeResolveEmitContext, silent);
693 public bool CheckAccessLevel (Type check_type)
695 if (check_type == TypeBuilder)
698 TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
701 // Broken Microsoft runtime, return public for arrays, no matter what
702 // the accessibility is for their underlying class, and they return
703 // NonPublic visibility for pointers
705 if (check_type.IsArray || check_type.IsPointer)
706 return CheckAccessLevel (TypeManager.GetElementType (check_type));
708 if (TypeBuilder == null)
709 // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
710 // However, this is invoked again later -- so safe to return true.
711 // May also be null when resolving top-level attributes.
715 case TypeAttributes.Public:
718 case TypeAttributes.NotPublic:
720 // This test should probably use the declaringtype.
722 return check_type.Assembly == TypeBuilder.Assembly;
724 case TypeAttributes.NestedPublic:
727 case TypeAttributes.NestedPrivate:
728 return NestedAccessible (check_type);
730 case TypeAttributes.NestedFamily:
731 return FamilyAccessible (check_type);
733 case TypeAttributes.NestedFamANDAssem:
734 return (check_type.Assembly == TypeBuilder.Assembly) &&
735 FamilyAccessible (check_type);
737 case TypeAttributes.NestedFamORAssem:
738 return (check_type.Assembly == TypeBuilder.Assembly) ||
739 FamilyAccessible (check_type);
741 case TypeAttributes.NestedAssembly:
742 return check_type.Assembly == TypeBuilder.Assembly;
745 Console.WriteLine ("HERE: " + check_attr);
750 protected bool NestedAccessible (Type check_type)
752 Type declaring = check_type.DeclaringType;
753 return TypeBuilder == declaring ||
754 TypeManager.IsNestedChildOf (TypeBuilder, declaring);
757 protected bool FamilyAccessible (Type check_type)
759 Type declaring = check_type.DeclaringType;
760 return TypeManager.IsNestedFamilyAccessible (TypeBuilder, declaring);
763 // Access level of a type.
765 enum AccessLevel { // Each column represents `is this scope larger or equal to Blah scope'
766 // Public Assembly Protected
767 Protected = (0 << 0) | (0 << 1) | (X << 2),
768 Public = (X << 0) | (X << 1) | (X << 2),
769 Private = (0 << 0) | (0 << 1) | (0 << 2),
770 Internal = (0 << 0) | (X << 1) | (0 << 2),
771 ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
774 static AccessLevel GetAccessLevelFromModifiers (int flags)
776 if ((flags & Modifiers.INTERNAL) != 0) {
778 if ((flags & Modifiers.PROTECTED) != 0)
779 return AccessLevel.ProtectedOrInternal;
781 return AccessLevel.Internal;
783 } else if ((flags & Modifiers.PROTECTED) != 0)
784 return AccessLevel.Protected;
786 else if ((flags & Modifiers.PRIVATE) != 0)
787 return AccessLevel.Private;
790 return AccessLevel.Public;
793 // What is the effective access level of this?
795 AccessLevel EffectiveAccessLevel {
797 AccessLevel myAccess = GetAccessLevelFromModifiers (ModFlags);
798 if (!IsTopLevel && (Parent != null))
799 return myAccess & Parent.EffectiveAccessLevel;
805 // Return the access level for type `t'
806 static AccessLevel TypeEffectiveAccessLevel (Type t)
809 return AccessLevel.Public;
810 if (t.IsNestedPrivate)
811 return AccessLevel.Private;
813 return AccessLevel.Internal;
815 // By now, it must be nested
816 AccessLevel parentLevel = TypeEffectiveAccessLevel (t.DeclaringType);
818 if (t.IsNestedPublic)
820 if (t.IsNestedAssembly)
821 return parentLevel & AccessLevel.Internal;
822 if (t.IsNestedFamily)
823 return parentLevel & AccessLevel.Protected;
824 if (t.IsNestedFamORAssem)
825 return parentLevel & AccessLevel.ProtectedOrInternal;
826 if (t.IsNestedFamANDAssem)
827 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
829 // nested private is taken care of
831 throw new Exception ("I give up, what are you?");
835 // This answers `is the type P, as accessible as a member M which has the
836 // accessability @flags which is declared as a nested member of the type T, this declspace'
838 public bool AsAccessible (Type p, int flags)
841 // 1) if M is private, its accessability is the same as this declspace.
842 // we already know that P is accessible to T before this method, so we
846 if ((flags & Modifiers.PRIVATE) != 0)
849 while (p.IsArray || p.IsPointer || p.IsByRef)
850 p = TypeManager.GetElementType (p);
852 AccessLevel pAccess = TypeEffectiveAccessLevel (p);
853 AccessLevel mAccess = this.EffectiveAccessLevel &
854 GetAccessLevelFromModifiers (flags);
856 // for every place from which we can access M, we must
857 // be able to access P as well. So, we want
858 // For every bit in M and P, M_i -> P_1 == true
859 // or, ~ (M -> P) == 0 <-> ~ ( ~M | P) == 0
861 return ~ (~ mAccess | pAccess) == 0;
865 // Return the nested type with name @name. Ensures that the nested type
866 // is defined if necessary. Do _not_ use this when you have a MemberCache handy.
868 public virtual Type FindNestedType (string name)
873 private Type LookupNestedTypeInHierarchy (string name)
875 // if the member cache has been created, lets use it.
876 // the member cache is MUCH faster.
877 if (MemberCache != null)
878 return MemberCache.FindNestedType (name);
880 // no member cache. Do it the hard way -- reflection
882 for (Type current_type = TypeBuilder;
883 current_type != null && current_type != TypeManager.object_type;
884 current_type = current_type.BaseType) {
885 if (current_type is TypeBuilder) {
886 DeclSpace decl = this;
887 if (current_type != TypeBuilder)
888 decl = TypeManager.LookupDeclSpace (current_type);
889 t = decl.FindNestedType (name);
891 t = TypeManager.GetNestedType (current_type, name);
894 if (t != null && CheckAccessLevel (t))
902 // Public function used to locate types.
904 // Set 'ignore_cs0104' to true if you want to ignore cs0104 errors.
906 // Returns: Type or null if they type can not be found.
908 public FullNamedExpression LookupType (string name, Location loc, bool ignore_cs0104)
910 if (this is PartialContainer)
911 throw new InternalErrorException ("Should not get here");
913 if (Cache.Contains (name))
914 return (FullNamedExpression) Cache [name];
916 FullNamedExpression e;
917 Type t = LookupNestedTypeInHierarchy (name);
919 e = new TypeExpression (t, Location.Null);
920 else if (Parent != null && Parent != RootContext.Tree.Types)
921 e = Parent.LookupType (name, loc, ignore_cs0104);
923 e = NamespaceEntry.LookupNamespaceOrType (this, name, loc, ignore_cs0104);
930 /// This function is broken and not what you're looking for. It should only
931 /// be used while the type is still being created since it doesn't use the cache
932 /// and relies on the filter doing the member name check.
934 public abstract MemberList FindMembers (MemberTypes mt, BindingFlags bf,
935 MemberFilter filter, object criteria);
938 /// If we have a MemberCache, return it. This property may return null if the
939 /// class doesn't have a member cache or while it's still being created.
941 public abstract MemberCache MemberCache {
945 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
947 if (a.Type == TypeManager.required_attr_type) {
948 Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
951 TypeBuilder.SetCustomAttribute (cb);
955 /// Goes through class hierarchy and get value of first CLSCompliantAttribute that found.
956 /// If no is attribute exists then return assembly CLSCompliantAttribute.
958 public bool GetClsCompliantAttributeValue ()
960 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
961 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
963 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
965 if (OptAttributes != null) {
966 Attribute cls_attribute = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, ec);
967 if (cls_attribute != null) {
968 caching_flags |= Flags.HasClsCompliantAttribute;
969 if (cls_attribute.GetClsCompliantAttributeValue (ec)) {
970 caching_flags |= Flags.ClsCompliantAttributeTrue;
977 if (Parent == null) {
978 if (CodeGen.Assembly.IsClsCompliant) {
979 caching_flags |= Flags.ClsCompliantAttributeTrue;
985 if (Parent.GetClsCompliantAttributeValue ()) {
986 caching_flags |= Flags.ClsCompliantAttributeTrue;
992 public override string[] ValidAttributeTargets {
993 get { return attribute_targets; }
998 /// This is a readonly list of MemberInfo's.
1000 public class MemberList : IList {
1001 public readonly IList List;
1005 /// Create a new MemberList from the given IList.
1007 public MemberList (IList list)
1012 this.List = new ArrayList ();
1017 /// Concatenate the ILists `first' and `second' to a new MemberList.
1019 public MemberList (IList first, IList second)
1021 ArrayList list = new ArrayList ();
1022 list.AddRange (first);
1023 list.AddRange (second);
1028 public static readonly MemberList Empty = new MemberList (new ArrayList ());
1031 /// Cast the MemberList into a MemberInfo[] array.
1034 /// This is an expensive operation, only use it if it's really necessary.
1036 public static explicit operator MemberInfo [] (MemberList list)
1038 Timer.StartTimer (TimerType.MiscTimer);
1039 MemberInfo [] result = new MemberInfo [list.Count];
1040 list.CopyTo (result, 0);
1041 Timer.StopTimer (TimerType.MiscTimer);
1053 public bool IsSynchronized {
1055 return List.IsSynchronized;
1059 public object SyncRoot {
1061 return List.SyncRoot;
1065 public void CopyTo (Array array, int index)
1067 List.CopyTo (array, index);
1072 public IEnumerator GetEnumerator ()
1074 return List.GetEnumerator ();
1079 public bool IsFixedSize {
1085 public bool IsReadOnly {
1091 object IList.this [int index] {
1093 return List [index];
1097 throw new NotSupportedException ();
1101 // FIXME: try to find out whether we can avoid the cast in this indexer.
1102 public MemberInfo this [int index] {
1104 return (MemberInfo) List [index];
1108 public int Add (object value)
1110 throw new NotSupportedException ();
1113 public void Clear ()
1115 throw new NotSupportedException ();
1118 public bool Contains (object value)
1120 return List.Contains (value);
1123 public int IndexOf (object value)
1125 return List.IndexOf (value);
1128 public void Insert (int index, object value)
1130 throw new NotSupportedException ();
1133 public void Remove (object value)
1135 throw new NotSupportedException ();
1138 public void RemoveAt (int index)
1140 throw new NotSupportedException ();
1145 /// This interface is used to get all members of a class when creating the
1146 /// member cache. It must be implemented by all DeclSpace derivatives which
1147 /// want to support the member cache and by TypeHandle to get caching of
1148 /// non-dynamic types.
1150 public interface IMemberContainer {
1152 /// The name of the IMemberContainer. This is only used for
1153 /// debugging purposes.
1160 /// The type of this IMemberContainer.
1167 /// Returns the IMemberContainer of the base class or null if this
1168 /// is an interface or TypeManger.object_type.
1169 /// This is used when creating the member cache for a class to get all
1170 /// members from the base class.
1172 MemberCache BaseCache {
1177 /// Whether this is an interface.
1184 /// Returns all members of this class with the corresponding MemberTypes
1185 /// and BindingFlags.
1188 /// When implementing this method, make sure not to return any inherited
1189 /// members and check the MemberTypes and BindingFlags properly.
1190 /// Unfortunately, System.Reflection is lame and doesn't provide a way to
1191 /// get the BindingFlags (static/non-static,public/non-public) in the
1192 /// MemberInfo class, but the cache needs this information. That's why
1193 /// this method is called multiple times with different BindingFlags.
1195 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1198 /// Return the container's member cache.
1200 MemberCache MemberCache {
1206 /// The MemberCache is used by dynamic and non-dynamic types to speed up
1207 /// member lookups. It has a member name based hash table; it maps each member
1208 /// name to a list of CacheEntry objects. Each CacheEntry contains a MemberInfo
1209 /// and the BindingFlags that were initially used to get it. The cache contains
1210 /// all members of the current class and all inherited members. If this cache is
1211 /// for an interface types, it also contains all inherited members.
1213 /// There are two ways to get a MemberCache:
1214 /// * if this is a dynamic type, lookup the corresponding DeclSpace and then
1215 /// use the DeclSpace.MemberCache property.
1216 /// * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1217 /// TypeHandle instance for the type and then use TypeHandle.MemberCache.
1219 public class MemberCache {
1220 public readonly IMemberContainer Container;
1221 protected Hashtable member_hash;
1222 protected Hashtable method_hash;
1225 /// Create a new MemberCache for the given IMemberContainer `container'.
1227 public MemberCache (IMemberContainer container)
1229 this.Container = container;
1231 Timer.IncrementCounter (CounterType.MemberCache);
1232 Timer.StartTimer (TimerType.CacheInit);
1234 // If we have a base class (we have a base class unless we're
1235 // TypeManager.object_type), we deep-copy its MemberCache here.
1236 if (Container.BaseCache != null)
1237 member_hash = SetupCache (Container.BaseCache);
1239 member_hash = new Hashtable ();
1241 // If this is neither a dynamic type nor an interface, create a special
1242 // method cache with all declared and inherited methods.
1243 Type type = container.Type;
1244 if (!(type is TypeBuilder) && !type.IsInterface &&
1245 (Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
1246 method_hash = new Hashtable ();
1250 // Add all members from the current class.
1251 AddMembers (Container);
1253 Timer.StopTimer (TimerType.CacheInit);
1256 public MemberCache (Type[] ifaces)
1259 // The members of this cache all belong to other caches.
1260 // So, 'Container' will not be used.
1262 this.Container = null;
1264 member_hash = new Hashtable ();
1268 foreach (Type itype in ifaces)
1269 AddCacheContents (TypeManager.LookupMemberCache (itype));
1273 /// Bootstrap this member cache by doing a deep-copy of our base.
1275 Hashtable SetupCache (MemberCache base_class)
1277 Hashtable hash = new Hashtable ();
1279 if (base_class == null)
1282 IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
1283 while (it.MoveNext ()) {
1284 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1291 /// Add the contents of `cache' to the member_hash.
1293 void AddCacheContents (MemberCache cache)
1295 IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
1296 while (it.MoveNext ()) {
1297 ArrayList list = (ArrayList) member_hash [it.Key];
1299 member_hash [it.Key] = list = new ArrayList ();
1301 ArrayList entries = (ArrayList) it.Value;
1302 for (int i = entries.Count-1; i >= 0; i--) {
1303 CacheEntry entry = (CacheEntry) entries [i];
1305 if (entry.Container != cache.Container)
1313 /// Add all members from class `container' to the cache.
1315 void AddMembers (IMemberContainer container)
1317 // We need to call AddMembers() with a single member type at a time
1318 // to get the member type part of CacheEntry.EntryType right.
1319 if (!container.IsInterface) {
1320 AddMembers (MemberTypes.Constructor, container);
1321 AddMembers (MemberTypes.Field, container);
1323 AddMembers (MemberTypes.Method, container);
1324 AddMembers (MemberTypes.Property, container);
1325 AddMembers (MemberTypes.Event, container);
1326 // Nested types are returned by both Static and Instance searches.
1327 AddMembers (MemberTypes.NestedType,
1328 BindingFlags.Static | BindingFlags.Public, container);
1329 AddMembers (MemberTypes.NestedType,
1330 BindingFlags.Static | BindingFlags.NonPublic, container);
1333 void AddMembers (MemberTypes mt, IMemberContainer container)
1335 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1336 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1337 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1338 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1342 /// Add all members from class `container' with the requested MemberTypes and
1343 /// BindingFlags to the cache. This method is called multiple times with different
1344 /// MemberTypes and BindingFlags.
1346 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1348 MemberList members = container.GetMembers (mt, bf);
1350 foreach (MemberInfo member in members) {
1351 string name = member.Name;
1353 // We use a name-based hash table of ArrayList's.
1354 ArrayList list = (ArrayList) member_hash [name];
1356 list = new ArrayList ();
1357 member_hash.Add (name, list);
1360 // When this method is called for the current class, the list will
1361 // already contain all inherited members from our base classes.
1362 // We cannot add new members in front of the list since this'd be an
1363 // expensive operation, that's why the list is sorted in reverse order
1364 // (ie. members from the current class are coming last).
1365 list.Add (new CacheEntry (container, member, mt, bf));
1370 /// Add all declared and inherited methods from class `type' to the method cache.
1372 void AddMethods (Type type)
1374 AddMethods (BindingFlags.Static | BindingFlags.Public |
1375 BindingFlags.FlattenHierarchy, type);
1376 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1377 BindingFlags.FlattenHierarchy, type);
1378 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1379 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1382 static ArrayList overrides = new ArrayList ();
1384 void AddMethods (BindingFlags bf, Type type)
1386 MethodBase [] members = type.GetMethods (bf);
1388 Array.Reverse (members);
1390 foreach (MethodBase member in members) {
1391 string name = member.Name;
1393 // We use a name-based hash table of ArrayList's.
1394 ArrayList list = (ArrayList) method_hash [name];
1396 list = new ArrayList ();
1397 method_hash.Add (name, list);
1400 MethodInfo curr = (MethodInfo) member;
1401 while (curr.IsVirtual && (curr.Attributes & MethodAttributes.NewSlot) == 0) {
1402 MethodInfo base_method = curr.GetBaseDefinition ();
1404 if (base_method == curr)
1405 // Not every virtual function needs to have a NewSlot flag.
1408 overrides.Add (curr);
1409 list.Add (new CacheEntry (null, base_method, MemberTypes.Method, bf));
1413 if (overrides.Count > 0) {
1414 for (int i = 0; i < overrides.Count; ++i)
1415 TypeManager.RegisterOverride ((MethodBase) overrides [i], curr);
1419 // Unfortunately, the elements returned by Type.GetMethods() aren't
1420 // sorted so we need to do this check for every member.
1421 BindingFlags new_bf = bf;
1422 if (member.DeclaringType == type)
1423 new_bf |= BindingFlags.DeclaredOnly;
1425 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1430 /// Compute and return a appropriate `EntryType' magic number for the given
1431 /// MemberTypes and BindingFlags.
1433 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1435 EntryType type = EntryType.None;
1437 if ((mt & MemberTypes.Constructor) != 0)
1438 type |= EntryType.Constructor;
1439 if ((mt & MemberTypes.Event) != 0)
1440 type |= EntryType.Event;
1441 if ((mt & MemberTypes.Field) != 0)
1442 type |= EntryType.Field;
1443 if ((mt & MemberTypes.Method) != 0)
1444 type |= EntryType.Method;
1445 if ((mt & MemberTypes.Property) != 0)
1446 type |= EntryType.Property;
1447 // Nested types are returned by static and instance searches.
1448 if ((mt & MemberTypes.NestedType) != 0)
1449 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1451 if ((bf & BindingFlags.Instance) != 0)
1452 type |= EntryType.Instance;
1453 if ((bf & BindingFlags.Static) != 0)
1454 type |= EntryType.Static;
1455 if ((bf & BindingFlags.Public) != 0)
1456 type |= EntryType.Public;
1457 if ((bf & BindingFlags.NonPublic) != 0)
1458 type |= EntryType.NonPublic;
1459 if ((bf & BindingFlags.DeclaredOnly) != 0)
1460 type |= EntryType.Declared;
1466 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1467 /// denote multiple member types. Returns true if the given flags value denotes a
1468 /// single member types.
1470 public static bool IsSingleMemberType (MemberTypes mt)
1473 case MemberTypes.Constructor:
1474 case MemberTypes.Event:
1475 case MemberTypes.Field:
1476 case MemberTypes.Method:
1477 case MemberTypes.Property:
1478 case MemberTypes.NestedType:
1487 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
1488 /// number to speed up the searching process.
1491 protected enum EntryType {
1496 MaskStatic = Instance|Static,
1500 MaskProtection = Public|NonPublic,
1504 Constructor = 0x020,
1511 MaskType = Constructor|Event|Field|Method|Property|NestedType
1514 protected class CacheEntry {
1515 public readonly IMemberContainer Container;
1516 public readonly EntryType EntryType;
1517 public readonly MemberInfo Member;
1519 public CacheEntry (IMemberContainer container, MemberInfo member,
1520 MemberTypes mt, BindingFlags bf)
1522 this.Container = container;
1523 this.Member = member;
1524 this.EntryType = GetEntryType (mt, bf);
1527 public override string ToString ()
1529 return String.Format ("CacheEntry ({0}:{1}:{2})", Container.Name,
1535 /// This is called each time we're walking up one level in the class hierarchy
1536 /// and checks whether we can abort the search since we've already found what
1537 /// we were looking for.
1539 protected bool DoneSearching (ArrayList list)
1542 // We've found exactly one member in the current class and it's not
1543 // a method or constructor.
1545 if (list.Count == 1 && !(list [0] is MethodBase))
1549 // Multiple properties: we query those just to find out the indexer
1552 if ((list.Count > 0) && (list [0] is PropertyInfo))
1559 /// Looks up members with name `name'. If you provide an optional
1560 /// filter function, it'll only be called with members matching the
1561 /// requested member name.
1563 /// This method will try to use the cache to do the lookup if possible.
1565 /// Unlike other FindMembers implementations, this method will always
1566 /// check all inherited members - even when called on an interface type.
1568 /// If you know that you're only looking for methods, you should use
1569 /// MemberTypes.Method alone since this speeds up the lookup a bit.
1570 /// When doing a method-only search, it'll try to use a special method
1571 /// cache (unless it's a dynamic type or an interface) and the returned
1572 /// MemberInfo's will have the correct ReflectedType for inherited methods.
1573 /// The lookup process will automatically restart itself in method-only
1574 /// search mode if it discovers that it's about to return methods.
1576 ArrayList global = new ArrayList ();
1577 bool using_global = false;
1579 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1581 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1582 MemberFilter filter, object criteria)
1585 throw new Exception ();
1587 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1588 bool method_search = mt == MemberTypes.Method;
1589 // If we have a method cache and we aren't already doing a method-only search,
1590 // then we restart a method search if the first match is a method.
1591 bool do_method_search = !method_search && (method_hash != null);
1593 ArrayList applicable;
1595 // If this is a method-only search, we try to use the method cache if
1596 // possible; a lookup in the method cache will return a MemberInfo with
1597 // the correct ReflectedType for inherited methods.
1599 if (method_search && (method_hash != null))
1600 applicable = (ArrayList) method_hash [name];
1602 applicable = (ArrayList) member_hash [name];
1604 if (applicable == null)
1605 return emptyMemberInfo;
1608 // 32 slots gives 53 rss/54 size
1609 // 2/4 slots gives 55 rss
1611 // Strange: from 25,000 calls, only 1,800
1612 // are above 2. Why does this impact it?
1615 using_global = true;
1617 Timer.StartTimer (TimerType.CachedLookup);
1619 EntryType type = GetEntryType (mt, bf);
1621 IMemberContainer current = Container;
1624 // `applicable' is a list of all members with the given member name `name'
1625 // in the current class and all its base classes. The list is sorted in
1626 // reverse order due to the way how the cache is initialy created (to speed
1627 // things up, we're doing a deep-copy of our base).
1629 for (int i = applicable.Count-1; i >= 0; i--) {
1630 CacheEntry entry = (CacheEntry) applicable [i];
1632 // This happens each time we're walking one level up in the class
1633 // hierarchy. If we're doing a DeclaredOnly search, we must abort
1634 // the first time this happens (this may already happen in the first
1635 // iteration of this loop if there are no members with the name we're
1636 // looking for in the current class).
1637 if (entry.Container != current) {
1638 if (declared_only || DoneSearching (global))
1641 current = entry.Container;
1644 // Is the member of the correct type ?
1645 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1648 // Is the member static/non-static ?
1649 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1652 // Apply the filter to it.
1653 if (filter (entry.Member, criteria)) {
1654 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method)
1655 do_method_search = false;
1656 global.Add (entry.Member);
1660 Timer.StopTimer (TimerType.CachedLookup);
1662 // If we have a method cache and we aren't already doing a method-only
1663 // search, we restart in method-only search mode if the first match is
1664 // a method. This ensures that we return a MemberInfo with the correct
1665 // ReflectedType for inherited methods.
1666 if (do_method_search && (global.Count > 0)){
1667 using_global = false;
1669 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1672 using_global = false;
1673 MemberInfo [] copy = new MemberInfo [global.Count];
1674 global.CopyTo (copy);
1678 // find the nested type @name in @this.
1679 public Type FindNestedType (string name)
1681 ArrayList applicable = (ArrayList) member_hash [name];
1682 if (applicable == null)
1685 for (int i = applicable.Count-1; i >= 0; i--) {
1686 CacheEntry entry = (CacheEntry) applicable [i];
1687 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1688 return (Type) entry.Member;
1695 // This finds the method or property for us to override. invocationType is the type where
1696 // the override is going to be declared, name is the name of the method/property, and
1697 // paramTypes is the parameters, if any to the method or property
1699 // Because the MemberCache holds members from this class and all the base classes,
1700 // we can avoid tons of reflection stuff.
1702 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1704 ArrayList applicable;
1705 if (method_hash != null && !is_property)
1706 applicable = (ArrayList) method_hash [name];
1708 applicable = (ArrayList) member_hash [name];
1710 if (applicable == null)
1713 // Walk the chain of methods, starting from the top.
1715 for (int i = applicable.Count - 1; i >= 0; i--) {
1716 CacheEntry entry = (CacheEntry) applicable [i];
1718 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1721 PropertyInfo pi = null;
1722 MethodInfo mi = null;
1723 FieldInfo fi = null;
1724 Type [] cmpAttrs = null;
1727 if ((entry.EntryType & EntryType.Field) != 0) {
1728 fi = (FieldInfo)entry.Member;
1730 // TODO: For this case we ignore member type
1731 //fb = TypeManager.GetField (fi);
1732 //cmpAttrs = new Type[] { fb.MemberType };
1734 pi = (PropertyInfo) entry.Member;
1735 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1738 mi = (MethodInfo) entry.Member;
1739 cmpAttrs = TypeManager.GetArgumentTypes (mi);
1743 // TODO: Almost duplicate !
1745 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1746 case FieldAttributes.Private:
1748 // A private method is Ok if we are a nested subtype.
1749 // The spec actually is not very clear about this, see bug 52458.
1751 if (invocationType != entry.Container.Type &
1752 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1756 case FieldAttributes.FamANDAssem:
1757 case FieldAttributes.Assembly:
1759 // Check for assembly methods
1761 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1765 return entry.Member;
1769 // Check the arguments
1771 if (cmpAttrs.Length != paramTypes.Length)
1774 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1775 if (paramTypes [j] != cmpAttrs [j])
1779 // get one of the methods because this has the visibility info.
1782 mi = pi.GetGetMethod (true);
1784 mi = pi.GetSetMethod (true);
1790 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1791 case MethodAttributes.Private:
1793 // A private method is Ok if we are a nested subtype.
1794 // The spec actually is not very clear about this, see bug 52458.
1796 if (invocationType == entry.Container.Type ||
1797 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1798 return entry.Member;
1801 case MethodAttributes.FamANDAssem:
1802 case MethodAttributes.Assembly:
1804 // Check for assembly methods
1806 if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1807 return entry.Member;
1812 // A protected method is ok, because we are overriding.
1813 // public is always ok.
1815 return entry.Member;
1825 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1826 /// We handle two cases. The first is for types without parameters (events, field, properties).
1827 /// The second are methods, indexers and this is why ignore_complex_types is here.
1828 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1830 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1832 ArrayList applicable = null;
1834 if (method_hash != null)
1835 applicable = (ArrayList) method_hash [name];
1837 if (applicable != null) {
1838 for (int i = applicable.Count - 1; i >= 0; i--) {
1839 CacheEntry entry = (CacheEntry) applicable [i];
1840 if ((entry.EntryType & EntryType.Public) != 0)
1841 return entry.Member;
1845 if (member_hash == null)
1847 applicable = (ArrayList) member_hash [name];
1849 if (applicable != null) {
1850 for (int i = applicable.Count - 1; i >= 0; i--) {
1851 CacheEntry entry = (CacheEntry) applicable [i];
1852 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1853 if (ignore_complex_types) {
1854 if ((entry.EntryType & EntryType.Method) != 0)
1857 // Does exist easier way how to detect indexer ?
1858 if ((entry.EntryType & EntryType.Property) != 0) {
1859 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1860 if (arg_types.Length > 0)
1864 return entry.Member;
1871 Hashtable locase_table;
1874 /// Builds low-case table for CLS Compliance test
1876 public Hashtable GetPublicMembers ()
1878 if (locase_table != null)
1879 return locase_table;
1881 locase_table = new Hashtable ();
1882 foreach (DictionaryEntry entry in member_hash) {
1883 ArrayList members = (ArrayList)entry.Value;
1884 for (int ii = 0; ii < members.Count; ++ii) {
1885 CacheEntry member_entry = (CacheEntry) members [ii];
1887 if ((member_entry.EntryType & EntryType.Public) == 0)
1890 // TODO: Does anyone know easier way how to detect that member is internal ?
1891 switch (member_entry.EntryType & EntryType.MaskType) {
1892 case EntryType.Constructor:
1895 case EntryType.Field:
1896 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
1900 case EntryType.Method:
1901 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1905 case EntryType.Property:
1906 PropertyInfo pi = (PropertyInfo)member_entry.Member;
1907 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
1911 case EntryType.Event:
1912 EventInfo ei = (EventInfo)member_entry.Member;
1913 MethodInfo mi = ei.GetAddMethod ();
1914 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1918 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
1919 locase_table [lcase] = member_entry.Member;
1923 return locase_table;
1926 public Hashtable Members {
1933 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
1935 public void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
1937 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
1939 for (int i = 0; i < al.Count; ++i) {
1940 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
1943 if (entry.Member == this_builder)
1946 if ((entry.EntryType & tested_type) != tested_type)
1949 MethodBase method_to_compare = (MethodBase)entry.Member;
1950 AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant (
1951 method.ParameterTypes, TypeManager.GetArgumentTypes (method_to_compare));
1953 if (result == AttributeTester.Result.Ok)
1956 IMethodData md = TypeManager.GetMethod (method_to_compare);
1958 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
1959 // However it is exactly what csc does.
1960 if (md != null && !md.IsClsCompliaceRequired (method.Parent))
1963 Report.SymbolRelatedToPreviousError (entry.Member);
1965 case AttributeTester.Result.RefOutArrayError:
1966 Report.Error (3006, method.Location, "Overloaded method `{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());
1968 case AttributeTester.Result.ArrayArrayError:
1969 Report.Error (3007, method.Location, "Overloaded method `{0}' differing only by unnamed array types is not CLS-compliant", method.GetSignatureForError ());
1973 throw new NotImplementedException (result.ToString ());