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;
59 /// This returns exclusively the name as seen on the source code
60 /// it is not the fully qualifed type after resolution
62 public string GetPartialName ()
65 return Left.GetPartialName () + "." + Name;
70 public string GetTypeName ()
73 return Left.GetTypeName () + "." + Name;
78 public Expression GetTypeExpression (Location loc)
81 Expression lexpr = Left.GetTypeExpression (loc);
83 return new MemberAccess (lexpr, Name, loc);
85 return new SimpleName (Name, loc);
89 public MemberName Clone ()
92 return new MemberName (Left.Clone (), Name);
94 return new MemberName (Name);
97 public string Basename {
103 public override string ToString ()
105 throw new Exception ("This exception is thrown because someone is miss-using\n" +
106 "MemberName.ToString in the compiler. Please report this bug");
112 /// Base representation for members. This is used to keep track
113 /// of Name, Location and Modifier flags, and handling Attributes.
115 public abstract class MemberCore : Attributable {
121 // !(this is GenericMethod) && !(this is Method)
122 return MemberName.GetName (false);
126 public readonly MemberName MemberName;
129 /// Modifier flags that the user specified in the source code
133 public readonly TypeContainer Parent;
136 /// Location where this declaration happens
138 public readonly Location Location;
142 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
143 Obsolete = 1 << 1, // Type has obsolete attribute
144 ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
145 ClsCompliant = 1 << 3, // Type is CLS Compliant
146 CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
147 HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
148 HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
149 ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
150 Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
151 Excluded = 1 << 9, // Method is conditional
152 TestMethodDuplication = 1 << 10 // Test for duplication must be performed
156 /// MemberCore flags at first detected then cached
158 internal Flags caching_flags;
160 public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
167 caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
171 /// Tests presence of ObsoleteAttribute and report proper error
173 protected void CheckUsageOfObsoleteAttribute (Type type)
178 ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
179 if (obsolete_attr == null)
182 AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, Location);
185 public abstract bool Define ();
188 // Returns full member name for error message
190 public virtual string GetSignatureForError ()
196 /// Use this method when MethodBuilder is null
198 public virtual string GetSignatureForError (TypeContainer tc)
204 /// Base Emit method. This is also entry point for CLS-Compliant verification.
206 public virtual void Emit ()
208 // Hack with Parent == null is for EnumMember
209 if (Parent == null || (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent) == null))
210 VerifyObsoleteAttribute ();
212 if (!RootContext.VerifyClsCompliance)
215 VerifyClsCompliance (Parent);
218 public bool InUnsafe {
220 return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
225 // Whehter is it ok to use an unsafe pointer in this type container
227 public bool UnsafeOK (DeclSpace parent)
230 // First check if this MemberCore modifier flags has unsafe set
232 if ((ModFlags & Modifiers.UNSAFE) != 0)
235 if (parent.UnsafeContext)
238 Expression.UnsafeError (Location);
243 /// Returns instance of ObsoleteAttribute for this MemberCore
245 public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
247 // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
248 if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
252 caching_flags &= ~Flags.Obsolete_Undetected;
254 if (OptAttributes == null)
257 // TODO: remove this allocation
258 EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
259 null, null, ds.ModFlags, false);
261 Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
262 if (obsolete_attr == null)
265 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds);
266 if (obsolete == null)
269 caching_flags |= Flags.Obsolete;
274 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
276 public override bool IsClsCompliaceRequired (DeclSpace container)
278 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
279 return (caching_flags & Flags.ClsCompliant) != 0;
281 if (GetClsCompliantAttributeValue (container) && IsExposedFromAssembly (container)) {
282 caching_flags &= ~Flags.ClsCompliance_Undetected;
283 caching_flags |= Flags.ClsCompliant;
287 caching_flags &= ~Flags.ClsCompliance_Undetected;
292 /// Returns true when MemberCore is exposed from assembly.
294 protected bool IsExposedFromAssembly (DeclSpace ds)
296 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
299 DeclSpace parentContainer = ds;
300 while (parentContainer != null && parentContainer.ModFlags != 0) {
301 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
303 parentContainer = parentContainer.Parent;
309 /// Resolve CLSCompliantAttribute value or gets cached value.
311 bool GetClsCompliantAttributeValue (DeclSpace ds)
313 if (OptAttributes != null) {
314 EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
315 null, null, ds.ModFlags, false);
316 Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
317 if (cls_attribute != null) {
318 caching_flags |= Flags.HasClsCompliantAttribute;
319 return cls_attribute.GetClsCompliantAttributeValue (ds);
322 return ds.GetClsCompliantAttributeValue ();
326 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
328 protected bool HasClsCompliantAttribute {
330 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
336 /// The main virtual method for CLS-Compliant verifications.
337 /// The method returns true if member is CLS-Compliant and false if member is not
338 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
339 /// and add their extra verifications.
341 protected virtual bool VerifyClsCompliance (DeclSpace ds)
343 if (!IsClsCompliaceRequired (ds)) {
344 if ((RootContext.WarningLevel >= 2) && HasClsCompliantAttribute && !IsExposedFromAssembly (ds)) {
345 Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
350 if (!CodeGen.Assembly.IsClsCompliant) {
351 if (HasClsCompliantAttribute) {
352 Report.Error (3014, Location, "'{0}' cannot be marked as CLS-compliant because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
357 int index = Name.LastIndexOf ('.');
358 if (Name [index > 0 ? index + 1 : 0] == '_') {
359 Report.Error (3008, Location, "Identifier '{0}' is not CLS-compliant", GetSignatureForError () );
364 protected abstract void VerifyObsoleteAttribute ();
369 /// Base class for structs, classes, enumerations and interfaces.
372 /// They all create new declaration spaces. This
373 /// provides the common foundation for managing those name
376 public abstract class DeclSpace : MemberCore {
378 /// this points to the actual definition that is being
379 /// created with System.Reflection.Emit
381 public TypeBuilder TypeBuilder;
384 // This is the namespace in which this typecontainer
385 // was declared. We use this to resolve names.
387 public NamespaceEntry NamespaceEntry;
389 public Hashtable Cache = new Hashtable ();
391 public string Basename;
393 protected Hashtable defined_names;
395 static string[] attribute_targets = new string [] { "type" };
397 public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
398 Attributes attrs, Location l)
399 : base (parent, name, attrs, l)
402 Basename = name.Name;
403 defined_names = new Hashtable ();
407 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
409 protected bool AddToContainer (MemberCore symbol, bool is_method, string fullname, string basename)
411 if (basename == Basename) {
412 Report.SymbolRelatedToPreviousError (this);
413 Report.Error (542, "'{0}': member names cannot be the same as their enclosing type", symbol.Location, symbol.GetSignatureForError ());
417 MemberCore mc = (MemberCore)defined_names [fullname];
419 if (is_method && (mc is MethodCore || mc is IMethodData)) {
420 symbol.caching_flags |= Flags.TestMethodDuplication;
421 mc.caching_flags |= Flags.TestMethodDuplication;
426 Report.SymbolRelatedToPreviousError (mc);
427 Report.Error (102, symbol.Location, "The type '{0}' already contains a definition for '{1}'", GetSignatureForError (), basename);
431 defined_names.Add (fullname, symbol);
435 public void RecordDecl ()
437 if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
438 NamespaceEntry.DefineName (MemberName.Basename, this);
442 /// Returns the MemberCore associated with a given name in the declaration
443 /// space. It doesn't return method based symbols !!
446 public MemberCore GetDefinition (string name)
448 return (MemberCore)defined_names [name];
451 bool in_transit = false;
454 /// This function is used to catch recursive definitions
457 public bool InTransit {
468 /// Looks up the alias for the name
470 public string LookupAlias (string name)
472 if (NamespaceEntry != null)
473 return NamespaceEntry.LookupAlias (name);
479 // root_types contains all the types. All TopLevel types
480 // hence have a parent that points to `root_types', that is
481 // why there is a non-obvious test down here.
483 public bool IsTopLevel {
486 if (Parent.Parent == null)
493 public virtual void CloseType ()
495 if ((caching_flags & Flags.CloseTypeCreated) == 0){
497 TypeBuilder.CreateType ();
500 // The try/catch is needed because
501 // nested enumerations fail to load when they
504 // Even if this is the right order (enumerations
505 // declared after types).
507 // Note that this still creates the type and
508 // it is possible to save it
510 caching_flags |= Flags.CloseTypeCreated;
515 /// Should be overriten by the appropriate declaration space
517 public abstract TypeBuilder DefineType ();
520 /// Define all members, but don't apply any attributes or do anything which may
521 /// access not-yet-defined classes. This method also creates the MemberCache.
523 public abstract bool DefineMembers (TypeContainer parent);
526 // Whether this is an `unsafe context'
528 public bool UnsafeContext {
530 if ((ModFlags & Modifiers.UNSAFE) != 0)
533 return Parent.UnsafeContext;
538 public static string MakeFQN (string nsn, string name)
542 return String.Concat (nsn, ".", name);
545 EmitContext type_resolve_ec;
546 EmitContext GetTypeResolveEmitContext (TypeContainer parent, Location loc)
548 type_resolve_ec = new EmitContext (parent, this, loc, null, null, ModFlags, false);
549 type_resolve_ec.ResolvingTypeTree = true;
551 return type_resolve_ec;
555 // Looks up the type, as parsed into the expression `e'.
557 //[Obsolete ("This method is going away soon")]
558 public Type ResolveType (Expression e, bool silent, Location loc)
560 TypeExpr d = ResolveTypeExpr (e, silent, loc);
561 return d == null ? null : d.Type;
565 // Resolves the expression `e' for a type, and will recursively define
566 // types. This should only be used for resolving base types.
568 public TypeExpr ResolveTypeExpr (Expression e, bool silent, Location loc)
570 if (type_resolve_ec == null)
571 type_resolve_ec = GetTypeResolveEmitContext (Parent, loc);
572 type_resolve_ec.loc = loc;
573 type_resolve_ec.ContainerType = TypeBuilder;
575 return e.ResolveAsTypeTerminal (type_resolve_ec, silent);
578 public bool CheckAccessLevel (Type check_type)
580 if (check_type == TypeBuilder)
583 TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
586 // Broken Microsoft runtime, return public for arrays, no matter what
587 // the accessibility is for their underlying class, and they return
588 // NonPublic visibility for pointers
590 if (check_type.IsArray || check_type.IsPointer)
591 return CheckAccessLevel (TypeManager.GetElementType (check_type));
593 if (TypeBuilder == null)
594 // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
595 // However, this is invoked again later -- so safe to return true.
596 // May also be null when resolving top-level attributes.
600 case TypeAttributes.Public:
603 case TypeAttributes.NotPublic:
605 // This test should probably use the declaringtype.
607 return check_type.Assembly == TypeBuilder.Assembly;
609 case TypeAttributes.NestedPublic:
612 case TypeAttributes.NestedPrivate:
613 return NestedAccessible (check_type);
615 case TypeAttributes.NestedFamily:
616 return FamilyAccessible (check_type);
618 case TypeAttributes.NestedFamANDAssem:
619 return (check_type.Assembly == TypeBuilder.Assembly) &&
620 FamilyAccessible (check_type);
622 case TypeAttributes.NestedFamORAssem:
623 return (check_type.Assembly == TypeBuilder.Assembly) ||
624 FamilyAccessible (check_type);
626 case TypeAttributes.NestedAssembly:
627 return check_type.Assembly == TypeBuilder.Assembly;
630 Console.WriteLine ("HERE: " + check_attr);
635 protected bool NestedAccessible (Type check_type)
637 string check_type_name = check_type.FullName;
639 // At this point, we already know check_type is a nested class.
640 int cio = check_type_name.LastIndexOf ('+');
642 // Ensure that the string 'container' has a '+' in it to avoid false matches
643 string container = check_type_name.Substring (0, cio + 1);
645 // Ensure that type_name ends with a '+' so that it can match 'container', if necessary
646 string type_name = TypeBuilder.FullName + "+";
648 // If the current class is nested inside the container of check_type,
649 // we can access check_type even if it is private or protected.
650 return type_name.StartsWith (container);
653 protected bool FamilyAccessible (Type check_type)
655 Type declaring = check_type.DeclaringType;
656 if (TypeBuilder == declaring ||
657 TypeBuilder.IsSubclassOf (declaring))
660 return NestedAccessible (check_type);
663 // Access level of a type.
665 enum AccessLevel { // Each column represents `is this scope larger or equal to Blah scope'
666 // Public Assembly Protected
667 Protected = (0 << 0) | (0 << 1) | (X << 2),
668 Public = (X << 0) | (X << 1) | (X << 2),
669 Private = (0 << 0) | (0 << 1) | (0 << 2),
670 Internal = (0 << 0) | (X << 1) | (0 << 2),
671 ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
674 static AccessLevel GetAccessLevelFromModifiers (int flags)
676 if ((flags & Modifiers.INTERNAL) != 0) {
678 if ((flags & Modifiers.PROTECTED) != 0)
679 return AccessLevel.ProtectedOrInternal;
681 return AccessLevel.Internal;
683 } else if ((flags & Modifiers.PROTECTED) != 0)
684 return AccessLevel.Protected;
686 else if ((flags & Modifiers.PRIVATE) != 0)
687 return AccessLevel.Private;
690 return AccessLevel.Public;
693 // What is the effective access level of this?
695 AccessLevel EffectiveAccessLevel {
697 AccessLevel myAccess = GetAccessLevelFromModifiers (ModFlags);
698 if (!IsTopLevel && (Parent != null))
699 return myAccess & Parent.EffectiveAccessLevel;
705 // Return the access level for type `t'
706 static AccessLevel TypeEffectiveAccessLevel (Type t)
709 return AccessLevel.Public;
710 if (t.IsNestedPrivate)
711 return AccessLevel.Private;
713 return AccessLevel.Internal;
715 // By now, it must be nested
716 AccessLevel parentLevel = TypeEffectiveAccessLevel (t.DeclaringType);
718 if (t.IsNestedPublic)
720 if (t.IsNestedAssembly)
721 return parentLevel & AccessLevel.Internal;
722 if (t.IsNestedFamily)
723 return parentLevel & AccessLevel.Protected;
724 if (t.IsNestedFamORAssem)
725 return parentLevel & AccessLevel.ProtectedOrInternal;
726 if (t.IsNestedFamANDAssem)
727 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
729 // nested private is taken care of
731 throw new Exception ("I give up, what are you?");
735 // This answers `is the type P, as accessible as a member M which has the
736 // accessability @flags which is declared as a nested member of the type T, this declspace'
738 public bool AsAccessible (Type p, int flags)
741 // 1) if M is private, its accessability is the same as this declspace.
742 // we already know that P is accessible to T before this method, so we
746 if ((flags & Modifiers.PRIVATE) != 0)
749 while (p.IsArray || p.IsPointer || p.IsByRef)
750 p = TypeManager.GetElementType (p);
752 AccessLevel pAccess = TypeEffectiveAccessLevel (p);
753 AccessLevel mAccess = this.EffectiveAccessLevel &
754 GetAccessLevelFromModifiers (flags);
756 // for every place from which we can access M, we must
757 // be able to access P as well. So, we want
758 // For every bit in M and P, M_i -> P_1 == true
759 // or, ~ (M -> P) == 0 <-> ~ ( ~M | P) == 0
761 return ~ (~ mAccess | pAccess) == 0;
764 static DoubleHash dh = new DoubleHash (1000);
766 Type DefineTypeAndParents (DeclSpace tc)
768 DeclSpace container = tc.Parent;
770 if (container.TypeBuilder == null && container.Name != "")
771 DefineTypeAndParents (container);
773 return tc.DefineType ();
776 Type LookupInterfaceOrClass (string ns, string name, out bool error)
783 int p = name.LastIndexOf ('.');
785 if (dh.Lookup (ns, name, out r))
789 // If the type is not a nested type, we do not need `LookupType's processing.
790 // If the @name does not have a `.' in it, this cant be a nested type.
793 if (Namespace.IsNamespace (ns)) {
795 t = TypeManager.LookupType (ns + "." + name);
797 t = TypeManager.LookupTypeDirect (ns + "." + name);
801 t = TypeManager.LookupType (name);
803 t = TypeManager.LookupTypeDirect (name);
807 dh.Insert (ns, name, t);
812 // In case we are fed a composite name, normalize it.
816 ns = MakeFQN (ns, name.Substring (0, p));
817 name = name.Substring (p+1);
820 parent = RootContext.Tree.LookupByNamespace (ns, name);
821 if (parent == null) {
822 dh.Insert (ns, name, null);
826 t = DefineTypeAndParents (parent);
832 dh.Insert (ns, name, t);
836 public static void Error_AmbiguousTypeReference (Location loc, string name, Type t1, Type t2)
838 Report.Error (104, loc,
839 String.Format ("`{0}' is an ambiguous reference ({1} or {2}) ", name,
840 t1.FullName, t2.FullName));
844 /// GetType is used to resolve type names at the DeclSpace level.
845 /// Use this to lookup class/struct bases, interface bases or
846 /// delegate type references
850 /// Contrast this to LookupType which is used inside method bodies to
851 /// lookup types that have already been defined. GetType is used
852 /// during the tree resolution process and potentially define
853 /// recursively the type
855 public Type FindType (Location loc, string name)
861 // For the case the type we are looking for is nested within this one
862 // or is in any base class
864 DeclSpace containing_ds = this;
866 while (containing_ds != null){
867 Type container_type = containing_ds.TypeBuilder;
868 Type current_type = container_type;
870 while (current_type != null && current_type != TypeManager.object_type) {
871 string pre = current_type.FullName;
873 t = LookupInterfaceOrClass (pre, name, out error);
877 if ((t != null) && containing_ds.CheckAccessLevel (t))
880 current_type = current_type.BaseType;
882 containing_ds = containing_ds.Parent;
886 // Attempt to lookup the class on our namespace and all it's implicit parents
888 for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
889 t = LookupInterfaceOrClass (ns.FullName, name, out error);
898 // Attempt to do a direct unqualified lookup
900 t = LookupInterfaceOrClass ("", name, out error);
908 // Attempt to lookup the class on any of the `using'
912 for (NamespaceEntry ns = NamespaceEntry; ns != null; ns = ns.Parent){
914 t = LookupInterfaceOrClass (ns.FullName, name, out error);
921 if (name.IndexOf ('.') > 0)
924 string alias_value = ns.LookupAlias (name);
925 if (alias_value != null) {
926 t = LookupInterfaceOrClass ("", alias_value, out error);
935 // Now check the using clause list
938 foreach (Namespace using_ns in ns.GetUsingTable ()) {
939 match = LookupInterfaceOrClass (using_ns.Name, name, out error);
945 if (CheckAccessLevel (match)) {
946 Error_AmbiguousTypeReference (loc, name, t, match);
959 //Report.Error (246, Location, "Can not find type `"+name+"'");
964 /// This function is broken and not what you're looking for. It should only
965 /// be used while the type is still being created since it doesn't use the cache
966 /// and relies on the filter doing the member name check.
968 public abstract MemberList FindMembers (MemberTypes mt, BindingFlags bf,
969 MemberFilter filter, object criteria);
972 /// If we have a MemberCache, return it. This property may return null if the
973 /// class doesn't have a member cache or while it's still being created.
975 public abstract MemberCache MemberCache {
979 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
982 TypeBuilder.SetCustomAttribute (cb);
983 } catch (System.ArgumentException e) {
984 Report.Warning (-21, a.Location,
985 "The CharSet named property on StructLayout\n"+
986 "\tdoes not work correctly on Microsoft.NET\n"+
987 "\tYou might want to remove the CharSet declaration\n"+
988 "\tor compile using the Mono runtime instead of the\n"+
989 "\tMicrosoft .NET runtime\n"+
990 "\tThe runtime gave the error: " + e);
995 /// Goes through class hierarchy and get value of first CLSCompliantAttribute that found.
996 /// If no is attribute exists then return assembly CLSCompliantAttribute.
998 public bool GetClsCompliantAttributeValue ()
1000 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
1001 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
1003 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
1005 if (OptAttributes != null) {
1006 EmitContext ec = new EmitContext (Parent, this, Location,
1007 null, null, ModFlags, false);
1008 Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
1009 if (cls_attribute != null) {
1010 caching_flags |= Flags.HasClsCompliantAttribute;
1011 if (cls_attribute.GetClsCompliantAttributeValue (this)) {
1012 caching_flags |= Flags.ClsCompliantAttributeTrue;
1019 if (Parent == null) {
1020 if (CodeGen.Assembly.IsClsCompliant) {
1021 caching_flags |= Flags.ClsCompliantAttributeTrue;
1027 if (Parent.GetClsCompliantAttributeValue ()) {
1028 caching_flags |= Flags.ClsCompliantAttributeTrue;
1034 public override string[] ValidAttributeTargets {
1036 return attribute_targets;
1042 /// This is a readonly list of MemberInfo's.
1044 public class MemberList : IList {
1045 public readonly IList List;
1049 /// Create a new MemberList from the given IList.
1051 public MemberList (IList list)
1056 this.List = new ArrayList ();
1061 /// Concatenate the ILists `first' and `second' to a new MemberList.
1063 public MemberList (IList first, IList second)
1065 ArrayList list = new ArrayList ();
1066 list.AddRange (first);
1067 list.AddRange (second);
1072 public static readonly MemberList Empty = new MemberList (new ArrayList ());
1075 /// Cast the MemberList into a MemberInfo[] array.
1078 /// This is an expensive operation, only use it if it's really necessary.
1080 public static explicit operator MemberInfo [] (MemberList list)
1082 Timer.StartTimer (TimerType.MiscTimer);
1083 MemberInfo [] result = new MemberInfo [list.Count];
1084 list.CopyTo (result, 0);
1085 Timer.StopTimer (TimerType.MiscTimer);
1097 public bool IsSynchronized {
1099 return List.IsSynchronized;
1103 public object SyncRoot {
1105 return List.SyncRoot;
1109 public void CopyTo (Array array, int index)
1111 List.CopyTo (array, index);
1116 public IEnumerator GetEnumerator ()
1118 return List.GetEnumerator ();
1123 public bool IsFixedSize {
1129 public bool IsReadOnly {
1135 object IList.this [int index] {
1137 return List [index];
1141 throw new NotSupportedException ();
1145 // FIXME: try to find out whether we can avoid the cast in this indexer.
1146 public MemberInfo this [int index] {
1148 return (MemberInfo) List [index];
1152 public int Add (object value)
1154 throw new NotSupportedException ();
1157 public void Clear ()
1159 throw new NotSupportedException ();
1162 public bool Contains (object value)
1164 return List.Contains (value);
1167 public int IndexOf (object value)
1169 return List.IndexOf (value);
1172 public void Insert (int index, object value)
1174 throw new NotSupportedException ();
1177 public void Remove (object value)
1179 throw new NotSupportedException ();
1182 public void RemoveAt (int index)
1184 throw new NotSupportedException ();
1189 /// This interface is used to get all members of a class when creating the
1190 /// member cache. It must be implemented by all DeclSpace derivatives which
1191 /// want to support the member cache and by TypeHandle to get caching of
1192 /// non-dynamic types.
1194 public interface IMemberContainer {
1196 /// The name of the IMemberContainer. This is only used for
1197 /// debugging purposes.
1204 /// The type of this IMemberContainer.
1211 /// Returns the IMemberContainer of the parent class or null if this
1212 /// is an interface or TypeManger.object_type.
1213 /// This is used when creating the member cache for a class to get all
1214 /// members from the parent class.
1216 IMemberContainer ParentContainer {
1221 /// Whether this is an interface.
1228 /// Returns all members of this class with the corresponding MemberTypes
1229 /// and BindingFlags.
1232 /// When implementing this method, make sure not to return any inherited
1233 /// members and check the MemberTypes and BindingFlags properly.
1234 /// Unfortunately, System.Reflection is lame and doesn't provide a way to
1235 /// get the BindingFlags (static/non-static,public/non-public) in the
1236 /// MemberInfo class, but the cache needs this information. That's why
1237 /// this method is called multiple times with different BindingFlags.
1239 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1242 /// Return the container's member cache.
1244 MemberCache MemberCache {
1250 /// The MemberCache is used by dynamic and non-dynamic types to speed up
1251 /// member lookups. It has a member name based hash table; it maps each member
1252 /// name to a list of CacheEntry objects. Each CacheEntry contains a MemberInfo
1253 /// and the BindingFlags that were initially used to get it. The cache contains
1254 /// all members of the current class and all inherited members. If this cache is
1255 /// for an interface types, it also contains all inherited members.
1257 /// There are two ways to get a MemberCache:
1258 /// * if this is a dynamic type, lookup the corresponding DeclSpace and then
1259 /// use the DeclSpace.MemberCache property.
1260 /// * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1261 /// TypeHandle instance for the type and then use TypeHandle.MemberCache.
1263 public class MemberCache {
1264 public readonly IMemberContainer Container;
1265 protected Hashtable member_hash;
1266 protected Hashtable method_hash;
1269 /// Create a new MemberCache for the given IMemberContainer `container'.
1271 public MemberCache (IMemberContainer container)
1273 this.Container = container;
1275 Timer.IncrementCounter (CounterType.MemberCache);
1276 Timer.StartTimer (TimerType.CacheInit);
1280 // If we have a parent class (we have a parent class unless we're
1281 // TypeManager.object_type), we deep-copy its MemberCache here.
1282 if (Container.IsInterface) {
1285 if (Container.ParentContainer != null)
1286 parent = Container.ParentContainer.MemberCache;
1288 parent = TypeHandle.ObjectType.MemberCache;
1289 member_hash = SetupCacheForInterface (parent);
1290 } else if (Container.ParentContainer != null)
1291 member_hash = SetupCache (Container.ParentContainer.MemberCache);
1293 member_hash = new Hashtable ();
1295 // If this is neither a dynamic type nor an interface, create a special
1296 // method cache with all declared and inherited methods.
1297 Type type = container.Type;
1298 if (!(type is TypeBuilder) && !type.IsInterface) {
1299 method_hash = new Hashtable ();
1303 // Add all members from the current class.
1304 AddMembers (Container);
1306 Timer.StopTimer (TimerType.CacheInit);
1310 /// Bootstrap this member cache by doing a deep-copy of our parent.
1312 Hashtable SetupCache (MemberCache parent)
1314 Hashtable hash = new Hashtable ();
1316 IDictionaryEnumerator it = parent.member_hash.GetEnumerator ();
1317 while (it.MoveNext ()) {
1318 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1326 /// Add the contents of `new_hash' to `hash'.
1328 void AddHashtable (Hashtable hash, MemberCache cache)
1330 Hashtable new_hash = cache.member_hash;
1331 IDictionaryEnumerator it = new_hash.GetEnumerator ();
1332 while (it.MoveNext ()) {
1333 ArrayList list = (ArrayList) hash [it.Key];
1335 hash [it.Key] = list = new ArrayList ();
1337 foreach (CacheEntry entry in (ArrayList) it.Value) {
1338 if (entry.Container != cache.Container)
1346 /// Bootstrap the member cache for an interface type.
1347 /// Type.GetMembers() won't return any inherited members for interface types,
1348 /// so we need to do this manually. Interfaces also inherit from System.Object.
1350 Hashtable SetupCacheForInterface (MemberCache parent)
1352 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 AddMembers (MemberTypes.Constructor, container);
1377 AddMembers (MemberTypes.Field, container);
1378 AddMembers (MemberTypes.Method, container);
1379 AddMembers (MemberTypes.Property, container);
1380 AddMembers (MemberTypes.Event, container);
1381 // Nested types are returned by both Static and Instance searches.
1382 AddMembers (MemberTypes.NestedType,
1383 BindingFlags.Static | BindingFlags.Public, container);
1384 AddMembers (MemberTypes.NestedType,
1385 BindingFlags.Static | BindingFlags.NonPublic, container);
1388 void AddMembers (MemberTypes mt, IMemberContainer container)
1390 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1391 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1392 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1393 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1397 /// Add all members from class `container' with the requested MemberTypes and
1398 /// BindingFlags to the cache. This method is called multiple times with different
1399 /// MemberTypes and BindingFlags.
1401 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1403 MemberList members = container.GetMembers (mt, bf);
1405 foreach (MemberInfo member in members) {
1406 string name = member.Name;
1408 // We use a name-based hash table of ArrayList's.
1409 ArrayList list = (ArrayList) member_hash [name];
1411 list = new ArrayList ();
1412 member_hash.Add (name, list);
1415 // When this method is called for the current class, the list will
1416 // already contain all inherited members from our parent classes.
1417 // We cannot add new members in front of the list since this'd be an
1418 // expensive operation, that's why the list is sorted in reverse order
1419 // (ie. members from the current class are coming last).
1420 list.Add (new CacheEntry (container, member, mt, bf));
1425 /// Add all declared and inherited methods from class `type' to the method cache.
1427 void AddMethods (Type type)
1429 AddMethods (BindingFlags.Static | BindingFlags.Public |
1430 BindingFlags.FlattenHierarchy, type);
1431 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1432 BindingFlags.FlattenHierarchy, type);
1433 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1434 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1437 void AddMethods (BindingFlags bf, Type type)
1439 MemberInfo [] members = type.GetMethods (bf);
1441 Array.Reverse (members);
1443 foreach (MethodBase member in members) {
1444 string name = member.Name;
1446 // We use a name-based hash table of ArrayList's.
1447 ArrayList list = (ArrayList) method_hash [name];
1449 list = new ArrayList ();
1450 method_hash.Add (name, list);
1453 // Unfortunately, the elements returned by Type.GetMethods() aren't
1454 // sorted so we need to do this check for every member.
1455 BindingFlags new_bf = bf;
1456 if (member.DeclaringType == type)
1457 new_bf |= BindingFlags.DeclaredOnly;
1459 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1466 /// Compute and return a appropriate `EntryType' magic number for the given
1467 /// MemberTypes and BindingFlags.
1469 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1471 EntryType type = EntryType.None;
1473 if ((mt & MemberTypes.Constructor) != 0)
1474 type |= EntryType.Constructor;
1475 if ((mt & MemberTypes.Event) != 0)
1476 type |= EntryType.Event;
1477 if ((mt & MemberTypes.Field) != 0)
1478 type |= EntryType.Field;
1479 if ((mt & MemberTypes.Method) != 0)
1480 type |= EntryType.Method;
1481 if ((mt & MemberTypes.Property) != 0)
1482 type |= EntryType.Property;
1483 // Nested types are returned by static and instance searches.
1484 if ((mt & MemberTypes.NestedType) != 0)
1485 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1487 if ((bf & BindingFlags.Instance) != 0)
1488 type |= EntryType.Instance;
1489 if ((bf & BindingFlags.Static) != 0)
1490 type |= EntryType.Static;
1491 if ((bf & BindingFlags.Public) != 0)
1492 type |= EntryType.Public;
1493 if ((bf & BindingFlags.NonPublic) != 0)
1494 type |= EntryType.NonPublic;
1495 if ((bf & BindingFlags.DeclaredOnly) != 0)
1496 type |= EntryType.Declared;
1502 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1503 /// denote multiple member types. Returns true if the given flags value denotes a
1504 /// single member types.
1506 public static bool IsSingleMemberType (MemberTypes mt)
1509 case MemberTypes.Constructor:
1510 case MemberTypes.Event:
1511 case MemberTypes.Field:
1512 case MemberTypes.Method:
1513 case MemberTypes.Property:
1514 case MemberTypes.NestedType:
1523 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
1524 /// number to speed up the searching process.
1527 protected enum EntryType {
1532 MaskStatic = Instance|Static,
1536 MaskProtection = Public|NonPublic,
1540 Constructor = 0x020,
1547 MaskType = Constructor|Event|Field|Method|Property|NestedType
1550 protected struct CacheEntry {
1551 public readonly IMemberContainer Container;
1552 public readonly EntryType EntryType;
1553 public readonly MemberInfo Member;
1555 public CacheEntry (IMemberContainer container, MemberInfo member,
1556 MemberTypes mt, BindingFlags bf)
1558 this.Container = container;
1559 this.Member = member;
1560 this.EntryType = GetEntryType (mt, bf);
1565 /// This is called each time we're walking up one level in the class hierarchy
1566 /// and checks whether we can abort the search since we've already found what
1567 /// we were looking for.
1569 protected bool DoneSearching (ArrayList list)
1572 // We've found exactly one member in the current class and it's not
1573 // a method or constructor.
1575 if (list.Count == 1 && !(list [0] is MethodBase))
1579 // Multiple properties: we query those just to find out the indexer
1582 if ((list.Count > 0) && (list [0] is PropertyInfo))
1589 /// Looks up members with name `name'. If you provide an optional
1590 /// filter function, it'll only be called with members matching the
1591 /// requested member name.
1593 /// This method will try to use the cache to do the lookup if possible.
1595 /// Unlike other FindMembers implementations, this method will always
1596 /// check all inherited members - even when called on an interface type.
1598 /// If you know that you're only looking for methods, you should use
1599 /// MemberTypes.Method alone since this speeds up the lookup a bit.
1600 /// When doing a method-only search, it'll try to use a special method
1601 /// cache (unless it's a dynamic type or an interface) and the returned
1602 /// MemberInfo's will have the correct ReflectedType for inherited methods.
1603 /// The lookup process will automatically restart itself in method-only
1604 /// search mode if it discovers that it's about to return methods.
1606 ArrayList global = new ArrayList ();
1607 bool using_global = false;
1609 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1611 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1612 MemberFilter filter, object criteria)
1615 throw new Exception ();
1617 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1618 bool method_search = mt == MemberTypes.Method;
1619 // If we have a method cache and we aren't already doing a method-only search,
1620 // then we restart a method search if the first match is a method.
1621 bool do_method_search = !method_search && (method_hash != null);
1623 ArrayList applicable;
1625 // If this is a method-only search, we try to use the method cache if
1626 // possible; a lookup in the method cache will return a MemberInfo with
1627 // the correct ReflectedType for inherited methods.
1629 if (method_search && (method_hash != null))
1630 applicable = (ArrayList) method_hash [name];
1632 applicable = (ArrayList) member_hash [name];
1634 if (applicable == null)
1635 return emptyMemberInfo;
1638 // 32 slots gives 53 rss/54 size
1639 // 2/4 slots gives 55 rss
1641 // Strange: from 25,000 calls, only 1,800
1642 // are above 2. Why does this impact it?
1645 using_global = true;
1647 Timer.StartTimer (TimerType.CachedLookup);
1649 EntryType type = GetEntryType (mt, bf);
1651 IMemberContainer current = Container;
1654 // `applicable' is a list of all members with the given member name `name'
1655 // in the current class and all its parent classes. The list is sorted in
1656 // reverse order due to the way how the cache is initialy created (to speed
1657 // things up, we're doing a deep-copy of our parent).
1659 for (int i = applicable.Count-1; i >= 0; i--) {
1660 CacheEntry entry = (CacheEntry) applicable [i];
1662 // This happens each time we're walking one level up in the class
1663 // hierarchy. If we're doing a DeclaredOnly search, we must abort
1664 // the first time this happens (this may already happen in the first
1665 // iteration of this loop if there are no members with the name we're
1666 // looking for in the current class).
1667 if (entry.Container != current) {
1668 if (declared_only || DoneSearching (global))
1671 current = entry.Container;
1674 // Is the member of the correct type ?
1675 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1678 // Is the member static/non-static ?
1679 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1682 // Apply the filter to it.
1683 if (filter (entry.Member, criteria)) {
1684 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method)
1685 do_method_search = false;
1686 global.Add (entry.Member);
1690 Timer.StopTimer (TimerType.CachedLookup);
1692 // If we have a method cache and we aren't already doing a method-only
1693 // search, we restart in method-only search mode if the first match is
1694 // a method. This ensures that we return a MemberInfo with the correct
1695 // ReflectedType for inherited methods.
1696 if (do_method_search && (global.Count > 0)){
1697 using_global = false;
1699 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1702 using_global = false;
1703 MemberInfo [] copy = new MemberInfo [global.Count];
1704 global.CopyTo (copy);
1708 // find the nested type @name in @this.
1709 public Type FindNestedType (string name)
1711 ArrayList applicable = (ArrayList) member_hash [name];
1712 if (applicable == null)
1715 for (int i = applicable.Count-1; i >= 0; i--) {
1716 CacheEntry entry = (CacheEntry) applicable [i];
1717 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1718 return (Type) entry.Member;
1725 // This finds the method or property for us to override. invocationType is the type where
1726 // the override is going to be declared, name is the name of the method/property, and
1727 // paramTypes is the parameters, if any to the method or property
1729 // Because the MemberCache holds members from this class and all the base classes,
1730 // we can avoid tons of reflection stuff.
1732 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1734 ArrayList applicable;
1735 if (method_hash != null && !is_property)
1736 applicable = (ArrayList) method_hash [name];
1738 applicable = (ArrayList) member_hash [name];
1740 if (applicable == null)
1743 // Walk the chain of methods, starting from the top.
1745 for (int i = applicable.Count - 1; i >= 0; i--) {
1746 CacheEntry entry = (CacheEntry) applicable [i];
1748 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1751 PropertyInfo pi = null;
1752 MethodInfo mi = null;
1753 FieldInfo fi = null;
1754 Type [] cmpAttrs = null;
1757 if ((entry.EntryType & EntryType.Field) != 0) {
1758 fi = (FieldInfo)entry.Member;
1760 // TODO: For this case we ignore member type
1761 //fb = TypeManager.GetField (fi);
1762 //cmpAttrs = new Type[] { fb.MemberType };
1764 pi = (PropertyInfo) entry.Member;
1765 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1768 mi = (MethodInfo) entry.Member;
1769 cmpAttrs = TypeManager.GetArgumentTypes (mi);
1773 // TODO: Almost duplicate !
1775 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1776 case FieldAttributes.Private:
1778 // A private method is Ok if we are a nested subtype.
1779 // The spec actually is not very clear about this, see bug 52458.
1781 if (invocationType != entry.Container.Type &
1782 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1786 case FieldAttributes.FamANDAssem:
1787 case FieldAttributes.Assembly:
1789 // Check for assembly methods
1791 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1795 return entry.Member;
1799 // Check the arguments
1801 if (cmpAttrs.Length != paramTypes.Length)
1804 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1805 if (paramTypes [j] != cmpAttrs [j])
1809 // get one of the methods because this has the visibility info.
1812 mi = pi.GetGetMethod (true);
1814 mi = pi.GetSetMethod (true);
1820 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1821 case MethodAttributes.Private:
1823 // A private method is Ok if we are a nested subtype.
1824 // The spec actually is not very clear about this, see bug 52458.
1826 if (invocationType == entry.Container.Type ||
1827 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1828 return entry.Member;
1831 case MethodAttributes.FamANDAssem:
1832 case MethodAttributes.Assembly:
1834 // Check for assembly methods
1836 if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1837 return entry.Member;
1842 // A protected method is ok, because we are overriding.
1843 // public is always ok.
1845 return entry.Member;
1855 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1856 /// We handle two cases. The first is for types without parameters (events, field, properties).
1857 /// The second are methods, indexers and this is why ignore_complex_types is here.
1858 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1860 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1862 ArrayList applicable = null;
1864 if (method_hash != null)
1865 applicable = (ArrayList) method_hash [name];
1867 if (applicable != null) {
1868 for (int i = applicable.Count - 1; i >= 0; i--) {
1869 CacheEntry entry = (CacheEntry) applicable [i];
1870 if ((entry.EntryType & EntryType.Public) != 0)
1871 return entry.Member;
1875 if (member_hash == null)
1877 applicable = (ArrayList) member_hash [name];
1879 if (applicable != null) {
1880 for (int i = applicable.Count - 1; i >= 0; i--) {
1881 CacheEntry entry = (CacheEntry) applicable [i];
1882 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1883 if (ignore_complex_types) {
1884 if ((entry.EntryType & EntryType.Method) != 0)
1887 // Does exist easier way how to detect indexer ?
1888 if ((entry.EntryType & EntryType.Property) != 0) {
1889 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1890 if (arg_types.Length > 0)
1894 return entry.Member;
1901 Hashtable locase_table;
1904 /// Builds low-case table for CLS Compliance test
1906 public Hashtable GetPublicMembers ()
1908 if (locase_table != null)
1909 return locase_table;
1911 locase_table = new Hashtable ();
1912 foreach (DictionaryEntry entry in member_hash) {
1913 ArrayList members = (ArrayList)entry.Value;
1914 for (int ii = 0; ii < members.Count; ++ii) {
1915 CacheEntry member_entry = (CacheEntry) members [ii];
1917 if ((member_entry.EntryType & EntryType.Public) == 0)
1920 // TODO: Does anyone know easier way how to detect that member is internal ?
1921 switch (member_entry.EntryType & EntryType.MaskType) {
1922 case EntryType.Constructor:
1925 case EntryType.Field:
1926 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
1930 case EntryType.Method:
1931 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1935 case EntryType.Property:
1936 PropertyInfo pi = (PropertyInfo)member_entry.Member;
1937 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
1941 case EntryType.Event:
1942 EventInfo ei = (EventInfo)member_entry.Member;
1943 MethodInfo mi = ei.GetAddMethod ();
1944 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1948 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
1949 locase_table [lcase] = member_entry.Member;
1953 return locase_table;
1956 public Hashtable Members {
1963 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
1965 public void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
1967 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
1969 for (int i = 0; i < al.Count; ++i) {
1970 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
1973 if (entry.Member == this_builder)
1976 if ((entry.EntryType & tested_type) != tested_type)
1979 MethodBase method_to_compare = (MethodBase)entry.Member;
1980 if (AttributeTester.AreOverloadedMethodParamsClsCompliant (method.ParameterTypes, TypeManager.GetArgumentTypes (method_to_compare)))
1983 IMethodData md = TypeManager.GetMethod (method_to_compare);
1985 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
1986 // However it is exactly what csc does.
1987 if (md != null && !md.IsClsCompliaceRequired (method.Parent))
1990 Report.SymbolRelatedToPreviousError (entry.Member);
1991 Report.Error (3006, method.Location, "Overloaded method '{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());