2004-05-24 Anders Carlsson <andersca@gnome.org>
[mono.git] / mcs / mcs / class.cs
index 27c509ec5075523ccf1afbc67243afe9a9d2320b..151d912828b85c9e803522cc6ec660def725f224 100755 (executable)
@@ -34,6 +34,7 @@ using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 
 namespace Mono.CSharp {
 
@@ -110,17 +111,16 @@ namespace Mono.CSharp {
                // from classes from the arraylist `type_bases' 
                //
                string     base_class_name;
+               public Type base_classs_type;
 
                ArrayList type_bases;
 
-               // Information in the case we are an attribute type
-
-               public AttributeTargets Targets = AttributeTargets.All;
-               public bool AllowMultiple = false;
-               public bool Inherited;
+               bool members_defined;
+               bool members_defined_ok;
 
                // The interfaces we implement.
                TypeExpr [] ifaces;
+               Type[] base_inteface_types;
 
                // The parent member container and our member cache
                IMemberContainer parent_container;
@@ -394,7 +394,7 @@ namespace Mono.CSharp {
                        if (indexers == null)
                                indexers = new ArrayList ();
 
-                       if (i.InterfaceType != null)
+                       if (i.ExplicitInterfaceName != null)
                                indexers.Insert (0, i);
                        else
                                indexers.Add (i);
@@ -416,6 +416,26 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.Type == TypeManager.default_member_type) {
+                               if (Indexers != null) {
+                                       Report.Error (646, a.Location,
+                                                     "Cannot specify the DefaultMember attribute on" +
+                                                     " a type containing an indexer");
+                                       return;
+                               }
+                       }
+                       
+                       base.ApplyAttributeBuilder (a, cb);
+               } 
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               throw new NotSupportedException ();
+                       }
+               }
+
                public void RegisterOrder (Interface iface)
                {
                        if (interface_order == null)
@@ -617,7 +637,8 @@ namespace Mono.CSharp {
                ///   The @parent argument is set to the parent object or null
                ///   if this is `System.Object'. 
                /// </summary>
-               TypeExpr [] GetClassBases (bool is_class, out TypeExpr parent, out bool error)
+               TypeExpr [] GetClassBases (bool is_class, bool is_iface,
+                                          out TypeExpr parent, out bool error)
                {
                        ArrayList bases = Bases;
                        int count;
@@ -625,7 +646,7 @@ namespace Mono.CSharp {
 
                        error = false;
 
-                       if (is_class)
+                       if (is_class || is_iface)
                                parent = null;
                        else
                                parent = TypeManager.system_valuetype_expr;
@@ -730,13 +751,20 @@ namespace Mono.CSharp {
                                }
 
                                for (int x = 0; x < j; x++) {
-                                       if (resolved == ifaces [x]) {
+                                       if (resolved.Equals (ifaces [x])) {
                                                Report.Error (528, "`" + name + "' is already listed in interface list");
                                                error = true;
                                                return null;
                                        }
                                }
 
+                               if (is_iface &&
+                                   !resolved.AsAccessible (Parent, ModFlags))
+                                       Report.Error (61, Location,
+                                                     "Inconsistent accessibility: base interface `" +
+                                                     name + "' is less accessible than interface `" +
+                                                     Name + "'");
+
                                ifaces [j] = resolved;
                        }
 
@@ -751,7 +779,7 @@ namespace Mono.CSharp {
                public override TypeBuilder DefineType ()
                {
                        TypeExpr parent;
-                       bool is_class;
+                       bool is_class, is_iface;
 
                        if (TypeBuilder != null)
                                return TypeBuilder;
@@ -767,14 +795,20 @@ namespace Mono.CSharp {
                        
                        InTransit = true;
 
-                       if (this is Class)
-                               is_class = true;
-                       else
+                       if (this is Interface) {
+                               is_iface = true;
                                is_class = false;
+                       } else {
+                               is_iface = false;
+                               if (this is Class)
+                                       is_class = true;
+                               else
+                                       is_class = false;
+                       }
 
                        ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
 
-                       ifaces = GetClassBases (is_class, out parent, out error); 
+                       ifaces = GetClassBases (is_class, is_iface, out parent, out error); 
 
                        if (error)
                                return null;
@@ -784,11 +818,8 @@ namespace Mono.CSharp {
 
                        TypeAttributes type_attributes = TypeAttr;
 
-                       Type ptype;
                        if (parent != null)
-                               ptype = parent.ResolveType (ec);
-                       else
-                               ptype = null;
+                               base_classs_type = parent.ResolveType (ec);
 
                        if (IsTopLevel){
                                if (TypeManager.NamespaceClash (Name, Location)) {
@@ -798,7 +829,7 @@ namespace Mono.CSharp {
                                
                                ModuleBuilder builder = CodeGen.Module.Builder;
                                TypeBuilder = builder.DefineType (
-                                       Name, type_attributes, ptype, null);
+                                       Name, type_attributes, base_classs_type, null);
                                
                        } else {
                                TypeBuilder builder = Parent.DefineType ();
@@ -806,7 +837,7 @@ namespace Mono.CSharp {
                                        return null;
                                
                                TypeBuilder = builder.DefineNestedType (
-                                       Basename, type_attributes, ptype, null);
+                                       Basename, type_attributes, base_classs_type, null);
                        }
                                
                        //
@@ -816,16 +847,18 @@ namespace Mono.CSharp {
                        // be specified.
                        //
 
-                       if (!is_class && !have_nonstatic_fields){
+                       if (!is_class && !is_iface && !have_nonstatic_fields){
                                TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
                                                         FieldAttributes.Private);
                        }
 
                        // add interfaces that were not added at type creation
                        if (ifaces != null) {
-                               foreach (TypeExpr iface in ifaces) {
-                                       Type itype = iface.ResolveType (ec);
+                               base_inteface_types = new Type[ifaces.Length];
+                               for (int i = 0; i < ifaces.Length; ++i) {
+                                       Type itype = ifaces [i].ResolveType (ec);
                                        TypeBuilder.AddInterfaceImplementation (itype);
+                                       base_inteface_types [i] = itype;
                                }
                        }
 
@@ -838,7 +871,6 @@ namespace Mono.CSharp {
 
                        if ((parent != null) && parent.IsAttribute) {
                                RootContext.RegisterAttribute (this);
-                               TypeManager.RegisterAttrType (TypeBuilder, this);
                        } else
                                RootContext.RegisterOrder (this); 
                                
@@ -949,11 +981,11 @@ namespace Mono.CSharp {
 
                //
                // Defines the indexers, and also verifies that the IndexerNameAttribute in the
-               // class is consisten.  Either it is `Item' or it is the name defined by all the
+               // class is consistent.  Either it is `Item' or it is the name defined by all the
                // indexers with the `IndexerName' attribute.
                //
                // Turns out that the IndexerNameAttribute is applied to each indexer,
-               // but it is never emitted, instead a DefaultName attribute is attached
+               // but it is never emitted, instead a DefaultMember attribute is attached
                // to the class.
                //
                void DefineIndexers ()
@@ -965,39 +997,33 @@ namespace Mono.CSharp {
                        // explicit one actually implements the interface while the other one is just
                        // a normal indexer.  See bug #37714.
                        //
-                       ArrayList list = new ArrayList ();
-                       foreach (Indexer i in Indexers){
-                               if (i.ExplicitInterfaceName != null)
-                                       list.Add (i);
-                       }
-                       foreach (Indexer i in Indexers){
-                               if (i.ExplicitInterfaceName == null)
-                                       list.Add (i);
-                       }
 
-                       foreach (Indexer i in list){
+                       // Invariant maintained by AddIndexer(): All explicit interface indexers precede normal indexers
+                       bool seen_normal_indexers = false;
+
+                       foreach (Indexer i in Indexers) {
                                string name;
 
                                i.Define (this);
 
                                name = i.IndexerName;
 
-                               if (i.InterfaceType != null)
+                               if (i.InterfaceType != null) {
+                                       if (seen_normal_indexers)
+                                               throw new Exception ("Internal Error: 'Indexers' array not sorted properly.");
                                        continue;
+                               }
 
-                               if (class_indexer_name == null){
+                               seen_normal_indexers = true;
+
+                               if (class_indexer_name == null)
                                        class_indexer_name = name;
-                                       continue;
-                               }
-                               
-                               if (name == class_indexer_name)
-                                       continue;
-                               
-                               Report.Error (
-                                       668, "Two indexers have different names, " +
-                                       " you should use the same name for all your indexers");
+                               else if (name != class_indexer_name)
+                                       Report.Error (668, "Two indexers have different names, " +
+                                                     " you should use the same name for all your indexers");
                        }
-                       if (class_indexer_name == null)
+
+                       if (seen_normal_indexers && class_indexer_name == null)
                                class_indexer_name = "Item";
                        IndexerName = class_indexer_name;
                }
@@ -1011,6 +1037,17 @@ namespace Mono.CSharp {
                ///   Populates our TypeBuilder with fields and methods
                /// </summary>
                public override bool DefineMembers (TypeContainer container)
+               {
+                       if (members_defined)
+                               return members_defined_ok;
+
+                       members_defined_ok = DoDefineMembers ();
+                       members_defined = true;
+
+                       return members_defined_ok;
+               }
+
+               bool DoDefineMembers ()
                {
                        MemberInfo [] defined_names = null;
 
@@ -1101,7 +1138,8 @@ namespace Mono.CSharp {
                                        ReportStructInitializedInstanceError ();
                        }
 
-                       Pending = PendingImplementation.GetPendingImplementations (this);
+                       if (!(this is Interface))
+                               Pending = PendingImplementation.GetPendingImplementations (this);
                        
                        //
                        // Constructors are not in the defined_names array
@@ -1121,10 +1159,8 @@ namespace Mono.CSharp {
                        if (events != null)
                                DefineMembers (events, defined_names);
 
-                       if (indexers != null) {
+                       if (indexers != null)
                                DefineIndexers ();
-                       } else
-                               IndexerName = "Item";
 
                        if (operators != null){
                                DefineMembers (operators, null);
@@ -1182,6 +1218,71 @@ namespace Mono.CSharp {
                        accepting_filter = new MemberFilter (AlwaysAccept);
                        mif_compare = new MemberInfoCompare ();
                }
+
+               public MethodInfo[] GetMethods ()
+               {
+                       ArrayList members = new ArrayList ();
+
+                       DefineMembers (null);
+
+                       if (methods != null) {
+                               int len = methods.Count;
+                               for (int i = 0; i < len; i++) {
+                                       Method m = (Method) methods [i];
+
+                                       members.Add (m.MethodBuilder);
+                               }
+                       }
+
+                       if (operators != null) {
+                               int len = operators.Count;
+                               for (int i = 0; i < len; i++) {
+                                       Operator o = (Operator) operators [i];
+
+                                       members.Add (o.OperatorMethodBuilder);
+                               }
+                       }
+
+                       if (properties != null) {
+                               int len = properties.Count;
+                               for (int i = 0; i < len; i++) {
+                                       Property p = (Property) properties [i];
+
+                                       if (p.GetBuilder != null)
+                                               members.Add (p.GetBuilder);
+                                       if (p.SetBuilder != null)
+                                               members.Add (p.SetBuilder);
+                               }
+                       }
+                               
+                       if (indexers != null) {
+                               int len = indexers.Count;
+                               for (int i = 0; i < len; i++) {
+                                       Indexer ix = (Indexer) indexers [i];
+
+                                       if (ix.GetBuilder != null)
+                                               members.Add (ix.GetBuilder);
+                                       if (ix.SetBuilder != null)
+                                               members.Add (ix.SetBuilder);
+                               }
+                       }
+
+                       if (events != null) {
+                               int len = events.Count;
+                               for (int i = 0; i < len; i++) {
+                                       Event e = (Event) events [i];
+
+                                       if (e.AddBuilder != null)
+                                               members.Add (e.AddBuilder);
+                                       if (e.RemoveBuilder != null)
+                                               members.Add (e.RemoveBuilder);
+                               }
+                       }
+
+                       MethodInfo[] retMethods = new MethodInfo [members.Count];
+                       members.CopyTo (retMethods, 0);
+                       return retMethods;
+               }
                
                /// <summary>
                ///   This method returns the members of this type just like Type.FindMembers would
@@ -1550,13 +1651,26 @@ namespace Mono.CSharp {
                        //
                        // Lookup members in parent if requested.
                        //
-                       if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
-                               MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
-                               if (list.Count > 0) {
-                                       if (members == null)
-                                               members = new ArrayList ();
+                       if ((bf & BindingFlags.DeclaredOnly) == 0) {
+                               if (TypeBuilder.BaseType != null) {
+                                       MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
+                                       if (list.Count > 0) {
+                                               if (members == null)
+                                                       members = new ArrayList ();
                                        
-                                       members.AddRange (list);
+                                               members.AddRange (list);
+                                       }
+                               }
+                               if (base_inteface_types != null) {
+                                       foreach (Type base_type in base_inteface_types) {
+                                               MemberList list = TypeContainer.FindMembers (base_type, mt, bf, filter, criteria);
+
+                                               if (list.Count > 0) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       members.AddRange (list);
+                                               }
+                                       }
                                }
                        }
 
@@ -1607,55 +1721,8 @@ namespace Mono.CSharp {
                        return;
                }
 
-               /// <summary>
-               ///   Emits the code, this step is performed after all
-               ///   the types, enumerations, constructors
-               /// </summary>
-               public void Emit ()
+               protected virtual void VerifyMembers (EmitContext ec)
                {
-                       if (instance_constructors != null)
-                               foreach (Constructor c in instance_constructors)
-                                       c.Emit (this);
-
-                       if (default_static_constructor != null)
-                               default_static_constructor.Emit (this);
-                       
-                       if (methods != null)
-                               foreach (Method m in methods)
-                                       m.Emit (this);
-
-                       if (operators != null)
-                               foreach (Operator o in operators)
-                                       o.Emit (this);
-
-                       if (properties != null)
-                               foreach (Property p in properties)
-                                       p.Emit (this);
-
-                       if (indexers != null){
-                               foreach (Indexer ix in indexers)
-                                       ix.Emit (this);
-                               
-                               CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
-                                       this, IndexerName, ModFlags, Location);
-                               TypeBuilder.SetCustomAttribute (cb);
-                       }
-                       
-                       if (fields != null)
-                               foreach (Field f in fields)
-                                       f.Emit (this);
-
-                       if (events != null){
-                               foreach (Event e in Events)
-                                       e.Emit (this);
-                       }
-
-                       if (Pending != null)
-                               if (Pending.VerifyPendingMethods ())
-                                       return;
-                       
-                       Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes);
-
                        //
                        // Check for internal or private fields that were never assigned
                        //
@@ -1695,19 +1762,121 @@ namespace Mono.CSharp {
                                        }
                                }
                        }
+               }
+
+               /// <summary>
+               ///   Emits the code, this step is performed after all
+               ///   the types, enumerations, constructors
+               /// </summary>
+               public void Emit ()
+               {
+                       if (OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
+                               
+                       Emit (this);
+
+                       if (instance_constructors != null) {
+                               if (TypeBuilder.IsSubclassOf (TypeManager.attribute_type) && IsClsCompliaceRequired (this)) {
+                                       bool has_compliant_args = false;
+
+                                       foreach (Constructor c in instance_constructors) {
+                                               c.Emit (this);
+
+                                               if (has_compliant_args)
+                                                       continue;
+
+                                               has_compliant_args = c.HasCompliantArgs;
+                                       }
+                                       if (!has_compliant_args)
+                                               Report.Error_T (3015, Location, GetSignatureForError ());
+                               } else {
+                                       foreach (Constructor c in instance_constructors)
+                                               c.Emit (this);
+                               }
+                       }
+
+                       if (default_static_constructor != null)
+                               default_static_constructor.Emit (this);
+                       
+                       if (methods != null)
+                               foreach (Method m in methods)
+                                       m.Emit (this);
+
+                       if (operators != null)
+                               foreach (Operator o in operators)
+                                       o.Emit (this);
+
+                       if (properties != null)
+                               foreach (Property p in properties)
+                                       p.Emit (this);
+
+                       if (indexers != null){
+                               foreach (Indexer ix in indexers)
+                                       ix.Emit (this);
+                               if (IndexerName != null) {
+                                       CustomAttributeBuilder cb = EmitDefaultMemberAttr ();
+                                       TypeBuilder.SetCustomAttribute (cb);
+                               }
+                       }
+                       
+                       if (fields != null)
+                               foreach (Field f in fields)
+                                       f.Emit (this);
+
+                       if (events != null){
+                               foreach (Event e in Events)
+                                       e.Emit (this);
+                       }
+
+                       if (delegates != null) {
+                               foreach (Delegate d in Delegates) {
+                                       d.Emit (this);
+                               }
+                       }
+
+                       if (Pending != null)
+                               if (Pending.VerifyPendingMethods ())
+                                       return;
+
+                       VerifyMembers (ec);
                        
 //                     if (types != null)
 //                             foreach (TypeContainer tc in types)
 //                                     tc.Emit ();
                }
-               
+
+               CustomAttributeBuilder EmitDefaultMemberAttr ()
+               {
+                       EmitContext ec = new EmitContext (this, Location, null, null, ModFlags);
+
+                       Expression ml = Expression.MemberLookup (ec, TypeManager.default_member_type,
+                                                                ".ctor", MemberTypes.Constructor,
+                                                                BindingFlags.Public | BindingFlags.Instance,
+                                                                Location.Null);
+                       
+                       MethodGroupExpr mg = (MethodGroupExpr) ml;
+
+                       MethodBase constructor = mg.Methods [0];
+
+                       string [] vals = { IndexerName };
+
+                       CustomAttributeBuilder cb = null;
+                       try {
+                               cb = new CustomAttributeBuilder ((ConstructorInfo) constructor, vals);
+                       } catch {
+                               Report.Warning (-100, "Can not set the indexer default member attribute");
+                       }
+
+                       return cb;
+               }
+
                public override void CloseType ()
                {
-                       if (Created)
+                       if ((caching_flags & Flags.CloseTypeCreated) != 0)
                                return;
                        
                        try {
-                               Created = true;
+                               caching_flags |= Flags.CloseTypeCreated;
                                TypeBuilder.CreateType ();
                        } catch (TypeLoadException){
                                //
@@ -1892,6 +2061,19 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected override bool VerifyClsCompliance (DeclSpace ds)
+               {
+                       if (!base.VerifyClsCompliance (ds))
+                               return false;
+
+                       // parent_container is null for System.Object
+                       if (parent_container != null && !AttributeTester.IsClsCompliant (parent_container.Type)) {
+                               Report.Error_T (3009, Location, GetSignatureForError (),  TypeManager.CSharpName (parent_container.Type));
+                       }
+                       return true;
+               }
+
+
                /// <summary>
                ///   Performs checks for an explicit interface implementation.  First it
                ///   checks whether the `interface_type' is a base inteface implementation.
@@ -1948,7 +2130,7 @@ namespace Mono.CSharp {
 
                bool IMemberContainer.IsInterface {
                        get {
-                               return false;
+                               return this is Interface;
                        }
                }
 
@@ -2132,7 +2314,52 @@ namespace Mono.CSharp {
                
        }
 
-       public class Class : TypeContainer {
+       public class ClassOrStruct : TypeContainer {
+               bool hasExplicitLayout = false;
+               public ClassOrStruct (NamespaceEntry ns, TypeContainer parent, string name, Attributes attrs, Location l)
+                       : base (ns, parent, name, attrs, l)
+               {
+               }
+
+               protected override void VerifyMembers (EmitContext ec) 
+               {
+                       if (Fields != null) {
+                               foreach (Field f in Fields) {
+                                       if ((f.ModFlags & Modifiers.STATIC) != 0)
+                                               continue;
+                                       if (hasExplicitLayout) {
+                                               if (f.OptAttributes == null 
+                                                   || !f.OptAttributes.Contains (TypeManager.field_offset_attribute_type, ec)) {
+                                                       Report.Error (625, f.Location,
+                                                                     "Instance field of type marked with" 
+                                                                     + " StructLayout(LayoutKind.Explicit) must have a"
+                                                                     + " FieldOffset attribute.");
+                                               }
+                                       }
+                                       else {
+                                               if (f.OptAttributes != null 
+                                                   && f.OptAttributes.Contains (TypeManager.field_offset_attribute_type, ec)) {
+                                                       Report.Error (636, f.Location,
+                                                                     "The FieldOffset attribute can only be placed on members of "
+                                                                     + "types marked with the StructLayout(LayoutKind.Explicit)");
+                                               }
+                                       }
+                               }
+                       }
+                       base.VerifyMembers (ec);
+               }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.Type == TypeManager.struct_layout_attribute_type
+                           && (LayoutKind) a.GetPositionalValue (0) == LayoutKind.Explicit)
+                               hasExplicitLayout = true;
+
+                       base.ApplyAttributeBuilder (a, cb);
+               }
+       }
+
+       public class Class : ClassOrStruct {
                // <summary>
                //   Modifiers allowed in a class declaration
                // </summary>
@@ -2146,7 +2373,12 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.UNSAFE;
 
-               public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+
+               // Information in the case we are an attribute type
+               AttributeUsageAttribute attribute_usage;
+
+               public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+                             Attributes attrs, Location l)
                        : base (ns, parent, name, attrs, l)
                {
                        int accmods;
@@ -2157,6 +2389,27 @@ namespace Mono.CSharp {
                                accmods = Modifiers.PRIVATE;
 
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+                       attribute_usage = new AttributeUsageAttribute (AttributeTargets.All);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Class;
+                       }
+               }
+
+               public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.UsageAttribute != null)
+                               attribute_usage = a.UsageAttribute;
+
+                       base.ApplyAttributeBuilder (a, cb);
+               }
+
+               public AttributeUsageAttribute AttributeUsage {
+                       get {
+                               return attribute_usage;
+                       }
                }
 
                //
@@ -2170,7 +2423,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class Struct : TypeContainer {
+       public class Struct : ClassOrStruct {
                // <summary>
                //   Modifiers allowed in a struct declaration
                // </summary>
@@ -2197,6 +2450,13 @@ namespace Mono.CSharp {
                        this.ModFlags |= Modifiers.SEALED;
                }
 
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Struct;
+                       }
+               }
+
+
                //
                // FIXME: Allow the user to specify a different set of attributes
                // in some cases (Sealed for example is mandatory for a class,
@@ -2212,27 +2472,79 @@ namespace Mono.CSharp {
                }
        }
 
-       public abstract class MethodCore : MemberBase {
-               public readonly Parameters Parameters;
-               protected Block block;
-               protected DeclSpace ds;
-               
-               //
-               // Parameters, cached for semantic analysis.
-               //
-               protected InternalParameters parameter_info;
-               protected Type [] parameter_types;
+       /// <summary>
+       ///   Interfaces
+       /// </summary>
+       public class Interface : TypeContainer, IMemberContainer {
+               /// <summary>
+               ///   Modifiers allowed in a class declaration
+               /// </summary>
+               public const int AllowedModifiers =
+                       Modifiers.NEW       |
+                       Modifiers.PUBLIC    |
+                       Modifiers.PROTECTED |
+                       Modifiers.INTERNAL  |
+                       Modifiers.UNSAFE    |
+                       Modifiers.PRIVATE;
 
-               // <summary>
-               //   This is set from TypeContainer.DefineMembers if this method overrides something.
+               public Interface (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+                                 Attributes attrs, Location l)
+                       : base (ns, parent, name, attrs, l)
+               {
+                       int accmods;
+
+                       if (parent.Parent == null)
+                               accmods = Modifiers.INTERNAL;
+                       else
+                               accmods = Modifiers.PRIVATE;
+
+                       this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Interface;
+                       }
+               }
+
+               public override TypeAttributes TypeAttr {
+                       get {
+                               return base.TypeAttr |
+                                       TypeAttributes.AutoLayout |
+                                       TypeAttributes.Abstract |
+                                       TypeAttributes.Interface;
+                       }
+               }
+       }
+
+       public abstract class MethodCore : MemberBase {
+               public readonly Parameters Parameters;
+               protected Block block;
+               public DeclSpace ds;
+               
+               //
+               // Parameters, cached for semantic analysis.
+               //
+               protected InternalParameters parameter_info;
+               protected Type [] parameter_types;
+
+               // <summary>
+               //   This is set from TypeContainer.DefineMembers if this method overrides something.
                // </summary>
                public bool OverridesSomething;
 
+               // Whether this is an operator method.
+               public bool IsOperator;
+
+               static string[] attribute_targets = new string [] { "method", "return" };
+
                public MethodCore (DeclSpace ds, Expression type, int mod, int allowed_mod,
-                                  string name, Attributes attrs, Parameters parameters, Location loc)
+                                  bool is_interface, string name, Attributes attrs,
+                                  Parameters parameters, Location loc)
                        : base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
                {
                        Parameters = parameters;
+                       IsInterface = is_interface;
                        this.ds = ds;
                }
                
@@ -2282,128 +2594,84 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public CallingConventions GetCallingConvention (bool is_class)
-               {
-                       CallingConventions cc = 0;
-                       
-                       cc = Parameters.GetCallingConvention ();
-
-                       if (is_class)
-                               if ((ModFlags & Modifiers.STATIC) == 0)
-                                       cc |= CallingConventions.HasThis;
-
-                       // FIXME: How is `ExplicitThis' used in C#?
-                       
-                       return cc;
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
                }
 
-               //
-               // The method's attributes are passed in because we need to extract
-               // the "return:" attribute from there to apply on the return type
-               //
-               static public void LabelParameters (EmitContext ec,
-                                                    MethodBase builder,
-                                                    Parameters parameters,
-                                                    Attributes method_attrs,
-                                                    Location loc)
+               protected override bool VerifyClsCompliance (DeclSpace ds)
                {
-                       //
-                       // Define each type attribute (in/out/ref) and
-                       // the argument names.
-                       //
-                       Parameter [] p = parameters.FixedParameters;
-                       int i = 0;
-                       
-                       MethodBuilder mb = null;
-                       ConstructorBuilder cb = null;
-
-                       if (builder is MethodBuilder)
-                               mb = (MethodBuilder) builder;
-                       else
-                               cb = (ConstructorBuilder) builder;
-
-                       if (p != null){
-                               for (i = 0; i < p.Length; i++) {
-                                       ParameterBuilder pb;
-                                       ParameterAttributes par_attr = p [i].Attributes;
-                                       
-                                       if (mb == null)
-                                               pb = cb.DefineParameter (
-                                                       i + 1, par_attr, p [i].Name);
-                                       else 
-                                               pb = mb.DefineParameter (
-                                                       i + 1, par_attr, p [i].Name);
-                                       
-                                       Attributes attr = p [i].OptAttributes;
-                                       if (attr != null){
-                                               Attribute.ApplyAttributes (ec, pb, pb, attr);
-
-                                               if (par_attr == ParameterAttributes.Out){
-                                                       if (attr.Contains (TypeManager.in_attribute_type))
-                                                               Report.Error (36, loc,
-                                                                    "Can not use [In] attribute on out parameter");
-                                               }
-                                       }
+                       if (!base.VerifyClsCompliance (ds)) {
+                               if ((ModFlags & Modifiers.ABSTRACT) != 0 && IsExposedFromAssembly (ds) && ds.IsClsCompliaceRequired (ds)) {
+                                       Report.Error_T (3011, Location, GetSignatureForError ());
                                }
+                               return false;
                        }
 
-                       if (parameters.ArrayParameter != null){
-                               ParameterBuilder pb;
-                               Parameter array_param = parameters.ArrayParameter;
+                       AttributeTester.AreParametersCompliant (Parameters.FixedParameters, Location);
 
-                               if (mb == null)
-                                       pb = cb.DefineParameter (
-                                               i + 1, array_param.Attributes,
-                                               array_param.Name);
-                               else
-                                       pb = mb.DefineParameter (
-                                               i + 1, array_param.Attributes,
-                                               array_param.Name);
-                                       
-                               CustomAttributeBuilder a = new CustomAttributeBuilder (
-                                       TypeManager.cons_param_array_attribute, new object [0]);
-                               
-                               pb.SetCustomAttribute (a);
+                       if (!AttributeTester.IsClsCompliant (MemberType)) {
+                               Report.Error_T (3002, Location, GetSignatureForError ());
                        }
 
-                       //
-                       // And now for the return type attribute decoration
-                       //
-                       ParameterBuilder ret_pb;
-                       Attributes ret_attrs = null;
-                               
-                       if (mb == null || method_attrs == null)
-                               return;
+                       return true;
+               }
 
-                       foreach (AttributeSection asec in method_attrs.AttributeSections) {
+               protected bool IsDuplicateImplementation (TypeContainer tc, MethodCore method)
+               {
+                       if ((method == this) || (method.Name != Name))
+                               return false;
 
-                               if (asec.Target != "return")
-                                       continue;
+                       Type[] param_types = method.ParameterTypes;
+                       if (param_types == null)
+                               return false;
 
-                               if (ret_attrs == null)
-                                       ret_attrs = new Attributes (asec);
-                               else
-                                       ret_attrs.AddAttributeSection (asec);
-                       }
+                       if (param_types.Length != ParameterTypes.Length)
+                               return false;
 
-                       if (ret_attrs != null) {
-                               try {
-                                       ret_pb = mb.DefineParameter (0, ParameterAttributes.None, "");
-                                       Attribute.ApplyAttributes (ec, ret_pb, ret_pb, ret_attrs);
+                       for (int i = 0; i < param_types.Length; i++)
+                               if (param_types [i] != ParameterTypes [i])
+                                       return false;
 
-                                } catch (ArgumentOutOfRangeException) {
-                                       Report.Warning (
-                                               -24, loc,
-                                               ".NET SDK 1.0 does not permit setting custom attributes" +
-                                                " on the return type of a method");
+                       //
+                       // Try to report 663: method only differs on out/ref
+                       //
+                       ParameterData info = ParameterInfo;
+                       ParameterData other_info = method.ParameterInfo;
+                       for (int i = 0; i < info.Count; i++){
+                               if (info.ParameterModifier (i) != other_info.ParameterModifier (i)){
+                                       Report.Error (663, Location, "Overload method only differs in parameter modifier");
+                                       return false;
                                }
                        }
+
+                       Report.Error (111, Location, "Class `{0}' already defines a " +
+                                     "member called `{1}' with the same parameter types",
+                                     tc.Name, Name);
+                       return true;
+               }
+
+               public CallingConventions GetCallingConvention (bool is_class)
+               {
+                       CallingConventions cc = 0;
+                       
+                       cc = Parameters.GetCallingConvention ();
+
+                       if (is_class)
+                               if ((ModFlags & Modifiers.STATIC) == 0)
+                                       cc |= CallingConventions.HasThis;
+
+                       // FIXME: How is `ExplicitThis' used in C#?
+                       
+                       return cc;
                }
        }
 
-       public class Method : MethodCore, IIteratorContainer {
+       public class Method : MethodCore, IIteratorContainer, IMethodData {
                public MethodBuilder MethodBuilder;
                public MethodData MethodData;
+               ReturnParameter return_attributes;
 
                /// <summary>
                ///   Modifiers allowed in a class declaration
@@ -2423,15 +2691,26 @@ namespace Mono.CSharp {
                        Modifiers.METHOD_YIELDS | 
                        Modifiers.EXTERN;
 
+               const int AllowedInterfaceModifiers =
+                       Modifiers.NEW | Modifiers.UNSAFE;
+
                //
                // return_type can be "null" for VOID values.
                //
-               public Method (DeclSpace ds, Expression return_type, int mod, string name,
-                              Parameters parameters, Attributes attrs, Location l)
-                       : base (ds, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
+               public Method (DeclSpace ds, Expression return_type, int mod, bool is_iface,
+                              string name, Parameters parameters, Attributes attrs, Location l)
+                       : base (ds, return_type, mod,
+                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+                               is_iface, name, attrs, parameters, l)
                {
                }
 
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Method | AttributeTargets.ReturnValue;
+                       }
+               }
+               
                //
                // Returns the `System.Type' for the ReturnType of this
                // function.  Provides a nice cache.  (used between semantic analysis
@@ -2442,8 +2721,10 @@ namespace Mono.CSharp {
                        return MemberType;
                }
 
-               // Whether this is an operator method.
-               public bool IsOperator;
+               public override string GetSignatureForError()
+               {
+                       return TypeManager.CSharpSignature (MethodBuilder);
+               }
 
                 void DuplicateEntryPoint (MethodInfo b, Location location)
                 {
@@ -2484,6 +2765,26 @@ namespace Mono.CSharp {
                                 return false;
                 }
 
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.Target == "return") {
+                               if (return_attributes == null)
+                                       return_attributes = new ReturnParameter (MethodBuilder, Location);
+
+                               return_attributes.ApplyAttributeBuilder (a, cb);
+                               return;
+                       }
+
+                       if (a.Type == TypeManager.methodimpl_attr_type && a.IsInternalCall) {
+                               MethodBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
+                       }
+
+                       if (a.Type == TypeManager.dllimport_type)
+                               return;
+
+                       MethodBuilder.SetCustomAttribute (cb);
+               }
+
                //
                // Checks our base implementation if any
                //
@@ -2499,7 +2800,6 @@ namespace Mono.CSharp {
                        if (IsOperator) {
                                flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
                        } else {
-                               
                                //
                                // Check in our class for dups
                                //
@@ -2509,23 +2809,8 @@ namespace Mono.CSharp {
                                        
                                        for (int i = 0; i < arLen; i++) {
                                                Method m = (Method) ar [i];
-                                               if (m == this || m.Name != this.Name)
-                                                       continue;
-                                               
-                                               if (m.MethodBuilder != null && m.ParameterTypes.Length == ParameterTypes.Length) {
-                                                       
-                                                       for (int j = ParameterTypes.Length - 1; j >= 0; j --)
-                                                               if (m.ParameterTypes [j] != ParameterTypes [j])
-                                                                       goto next;
-                                                       
-                                                       Report.Error (111, Location, "Class `" + container.Name + "' " +
-                                                                     "already defines a member called `" + Name + "' " +
-                                                                     "with the same parameter types");
+                                               if (IsDuplicateImplementation (container, m))
                                                        return false;
-                                               }
-                                               
-                                       next :
-                                               ;
                                        }
                                }
                        }
@@ -2538,31 +2823,19 @@ namespace Mono.CSharp {
                        Type ptype = container.TypeBuilder.BaseType;
 
                        // ptype is only null for System.Object while compiling corlib.
-                       if (ptype != null){
-                               MemberList mi, mi_static, mi_instance;
-
-                               mi_instance = TypeContainer.FindMembers (
-                                       ptype, MemberTypes.Method,
-                                       BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
-                                       MethodSignature.inheritable_method_signature_filter,
-                                       ms);
-
-                               if (mi_instance.Count > 0){
-                                       mi = mi_instance;
-                               } else {
-                                       mi_static = TypeContainer.FindMembers (
-                                               ptype, MemberTypes.Method,
-                                               BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
-                                               MethodSignature.inheritable_method_signature_filter, ms);
-
-                                       if (mi_static.Count > 0)
-                                               mi = mi_static;
-                                       else
-                                               mi = null;
+                       if (ptype != null) {
+                               
+                               //
+                               // Explicit implementations do not have `parent' methods, however,
+                               // the member cache stores them there. Without this check, we get
+                               // an incorrect warning in corlib.
+                               //
+                               if (! IsExplicitImpl) {
+                                       parent_method = (MethodInfo)((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
+                                               container.TypeBuilder, Name, ParameterTypes, false);
                                }
-
-                               if (mi != null && mi.Count > 0){
-                                       parent_method = (MethodInfo) mi [0];
+                               
+                               if (parent_method != null) {
                                        string name = parent_method.DeclaringType.Name + "." +
                                                parent_method.Name;
 
@@ -2608,11 +2881,7 @@ namespace Mono.CSharp {
                        if (!CheckBase (container))
                                return false;
 
-                       CallingConventions cc = GetCallingConvention (container is Class);
-
-                       MethodData = new MethodData (container, this, null, MemberType,
-                                                    ParameterTypes, ParameterInfo, cc,
-                                                    OptAttributes, ModFlags, flags, true);
+                       MethodData = new MethodData (this, ParameterInfo, ModFlags, flags, true, this);
 
                        if (!MethodData.Define (container))
                                return false;
@@ -2659,9 +2928,10 @@ namespace Mono.CSharp {
                //
                // Emits the code
                // 
-               public void Emit (TypeContainer container)
+               public override void Emit (TypeContainer container)
                {
-                       MethodData.Emit (container, Block, this);
+                       MethodData.Emit (container, this);
+                       base.Emit (container);
                        Block = null;
                        MethodData = null;
                }
@@ -2670,11 +2940,61 @@ namespace Mono.CSharp {
                {
                        ModFlags |= Modifiers.METHOD_YIELDS;
                }
+       
+               protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+               {
+                       return IsIdentifierAndParamClsCompliant (ds, Name, MethodBuilder, parameter_types);
+               }
+
+               #region IMethodData Members
+
+               public CallingConventions CallingConventions {
+                       get {
+                               CallingConventions cc = Parameters.GetCallingConvention ();
+
+                               if (!IsInterface)
+                                       if ((ModFlags & Modifiers.STATIC) == 0)
+                                               cc |= CallingConventions.HasThis;
+
+                               // FIXME: How is `ExplicitThis' used in C#?
+                       
+                               return cc;
+                       }
+               }
+
+               public Type ReturnType {
+                       get {
+                               return MemberType;
+                       }
+               }
+
+               public string MethodName {
+                       get {
+                               return ShortName;
+                       }
+               }
+
+               public new Location Location {
+                       get {
+                               return base.Location;
+                       }
+               }
+
+               public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+               {
+                       return new EmitContext (tc, ds, Location, ig, ReturnType, ModFlags, false);
+               }
+
+               public ObsoleteAttribute GetObsoleteAttribute ()
+               {
+                       return GetObsoleteAttribute (ds);
+               }
+               #endregion
        }
 
        public abstract class ConstructorInitializer {
                ArrayList argument_list;
-               ConstructorInfo parent_constructor;
+               protected ConstructorInfo parent_constructor;
                Parameters parameters;
                Location loc;
                
@@ -2721,14 +3041,24 @@ namespace Mono.CSharp {
                                t = ec.ContainerType;
 
                        parent_constructor_group = Expression.MemberLookup (
-                               ec, t, null, t, ".ctor", 
-                               MemberTypes.Constructor,
+                               ec, t, ".ctor", MemberTypes.Constructor,
                                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                loc);
                        
                        if (parent_constructor_group == null){
-                               Report.Error (1501, loc,
-                                      "Can not find a constructor for this argument list");
+                               parent_constructor_group = Expression.MemberLookup (
+                                       ec, t, ".ctor", MemberTypes.Constructor,
+                                       BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly,
+                                       loc);
+
+                               if (parent_constructor_group != null)
+                                       Report.Error (
+                                               112, loc, "`{0}.{1}' is inaccessible due to " +
+                                               "its protection level", t.FullName, t.Name);
+                               else
+                                       Report.Error (
+                                               1501, loc, "Can not find a constructor for " +
+                                               "this argument list");
                                return false;
                        }
                        
@@ -2759,6 +3089,49 @@ namespace Mono.CSharp {
                                        Invocation.EmitCall (ec, true, false, ec.GetThis (loc), parent_constructor, argument_list, loc);
                        }
                }
+
+               /// <summary>
+               /// Method search for base ctor. (We do not cache it).
+               /// </summary>
+               Constructor GetOverloadedConstructor (TypeContainer tc)
+               {
+                       if (tc.InstanceConstructors == null)
+                               return null;
+
+                       foreach (Constructor c in tc.InstanceConstructors) {
+                               if (Arguments == null) {
+                                       if (c.ParameterTypes.Length == 0)
+                                               return c;
+
+                                       continue;
+                               }
+
+                               if (c.ParameterTypes.Length != Arguments.Count)
+                                       continue;
+
+                               for (int i = 0; i < Arguments.Count; ++i)
+                                       if (c.ParameterTypes [i] != ((Argument)Arguments [i]).Type)
+                                               continue;
+
+                               return c;
+                       }
+
+                       throw new InternalErrorException ();
+               }
+
+               //TODO: implement caching when it will be necessary
+               public virtual void CheckObsoleteAttribute (TypeContainer tc, Location loc)
+               {
+                       Constructor ctor = GetOverloadedConstructor (tc);
+                       if (ctor == null)
+                               return;
+
+                       ObsoleteAttribute oa = ctor.GetObsoleteAttribute (tc);
+                       if (oa == null)
+                               return;
+
+                       AttributeTester.Report_ObsoleteMessage (oa, ctor.GetSignatureForError (), loc);
+               }
        }
 
        public class ConstructorBaseInitializer : ConstructorInitializer {
@@ -2766,6 +3139,24 @@ namespace Mono.CSharp {
                        base (argument_list, pars, l)
                {
                }
+
+               public override void CheckObsoleteAttribute(TypeContainer tc, Location loc) {
+                       if (parent_constructor == null)
+                               return;
+
+                       TypeContainer type_ds = TypeManager.LookupTypeContainer (tc.base_classs_type);
+                       if (type_ds == null) {
+                               ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (parent_constructor);
+
+                               if (oa != null)
+                                       AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (parent_constructor), loc);
+
+                               return;
+                       }
+
+                       base.CheckObsoleteAttribute (type_ds, loc);
+               }
+
        }
 
        public class ConstructorThisInitializer : ConstructorInitializer {
@@ -2791,17 +3182,36 @@ namespace Mono.CSharp {
                        Modifiers.EXTERN |              
                        Modifiers.PRIVATE;
 
+               bool has_compliant_args = false;
                //
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
                public Constructor (DeclSpace ds, string name, int mod, Parameters args,
                                    ConstructorInitializer init, Location l)
-                       : base (ds, null, mod, AllowedModifiers, name, null, args, l)
+                       : base (ds, null, mod, AllowedModifiers, false, name, null, args, l)
                {
                        Initializer = init;
                }
 
+               public override string GetSignatureForError()
+               {
+                       return TypeManager.CSharpSignature (ConstructorBuilder);
+               }
+
+               public bool HasCompliantArgs {
+                       get {
+                               return has_compliant_args;
+                       }
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Constructor;
+                       }
+               }
+
+
                //
                // Returns true if this is a default constructor
                //
@@ -2817,6 +3227,11 @@ namespace Mono.CSharp {
                                        (Initializer is ConstructorBaseInitializer) &&
                                        (Initializer.Arguments == null);
                }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       ConstructorBuilder.SetCustomAttribute (cb);
+               }
                
                protected override bool CheckBase (TypeContainer container)
                {
@@ -2840,35 +3255,14 @@ namespace Mono.CSharp {
                        // Check in our class for dups
                        //
                        ArrayList ar = container.InstanceConstructors;
-                       
-                       // I don't think this is possible (there should be
-                       // at least one, us). However, just in case:
-                       if (ar == null)
-                               return true;
-                       
-                       int arLen = ar.Count;
-                       for (int i = 0; i < arLen; i++) {
-                               Constructor m = (Constructor) ar [i];
-                               
-                               //
-                               // Check for a ctor with identical args
-                               //
-                               if (m == this || m.ConstructorBuilder == null || m.ParameterTypes.Length != ParameterTypes.Length)
-                                       continue;
-
-                               for (int j = ParameterTypes.Length - 1; j >= 0; j --)
-                                       if (m.ParameterTypes [j] != ParameterTypes [j])
-                                               goto next;
-                               
-                               Report.Error (
-                                       111, Location,
-                                       "Class `{0}' already contains a definition with the " +
-                                       "same return value and parameter types for constructor `{1}'",
-                                       container.Name, Name);
-                               return false;
-                               
-                       next :
-                               ;
+                       if (ar != null) {
+                               int arLen = ar.Count;
+                                       
+                               for (int i = 0; i < arLen; i++) {
+                                       Constructor m = (Constructor) ar [i];
+                                       if (IsDuplicateImplementation (container, m))
+                                               return false;
+                               }
                        }
                        
                        return true;
@@ -2923,7 +3317,7 @@ namespace Mono.CSharp {
                //
                // Emits the code
                //
-               public void Emit (TypeContainer container)
+               public override void Emit (TypeContainer container)
                {
                        ILGenerator ig = ConstructorBuilder.GetILGenerator ();
                        EmitContext ec = new EmitContext (container, Location, ig, null, ModFlags, true);
@@ -2963,8 +3357,7 @@ namespace Mono.CSharp {
                                ec.IsStatic = false;
                        }
 
-                       MethodCore.LabelParameters (ec, ConstructorBuilder,
-                                                    Parameters, OptAttributes, Location);
+                       Parameters.LabelParameters (ec, ConstructorBuilder, Location);
                        
                        SymbolWriter sw = CodeGen.SymbolWriter;
                        bool generate_debugging = false;
@@ -2992,13 +3385,16 @@ namespace Mono.CSharp {
                                                container.EmitFieldInitializers (ec);
                                }
                        }
-                       if (Initializer != null)
+                       if (Initializer != null) {
+                               Initializer.CheckObsoleteAttribute (container, Location);
                                Initializer.Emit (ec);
+                       }
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
                                container.EmitFieldInitializers (ec);
 
-                       Attribute.ApplyAttributes (ec, ConstructorBuilder, this, OptAttributes);
+                       if (OptAttributes != null) 
+                               OptAttributes.Emit (ec, this);
 
                        // If this is a non-static `struct' constructor and doesn't have any
                        // initializer, it must initialize all of the struct's fields.
@@ -3010,25 +3406,110 @@ namespace Mono.CSharp {
                        if (generate_debugging)
                                sw.CloseMethod ();
 
+                       base.Emit (container);
+
                        block = null;
                }
-       }
 
-       //
-       // Encapsulates most of the Method's state
-       //
-       public class MethodData {
-               //
-               // The return type of this method
-               //
-               public readonly Type ReturnType;
-               public readonly Type[] ParameterTypes;
-               public readonly InternalParameters ParameterInfo;
-               public readonly CallingConventions CallingConventions;
-               public readonly Attributes OptAttributes;
-               public readonly Location Location;
+               // For constructors is needed to test only parameters
+               protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+               {
+                       if (parameter_types == null || parameter_types.Length == 0)
+                               return true;
 
-               //
+                       TypeContainer tc = ds as TypeContainer;
+
+                       for (int i = 0; i < tc.InstanceConstructors.Count; i++) {
+                               Constructor c = (Constructor) tc.InstanceConstructors [i];
+                                               
+                               if (c == this || c.ParameterTypes.Length == 0)
+                                       continue;
+
+                               if (!c.IsClsCompliaceRequired (ds))
+                                       continue;
+                               
+                               if (!AttributeTester.AreOverloadedMethodParamsClsCompliant (parameter_types, c.ParameterTypes)) {
+                                       Report.Error_T (3006, Location, GetSignatureForError ());
+                                       return false;
+                               }
+                       }
+
+                       if (tc.TypeBuilder.BaseType == null)
+                               return true;
+
+                       DeclSpace temp_ds = TypeManager.LookupDeclSpace (tc.TypeBuilder.BaseType);
+                       if (temp_ds != null)
+                               return IsIdentifierClsCompliant (temp_ds);
+
+                       MemberInfo[] ml = tc.TypeBuilder.BaseType.FindMembers (MemberTypes.Constructor, BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance, null, null);
+                       // Skip parameter-less ctor
+                       if (ml.Length < 2)
+                               return true;
+
+                       foreach (ConstructorInfo ci in ml) {
+                               object[] cls_attribute = ci.GetCustomAttributes (TypeManager.cls_compliant_attribute_type, false);
+                               if (cls_attribute.Length == 1 && (!((CLSCompliantAttribute)cls_attribute[0]).IsCompliant))
+                                       continue;
+
+                               if (!AttributeTester.AreOverloadedMethodParamsClsCompliant (parameter_types, TypeManager.GetArgumentTypes (ci))) {
+                                       Report.Error_T (3006, Location, GetSignatureForError ());
+                                       return false;
+                               }
+                       }
+                       
+                       return true;
+               }
+
+               protected override bool VerifyClsCompliance (DeclSpace ds)
+               {
+                       if (!base.VerifyClsCompliance (ds) || !IsExposedFromAssembly (ds)) {
+                               return false;
+                       }
+                       
+                       if (ds.TypeBuilder.IsSubclassOf (TypeManager.attribute_type)) {
+                               foreach (Type param in parameter_types) {
+                                       if (param.IsArray) {
+                                               return false;
+                                       }
+                               }
+                       }
+                       has_compliant_args = true;
+                       return true;
+               }
+
+       }
+
+       /// <summary>
+       /// Interface for MethodData class. Holds links to parent members to avoid member duplication.
+       /// </summary>
+       public interface IMethodData
+       {
+               CallingConventions CallingConventions { get; }
+               Location Location { get; }
+               string MethodName { get; }
+               Type[] ParameterTypes { get; }
+               Type ReturnType { get; }
+
+               Attributes OptAttributes { get; }
+               Block Block { get; }
+
+               EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig);
+               ObsoleteAttribute GetObsoleteAttribute ();
+       }
+
+       //
+       // Encapsulates most of the Method's state
+       //
+       public class MethodData {
+
+               readonly IMethodData method;
+
+               //
+               // The return type of this method
+               //
+               public readonly InternalParameters ParameterInfo;
+
+               //
                // Are we implementing an interface ?
                //
                public bool IsImplementing = false;
@@ -3036,12 +3517,10 @@ namespace Mono.CSharp {
                //
                // Protected data.
                //
-               protected DeclSpace ds;
                protected MemberBase member;
                protected int modifiers;
                protected MethodAttributes flags;
                protected bool is_method;
-               protected string accessor_name;
 
                //
                // It can either hold a string with the condition, or an arraylist of conditions.
@@ -3054,58 +3533,42 @@ namespace Mono.CSharp {
                        }
                }
 
-               public MethodData (DeclSpace ds, MemberBase member, string name, Type return_type,
-                                  Type [] parameter_types, InternalParameters parameters,
-                                  CallingConventions cc, Attributes opt_attrs,
-                                  int modifiers, MethodAttributes flags, bool is_method)
+               public MethodData (MemberBase member, InternalParameters parameters,
+                                  int modifiers, MethodAttributes flags, bool is_method, IMethodData method)
                {
-                       this.ds = ds;
                        this.member = member;
-                       this.accessor_name = name;
-                       this.ReturnType = return_type;
-                       this.ParameterTypes = parameter_types;
                        this.ParameterInfo = parameters;
-                       this.CallingConventions = cc;
-                       this.OptAttributes = opt_attrs;
                        this.modifiers = modifiers;
                        this.flags = flags;
                        this.is_method = is_method;
-                       this.Location = member.Location;
                        this.conditionals = null;
+
+                       this.method = method;
                }
 
                //
                // Attributes.
                //
                Attribute dllimport_attribute = null;
-               string obsolete = null;
-               bool obsolete_error = false;
 
-               public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method)
+               public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method,
+                                                    EmitContext ec)
                {
-                       if ((opt_attrs == null) || (opt_attrs.AttributeSections == null))
+                       if ((opt_attrs == null) || (opt_attrs.Attrs == null))
                                return true;
 
-                       foreach (AttributeSection asec in opt_attrs.AttributeSections) {
-                               if (asec.Attributes == null)
-                                       continue;
-                                       
-                               foreach (Attribute a in asec.Attributes) {
-                                       if (a.Name == "Conditional") {
-                                               if (!ApplyConditionalAttribute (a))
-                                                       return false;
-                                       } else if (a.Name == "Obsolete") {
-                                               if (!ApplyObsoleteAttribute (a))
-                                                       return false;
-                                       } else if (a.Name.IndexOf ("DllImport") != -1) {
-                                               if (!is_method) {
-                                                       a.Type = TypeManager.dllimport_type;
-                                                       Attribute.Error_AttributeNotValidForElement (a, Location);
-                                                       return false;
-                                               }
-                                               if (!ApplyDllImportAttribute (a))
-                                                       return false;
+                       foreach (Attribute a in opt_attrs.Attrs) {
+                               Type attr_type = a.ResolveType (ec, true);
+                               if (attr_type == TypeManager.conditional_attribute_type) {
+                                       if (!ApplyConditionalAttribute (a))
+                                               return false;
+                               } else if (attr_type == TypeManager.dllimport_type) {
+                                       if (!is_method) {
+                                               Attribute.Error_AttributeNotValidForElement (a, method.Location);
+                                               return false;
                                        }
+                                       if (!ApplyDllImportAttribute (a))
+                                               return false;
                                }
                        }
 
@@ -3119,7 +3582,7 @@ namespace Mono.CSharp {
                {
                        const int extern_static = Modifiers.EXTERN | Modifiers.STATIC;
                        if ((modifiers & extern_static) != extern_static) {
-                               Report.Error (601, Location,
+                               Report.Error (601, method.Location,
                                              "The DllImport attribute must be specified on a method " +
                                              "marked `static' and `extern'.");
                                return false;
@@ -3130,20 +3593,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               //
-               // Applies the `Obsolete' attribute to the method.
-               //
-               protected virtual bool ApplyObsoleteAttribute (Attribute a)
-               {
-                       if (obsolete != null) {
-                               Report.Error (579, Location, "Duplicate `Obsolete' attribute");
-                               return false;
-                       }
-
-                       obsolete = a.Obsolete_GetObsoleteMessage (out obsolete_error);
-                       return obsolete != null;
-               }
-
                //
                // Applies the `Conditional' attribute to the method.
                //
@@ -3151,7 +3600,7 @@ namespace Mono.CSharp {
                {
                        // The Conditional attribute is only valid on methods.
                        if (!is_method) {
-                               Attribute.Error_AttributeNotValidForElement (a, Location);
+                               Attribute.Error_AttributeNotValidForElement (a, method.Location);
                                return false;
                        }
 
@@ -3160,29 +3609,29 @@ namespace Mono.CSharp {
                        if (condition == null)
                                return false;
 
-                       if (ReturnType != TypeManager.void_type) {
-                               Report.Error (578, Location,
+                       if (method.ReturnType != TypeManager.void_type) {
+                               Report.Error (578, method.Location,
                                              "Conditional not valid on `" + member.Name + "' " +
                                              "because its return type is not void");
                                return false;
                        }
 
                        if ((modifiers & Modifiers.OVERRIDE) != 0) {
-                               Report.Error (243, Location,
+                               Report.Error (243, method.Location,
                                              "Conditional not valid on `" + member.Name + "' " +
                                              "because it is an override method");
                                return false;
                        }
 
                        if (member.IsExplicitImpl) {
-                               Report.Error (577, Location,
+                               Report.Error (577, method.Location,
                                              "Conditional not valid on `" + member.Name + "' " +
                                              "because it is an explicit interface implementation");
                                return false;
                        }
 
                        if (IsImplementing) {
-                               Report.Error (623, Location,
+                               Report.Error (623, method.Location,
                                              "Conditional not valid on `" + member.Name + "' " +
                                              "because it is an interface method");
                                return false;
@@ -3240,31 +3689,21 @@ namespace Mono.CSharp {
                {
                        TypeManager.MethodFlags flags = 0;
 
-                       if (obsolete != null) {
-                               if (obsolete_error) {
-                                       Report.Error (619, loc, "Method `" + member.Name +
-                                                     "' is obsolete: `" + obsolete + "'");
-                                       return TypeManager.MethodFlags.IsObsoleteError;
-                               } else
-                                       Report.Warning (618, loc, "Method `" + member.Name +
-                                                       "' is obsolete: `" + obsolete + "'");
-
-                               flags |= TypeManager.MethodFlags.IsObsolete;
-                       }
-
                        if (ShouldIgnore (loc))
                                flags |= TypeManager.MethodFlags.ShouldIgnore;
 
                        return flags;
                }
 
-               public virtual bool Define (TypeContainer container)
+               public bool Define (TypeContainer container)
                {
                        MethodInfo implementing = null;
-                       string method_name, name, prefix;
+                       string prefix;
 
-                       if (OptAttributes != null)
-                               if (!ApplyAttributes (OptAttributes, is_method))
+                       EmitContext ec = method.CreateEmitContext (container, null);
+                               
+                       if (method.OptAttributes != null)
+                               if (!ApplyAttributes (method.OptAttributes, is_method, ec))
                                        return false;
 
                        if (member.IsExplicitImpl)
@@ -3272,22 +3711,20 @@ namespace Mono.CSharp {
                        else
                                prefix = "";
 
-                       if (accessor_name != null)
-                               name = accessor_name + "_" + member.ShortName;
-                       else
-                               name = member.ShortName;
-                       method_name = prefix + name;
+                       string name = method.MethodName;
+                       string method_name = prefix + name;
+                       Type[] ParameterTypes = method.ParameterTypes;
 
                        if (container.Pending != null){
                                if (member is Indexer)
                                        implementing = container.Pending.IsInterfaceIndexer (
-                                               member.InterfaceType, ReturnType, ParameterTypes);
+                                               member.InterfaceType, method.ReturnType, ParameterTypes);
                                else
                                        implementing = container.Pending.IsInterfaceMethod (
-                                               member.InterfaceType, name, ReturnType, ParameterTypes);
+                                               member.InterfaceType, name, method.ReturnType, ParameterTypes);
 
                                if (member.InterfaceType != null && implementing == null){
-                                       Report.Error (539, Location, "'{0}' in explicit interface declaration is not an interface", method_name);
+                                       Report.Error (539, method.Location, "'{0}' in explicit interface declaration is not an interface", method_name);
                                        return false;
                                }
                        }
@@ -3306,7 +3743,7 @@ namespace Mono.CSharp {
                                //
                                if (member.IsExplicitImpl){
                                        if ((modifiers & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
-                                               Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
+                                               Modifiers.Error_InvalidModifier (method.Location, "public, virtual or abstract");
                                                implementing = null;
                                        }
                                } else if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public){
@@ -3332,7 +3769,7 @@ namespace Mono.CSharp {
                                //
                                if ((modifiers & Modifiers.STATIC) != 0){
                                        implementing = null;
-                                       Modifiers.Error_InvalidModifier (Location, "static");
+                                       Modifiers.Error_InvalidModifier (method.Location, "static");
                                }
                        }
                        
@@ -3370,22 +3807,19 @@ namespace Mono.CSharp {
                        //
                        if ((flags & MethodAttributes.PinvokeImpl) != 0) {
                                if ((modifiers & Modifiers.STATIC) == 0) {
-                                       Report.Error (601, Location,
+                                       Report.Error (601, method.Location,
                                                      "The DllImport attribute must be specified on " +
                                                      "a method marked 'static' and 'extern'.");
                                        return false;
                                }
                                
-                               EmitContext ec = new EmitContext (
-                                       container, ds, Location, null, ReturnType, modifiers, false);
-                               
                                builder = dllimport_attribute.DefinePInvokeMethod (
                                        ec, container.TypeBuilder, method_name, flags,
-                                       ReturnType, ParameterTypes);
+                                       method.ReturnType, ParameterTypes);
                        } else
                                builder = container.TypeBuilder.DefineMethod (
-                                       method_name, flags, CallingConventions,
-                                       ReturnType, ParameterTypes);
+                                       method_name, flags, method.CallingConventions,
+                                       method.ReturnType, ParameterTypes);
 
                        if (builder == null)
                                return false;
@@ -3399,11 +3833,11 @@ namespace Mono.CSharp {
                                //
                                if (member is Indexer) {
                                        container.Pending.ImplementIndexer (
-                                               member.InterfaceType, builder, ReturnType,
+                                               member.InterfaceType, builder, method.ReturnType,
                                                ParameterTypes, true);
                                } else
                                        container.Pending.ImplementMethod (
-                                               member.InterfaceType, name, ReturnType,
+                                               member.InterfaceType, name, method.ReturnType,
                                                ParameterTypes, member.IsExplicitImpl);
 
                                if (member.IsExplicitImpl)
@@ -3413,7 +3847,7 @@ namespace Mono.CSharp {
                        }
 
                        if (!TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes)) {
-                               Report.Error (111, Location,
+                               Report.Error (111, method.Location,
                                              "Class `" + container.Name +
                                              "' already contains a definition with the " +
                                              "same return value and parameter types as the " +
@@ -3422,6 +3856,7 @@ namespace Mono.CSharp {
                        }
 
                        TypeManager.AddMethod (builder, this);
+                       TypeManager.AddMethod2 (builder, method);
 
                        return true;
                }
@@ -3429,28 +3864,26 @@ namespace Mono.CSharp {
                //
                // Emits the code
                // 
-               public virtual void Emit (TypeContainer container, Block block, object kind)
+               public void Emit (TypeContainer container, Attributable kind)
                {
-                       ILGenerator ig;
                        EmitContext ec;
 
                        if ((flags & MethodAttributes.PinvokeImpl) == 0)
-                               ig = builder.GetILGenerator ();
+                               ec = method.CreateEmitContext (container, builder.GetILGenerator ());
                        else
-                               ig = null;
+                               ec = method.CreateEmitContext (container, null);
 
-                       ec = new EmitContext (container, ds, Location, ig, ReturnType, modifiers, false);
+                       Location loc = method.Location;
+                       Attributes OptAttributes = method.OptAttributes;
 
                        if (OptAttributes != null)
-                               Attribute.ApplyAttributes (ec, builder, kind, OptAttributes);
+                               OptAttributes.Emit (ec, kind);
 
                        if (member is MethodCore)
-                               MethodCore.LabelParameters (ec, MethodBuilder,
-                                                            ((MethodCore) member).Parameters,
-                                                            OptAttributes,
-                                                            Location);
+                               ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder, loc);
 
                        SymbolWriter sw = CodeGen.SymbolWriter;
+                       Block block = method.Block;
                        
                        //
                        // abstract or extern methods have no bodies
@@ -3458,9 +3891,9 @@ namespace Mono.CSharp {
                        if ((modifiers & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0){
                                if (block == null) {
                                        if ((sw != null) && ((modifiers & Modifiers.EXTERN) != 0) &&
-                                           !Location.IsNull (Location) &&
-                                           (Location.SymbolDocument != null)) {
-                                               sw.OpenMethod (container, MethodBuilder, Location, Location);
+                                           !Location.IsNull (loc) &&
+                                           (method.Location.SymbolDocument != null)) {
+                                               sw.OpenMethod (container, MethodBuilder, loc, loc);
                                                sw.CloseMethod ();
                                        }
 
@@ -3472,13 +3905,13 @@ namespace Mono.CSharp {
                                //
                                if ((modifiers & Modifiers.ABSTRACT) != 0)
                                        Report.Error (
-                                               500, Location, "Abstract method `" +
+                                               500, method.Location, "Abstract method `" +
                                                TypeManager.CSharpSignature (builder) +
                                                "' can not have a body");
 
                                if ((modifiers & Modifiers.EXTERN) != 0)
                                        Report.Error (
-                                               179, Location, "External method `" +
+                                               179, method.Location, "External method `" +
                                                TypeManager.CSharpSignature (builder) +
                                                "' can not have a body");
 
@@ -3490,7 +3923,7 @@ namespace Mono.CSharp {
                        //
                        if (block == null) {
                                Report.Error (
-                                       501, Location, "Method `" +
+                                       501, method.Location, "Method `" +
                                        TypeManager.CSharpSignature (builder) +
                                        "' must declare a body since it is not marked " +
                                        "abstract or extern");
@@ -3502,22 +3935,22 @@ namespace Mono.CSharp {
                        //
                        // FIXME: This code generates buggy code
                        //
-                       if ((sw != null) && !Location.IsNull (Location) &&
+                       if ((sw != null) && !Location.IsNull (loc) &&
                            !Location.IsNull (block.EndLocation) &&
-                           (Location.SymbolDocument != null)) {
-                               sw.OpenMethod (container, MethodBuilder, Location, block.EndLocation);
+                           (loc.SymbolDocument != null)) {
+                               sw.OpenMethod (container, MethodBuilder, loc, block.EndLocation);
 
                                if (member is Destructor)
                                        EmitDestructor (ec, block);
                                else
-                                       ec.EmitTopBlock (block, ParameterInfo, Location);
+                                       ec.EmitTopBlock (block, ParameterInfo, loc);
 
                                sw.CloseMethod ();
                        } else {
                                if (member is Destructor)
                                        EmitDestructor (ec, block);
                                else
-                                       ec.EmitTopBlock (block, ParameterInfo, Location);
+                                       ec.EmitTopBlock (block, ParameterInfo, loc);
                        }
                }
 
@@ -3532,7 +3965,7 @@ namespace Mono.CSharp {
                        ig.BeginExceptionBlock ();
                        ec.ReturnLabel = finish;
                        ec.HasReturnLabel = true;
-                       ec.EmitTopBlock (block, null, Location);
+                       ec.EmitTopBlock (block, null, method.Location);
                        
                        // ig.MarkLabel (finish);
                        ig.BeginFinallyBlock ();
@@ -3540,7 +3973,7 @@ namespace Mono.CSharp {
                        if (ec.ContainerType.BaseType != null) {
                                Expression member_lookup = Expression.MemberLookup (
                                        ec, ec.ContainerType.BaseType, null, ec.ContainerType.BaseType,
-                                       "Finalize", MemberTypes.Method, Expression.AllBindingFlags, Location);
+                                       "Finalize", MemberTypes.Method, Expression.AllBindingFlags, method.Location);
 
                                if (member_lookup != null){
                                        MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
@@ -3560,7 +3993,7 @@ namespace Mono.CSharp {
 
                public Destructor (DeclSpace ds, Expression return_type, int mod, string name,
                                   Parameters parameters, Attributes attrs, Location l)
-                       : base (ds, return_type, mod, name, parameters, attrs, l)
+                       : base (ds, return_type, mod, false, name, parameters, attrs, l)
                { }
 
        }
@@ -3568,7 +4001,7 @@ namespace Mono.CSharp {
        abstract public class MemberBase : MemberCore {
                public Expression Type;
 
-               protected MethodAttributes flags;
+               public MethodAttributes flags;
                        
                protected readonly int explicit_mod_flags;
 
@@ -3593,6 +4026,11 @@ namespace Mono.CSharp {
                //
                public string ExplicitInterfaceName = null;
 
+               //
+               // Whether this is an interface member.
+               //
+               public bool IsInterface;
+
                //
                // If true, the interface type we are explicitly implementing
                //
@@ -3786,6 +4224,13 @@ namespace Mono.CSharp {
                        bool error = false;
 
                        foreach (Type partype in parameters){
+                               if (partype == TypeManager.void_type) {
+                                       Report.Error (
+                                               1547, Location, "Keyword 'void' cannot " +
+                                               "be used in this context");
+                                       return false;
+                               }
+
                                if (partype.IsPointer){
                                        if (!UnsafeOK (ds))
                                                error = true;
@@ -3822,10 +4267,22 @@ namespace Mono.CSharp {
                        if (Name == null)
                                Name = "this";
 
-                       if (!container.MethodModifiersValid (ModFlags, Name, Location))
-                               return false;
+                       if (IsInterface) {
+                               ModFlags = Modifiers.PUBLIC |
+                                       Modifiers.ABSTRACT |
+                                       Modifiers.VIRTUAL | (ModFlags & Modifiers.UNSAFE);
 
-                       flags = Modifiers.MethodAttr (ModFlags);
+                               flags = MethodAttributes.Public |
+                                       MethodAttributes.Abstract |
+                                       MethodAttributes.HideBySig |
+                                       MethodAttributes.NewSlot |
+                                       MethodAttributes.Virtual;
+                       } else {
+                               if (!container.MethodModifiersValid (ModFlags, Name, Location))
+                                       return false;
+
+                               flags = Modifiers.MethodAttr (ModFlags);
+                       }
 
                        // Lookup Type, verify validity
                        MemberType = container.ResolveType (Type, false, Location);
@@ -3909,6 +4366,25 @@ namespace Mono.CSharp {
 
                        return true;
                }
+
+               protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+               {
+                       return IsIdentifierAndParamClsCompliant (ds, Name, null, null);
+               }
+
+               protected override bool VerifyClsCompliance(DeclSpace ds)
+               {
+                       if (base.VerifyClsCompliance (ds)) {
+                               return true;
+                       }
+
+                       if (IsInterface && HasClsCompliantAttribute && ds.IsClsCompliaceRequired (ds)) {
+                               Report.Error_T (3010, Location, GetSignatureForError ());
+                       }
+                       return false;
+               }
+
+
        }
 
        //
@@ -3922,6 +4398,8 @@ namespace Mono.CSharp {
                [Flags]
                public enum Status : byte { ASSIGNED = 1, USED = 2 }
 
+               static string[] attribute_targets = new string [] { "field" };
+
                //
                // The constructor is only exposed to our children
                //
@@ -3932,6 +4410,28 @@ namespace Mono.CSharp {
                        this.init = init;
                }
 
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Field;
+                       }
+               }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.Type == TypeManager.marshal_as_attr_type) {
+                               UnmanagedMarshal marshal = a.GetMarshal ();
+                               if (marshal != null) {
+                                       FieldBuilder.SetMarshal (marshal);
+                                       return;
+                               }
+                               Report.Warning_T (-24, a.Location);
+                               return;
+                       }
+
+                       
+                       FieldBuilder.SetCustomAttribute (cb);
+               }
+
                //
                // Whether this field has an initializer.
                //
@@ -3970,6 +4470,47 @@ namespace Mono.CSharp {
                        return init_expr;
                }
 
+               protected override bool DoDefine (TypeContainer container)
+               {
+                       if (!base.DoDefine (container))
+                               return false;
+
+                       if (MemberType == TypeManager.void_type) {
+                               Report.Error (1547, Location,
+                                             "Keyword 'void' cannot be used in this context");
+                               return false;
+                       }
+
+                       return true;
+               }
+
+               public override string GetSignatureForError ()
+               {
+                       return TypeManager.GetFullNameSignature (FieldBuilder);
+               }
+
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
+
+               protected override bool VerifyClsCompliance (DeclSpace ds)
+               {
+                       if (!base.VerifyClsCompliance (ds))
+                               return false;
+
+                       if (FieldBuilder == null) {
+                               return true;
+                       }
+
+                       if (!AttributeTester.IsClsCompliant (FieldBuilder.FieldType)) {
+                               Report.Error_T (3003, Location, GetSignatureForError ());
+                       }
+                       return true;
+               }
+
+
                public void SetAssigned ()
                {
                        status |= Status.ASSIGNED;
@@ -4002,22 +4543,22 @@ namespace Mono.CSharp {
 
                public override bool Define (TypeContainer container)
                {
-                       Type t = container.ResolveType (Type, false, Location);
+                       MemberType = container.ResolveType (Type, false, Location);
                        
-                       if (t == null)
+                       if (MemberType == null)
                                return false;
 
                        CheckBase (container);
                        
-                       if (!container.AsAccessible (t, ModFlags)) {
+                       if (!container.AsAccessible (MemberType, ModFlags)) {
                                Report.Error (52, Location,
                                              "Inconsistent accessibility: field type `" +
-                                             TypeManager.CSharpName (t) + "' is less " +
+                                             TypeManager.CSharpName (MemberType) + "' is less " +
                                              "accessible than field `" + Name + "'");
                                return false;
                        }
 
-                       if (t.IsPointer && !UnsafeOK (container))
+                       if (MemberType.IsPointer && !UnsafeOK (container))
                                return false;
                        
                        if (RootContext.WarningLevel > 1){
@@ -4034,21 +4575,22 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.VOLATILE) != 0){
-                               if (!t.IsClass){
-                                       Type vt = t;
+                               if (!MemberType.IsClass){
+                                       Type vt = MemberType;
                                        
                                        if (TypeManager.IsEnumType (vt))
-                                               vt = TypeManager.EnumToUnderlying (t);
+                                               vt = TypeManager.EnumToUnderlying (MemberType);
 
                                        if (!((vt == TypeManager.bool_type) ||
                                              (vt == TypeManager.sbyte_type) ||
                                              (vt == TypeManager.byte_type) ||
-                                             (vt == TypeManager.short_type) ||    
+                                             (vt == TypeManager.short_type) ||
                                              (vt == TypeManager.ushort_type) ||
-                                             (vt == TypeManager.int32_type) ||    
+                                             (vt == TypeManager.int32_type) ||
                                              (vt == TypeManager.uint32_type) ||    
-                                             (vt == TypeManager.char_type) ||    
-                                             (vt == TypeManager.float_type))){
+                                             (vt == TypeManager.char_type) ||
+                                             (vt == TypeManager.float_type) ||
+                                             (!vt.IsValueType))){
                                                Report.Error (
                                                        677, Location, container.MakeName (Name) +
                                                        " A volatile field can not be of type `" +
@@ -4069,8 +4611,8 @@ namespace Mono.CSharp {
 
                        if (container is Struct && 
                            ((fa & FieldAttributes.Static) == 0) &&
-                           t == container.TypeBuilder &&
-                           !TypeManager.IsBuiltinType (t)){
+                           MemberType == container.TypeBuilder &&
+                           !TypeManager.IsBuiltinType (MemberType)){
                                Report.Error (523, Location, "Struct member `" + container.Name + "." + Name + 
                                              "' causes a cycle in the structure layout");
                                return false;
@@ -4078,7 +4620,7 @@ namespace Mono.CSharp {
 
                        try {
                                FieldBuilder = container.TypeBuilder.DefineField (
-                                       Name, t, Modifiers.FieldAttr (ModFlags));
+                                       Name, MemberType, Modifiers.FieldAttr (ModFlags));
 
                                TypeManager.RegisterFieldBase (FieldBuilder, this);
                        }
@@ -4090,12 +4632,14 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public void Emit (TypeContainer tc)
+               public override void Emit (TypeContainer tc)
                {
-                       EmitContext ec = new EmitContext (tc, Location, null,
-                                                         FieldBuilder.FieldType, ModFlags);
+                       if (OptAttributes != null) {
+                               EmitContext ec = new EmitContext (tc, Location, null, FieldBuilder.FieldType, ModFlags);
+                               OptAttributes.Emit (ec, this);
+                       }
 
-                       Attribute.ApplyAttributes (ec, FieldBuilder, this, OptAttributes);
+                       base.Emit (tc);
                }
        }
 
@@ -4107,12 +4651,12 @@ namespace Mono.CSharp {
                // Null if the accessor is empty, or a Block if not
                //
                public Block Block;
-               public Attributes OptAttributes;
+               public Attributes Attributes;
                
                public Accessor (Block b, Attributes attrs)
                {
                        Block = b;
-                       OptAttributes = attrs;
+                       Attributes = attrs;
                }
        }
 
@@ -4121,21 +4665,236 @@ namespace Mono.CSharp {
        // their common bits.
        //
        abstract public class PropertyBase : MethodCore {
-               public Accessor Get, Set;
+
+               public class GetMethod: PropertyMethod
+               {
+                       static string[] attribute_targets = new string [] { "method", "return" };
+
+                       public GetMethod (MethodCore method, Accessor accessor):
+                               base (method, accessor)
+                       {
+                       }
+
+                       public override MethodBuilder Define(TypeContainer container)
+                       {
+                               method_data = new MethodData (method, method.ParameterInfo, method.ModFlags, method.flags, false, this);
+
+                               if (!method_data.Define (container))
+                                       return null;
+
+                               return method_data.MethodBuilder;
+                       }
+
+                       public override string MethodName {
+                               get {
+                                       return "get_" + method.ShortName;
+                               }
+                       }
+
+                       public override Type ReturnType {
+                               get {
+                                       return method.MemberType;
+                               }
+                       }
+
+                       protected override string[] ValidAttributeTargets {
+                               get {
+                                       return attribute_targets;
+                               }
+                       }
+               }
+
+               public class SetMethod: PropertyMethod {
+
+                       static string[] attribute_targets = new string [] { "method", "param", "return" };
+                       ImplicitParameter param_attr;
+
+                       public SetMethod (MethodCore method, Accessor accessor):
+                               base (method, accessor)
+                       {
+                       }
+
+                       public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+                       {
+                               if (a.Target == "param") {
+                                       if (param_attr == null)
+                                               param_attr = new ImplicitParameter (method_data.MethodBuilder);
+
+                                       param_attr.ApplyAttributeBuilder (a, cb);
+                                       return;
+                               }
+
+                               base.ApplyAttributeBuilder (a, cb);
+                       }
+
+                       protected virtual InternalParameters GetParameterInfo (TypeContainer container)
+                       {
+                               Parameter [] parms = new Parameter [1];
+                               parms [0] = new Parameter (method.Type, "value", Parameter.Modifier.NONE, null);
+                               return new InternalParameters (
+                                       container, new Parameters (parms, null, method.Location));
+                       }
+
+                       public override MethodBuilder Define(TypeContainer container)
+                       {
+                               method_data = new MethodData (method, GetParameterInfo (container), method.ModFlags, method.flags, false, this);
+
+                               if (!method_data.Define (container))
+                                       return null;
+
+                               return method_data.MethodBuilder;
+                       }
+
+                       public override string MethodName {
+                               get {
+                                       return "set_" + method.ShortName;
+                               }
+                       }
+
+                       public override Type[] ParameterTypes {
+                               get {
+                                       return new Type[] { method.MemberType };
+                               }
+                       }
+
+                       public override Type ReturnType {
+                               get {
+                                       return TypeManager.void_type;
+                               }
+                       }
+
+                       protected override string[] ValidAttributeTargets {
+                               get {
+                                       return attribute_targets;
+                               }
+                       }
+               }
+
+
+               static string[] attribute_targets = new string [] { "property" };
+
+               public abstract class PropertyMethod: Attributable, IMethodData 
+               {
+                       protected readonly MethodCore method;
+                       protected MethodData method_data;
+                       Block block;
+
+                       ReturnParameter return_attributes;
+
+                       public PropertyMethod (MethodCore method, Accessor accessor):
+                               base (accessor.Attributes)
+                       {
+                               this.method = method;
+                               this.block = accessor.Block;
+                       }
+
+                       public override AttributeTargets AttributeTargets {
+                               get {
+                                       return AttributeTargets.Method | AttributeTargets.ReturnValue;
+                               }
+                       }
+
+
+                       public override bool IsClsCompliaceRequired(DeclSpace ds)
+                       {
+                               return method.IsClsCompliaceRequired (ds);
+                       }
+
+                       public InternalParameters ParameterInfo 
+                       {
+                               get {
+                                       return method_data.ParameterInfo;
+                               }
+                       }
+
+                       #region IMethodData Members
+
+                       public Block Block {
+                               get {
+                                       return block;
+                               }
+                       }
+
+                       public CallingConventions CallingConventions {
+                               get {
+                                       return CallingConventions.Standard;
+                               }
+                       }
+
+                       public abstract MethodBuilder Define (TypeContainer container);
+
+                       public void Emit (TypeContainer container)
+                       {
+                               method_data.Emit (container, this);
+                               block = null;
+                       }
+
+                       public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+                       {
+                               if (a.Target == "return") {
+                                       if (return_attributes == null)
+                                               return_attributes = new ReturnParameter (method_data.MethodBuilder, Location);
+
+                                       return_attributes.ApplyAttributeBuilder (a, cb);
+                                       return;
+                               }
+
+                               method_data.MethodBuilder.SetCustomAttribute (cb);
+                       }
+
+                       public virtual Type[] ParameterTypes {
+                               get {
+                                       return TypeManager.NoTypes;
+                               }
+                       }
+
+                       public abstract Type ReturnType { get; }
+
+                       public Location Location {
+                               get {
+                                       return method.Location;
+                               }
+                       }
+
+                       public abstract string MethodName { get; }
+
+                       public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+                       {
+                               return new EmitContext (tc, method.ds, method.Location, ig, ReturnType, method.ModFlags, false);
+                       }
+
+                       public ObsoleteAttribute GetObsoleteAttribute ()
+                       {
+                               return method.GetObsoleteAttribute (method.ds);
+                       }
+                       #endregion
+               }
+
+
+               public PropertyMethod Get, Set;
                public PropertyBuilder PropertyBuilder;
                public MethodBuilder GetBuilder, SetBuilder;
-               public MethodData GetData, SetData;
 
                protected EmitContext ec;
 
-               public PropertyBase (DeclSpace ds, Expression type, string name, int mod_flags,
-                                    int allowed_mod, Parameters parameters,
-                                    Accessor get_block, Accessor set_block,
-                                    Attributes attrs, Location loc)
-                       : base (ds, type, mod_flags, allowed_mod, name, attrs, parameters, loc)
+               public PropertyBase (DeclSpace ds, Expression type, int mod_flags,
+                                    int allowed_mod, bool is_iface, string name,
+                                    Parameters parameters, Attributes attrs,
+                                    Location loc)
+                       : base (ds, type, mod_flags, allowed_mod, is_iface, name,
+                               attrs, parameters, loc)
+               {
+               }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
-                       Get = get_block;
-                       Set = set_block;
+                       PropertyBuilder.SetCustomAttribute (cb);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Property;
+                       }
                }
 
                protected override bool DoDefine (TypeContainer container)
@@ -4148,6 +4907,32 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               public override string GetSignatureForError()
+               {
+                       return TypeManager.CSharpSignature (PropertyBuilder, false);
+               }
+
+               protected virtual string RealMethodName {
+                       get {
+                               return Name;
+                       }
+               }
+
+               protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+               {
+                       if (!IsIdentifierAndParamClsCompliant (ds, RealMethodName, null, null))
+                               return false;
+
+                       if (Get != null && !IsIdentifierAndParamClsCompliant (ds, "get_" + RealMethodName, null, null))
+                               return false;
+
+                       if (Set != null && !IsIdentifierAndParamClsCompliant (ds, "set_" + RealMethodName, null, null))
+                               return false;
+
+                       return true;
+               }
+
+
                //
                // Checks our base implementation if any
                //
@@ -4162,6 +4947,23 @@ namespace Mono.CSharp {
                        if (IsExplicitImpl)
                                return true;
 
+                       //
+                       // Check in our class for dups
+                       //
+                       ArrayList ar = container.Properties;
+                       if (ar != null) {
+                               int arLen = ar.Count;
+                                       
+                               for (int i = 0; i < arLen; i++) {
+                                       Property m = (Property) ar [i];
+                                       if (IsDuplicateImplementation (container, m))
+                                               return false;
+                               }
+                       }
+
+                       if (IsInterface)
+                               return true;
+
                        string report_name;
                        MethodSignature ms, base_ms;
                        if (this is Indexer) {
@@ -4191,32 +4993,21 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       MemberList props_this;
-
-                       props_this = TypeContainer.FindMembers (
-                               container.TypeBuilder, MemberTypes.Property,
-                               BindingFlags.NonPublic | BindingFlags.Public |
-                               BindingFlags.Static | BindingFlags.Instance |
-                               BindingFlags.DeclaredOnly,
-                               MethodSignature.method_signature_filter, ms);
-
-                       if (props_this.Count > 0) {
-                               Report.Error (111, Location, "Class `" + container.Name + "' " +
-                                             "already defines a member called `" + report_name + "' " +
-                                             "with the same parameter types");
-                               return false;
+                       MemberInfo parent_member = null;
+                       
+                       //
+                       // Explicit implementations do not have `parent' methods, however,
+                       // the member cache stores them there. Without this check, we get
+                       // an incorrect warning in corlib.
+                       //
+                       if (! IsExplicitImpl) {
+                               parent_member = ((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
+                                       container.TypeBuilder, Name, ParameterTypes, true);
                        }
 
-                       MemberList mi_props;
+                       if (parent_member is PropertyInfo) {
+                               PropertyInfo parent_property = (PropertyInfo)parent_member;
 
-                       mi_props = TypeContainer.FindMembers (
-                               ptype, MemberTypes.Property,
-                               BindingFlags.NonPublic | BindingFlags.Public |
-                               BindingFlags.Instance | BindingFlags.Static,
-                               MethodSignature.inheritable_method_signature_filter, base_ms);
-
-                       if (mi_props.Count > 0){
-                               PropertyInfo parent_property = (PropertyInfo) mi_props [0];
                                string name = parent_property.DeclaringType.Name + "." +
                                        parent_property.Name;
 
@@ -4246,7 +5037,7 @@ namespace Mono.CSharp {
                                                return false;
                                        }
                                }
-                       } else {
+                       } else if (parent_member == null){
                                if ((ModFlags & Modifiers.NEW) != 0)
                                        WarningNotHiding (container);
 
@@ -4265,24 +5056,28 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public void Emit (TypeContainer tc)
+               public override void Emit (TypeContainer tc)
                {
                        //
                        // The PropertyBuilder can be null for explicit implementations, in that
                        // case, we do not actually emit the ".property", so there is nowhere to
                        // put the attribute
                        //
-                       if (PropertyBuilder != null)
-                               Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes);
+                       if (PropertyBuilder != null && OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
 
-                       if (GetData != null) {
-                               GetData.Emit (tc, Get.Block, Get);
-                               Get.Block = null;
-                       }
+                       if (Get != null)
+                               Get.Emit (tc);
+
+                       if (Set != null)
+                               Set.Emit (tc);
+
+                       base.Emit (tc);
+               }
 
-                       if (SetData != null) {
-                               SetData.Emit (tc, Set.Block, Set);
-                               Set.Block = null;
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
                        }
                }
        }
@@ -4303,13 +5098,22 @@ namespace Mono.CSharp {
                        Modifiers.METHOD_YIELDS |
                        Modifiers.VIRTUAL;
 
-               public Property (DeclSpace ds, Expression type, string name, int mod_flags,
-                                Accessor get_block, Accessor set_block,
-                                Attributes attrs, Location loc)
-                       : base (ds, type, name, mod_flags, AllowedModifiers,
-                               Parameters.EmptyReadOnlyParameters,
-                               get_block, set_block, attrs, loc)
+               const int AllowedInterfaceModifiers =
+                       Modifiers.NEW;
+
+               public Property (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
+                                string name, Attributes attrs, Accessor get_block,
+                                Accessor set_block, Location loc)
+                       : base (ds, type, mod_flags,
+                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+                               is_iface, name, Parameters.EmptyReadOnlyParameters, attrs,
+                               loc)
                {
+                       if (get_block != null)
+                               Get = new GetMethod (this, get_block);
+
+                       if (set_block != null)
+                               Set = new SetMethod (this, set_block);
                }
 
                public override bool Define (TypeContainer container)
@@ -4323,14 +5127,10 @@ namespace Mono.CSharp {
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
                        if (Get != null) {
-                               Type [] parameters = TypeManager.NoTypes;
-
-                               InternalParameters ip = new InternalParameters (
-                                       container, Parameters.EmptyReadOnlyParameters);
 
-                               GetData = new MethodData (container, this, "get", MemberType,
-                                                         parameters, ip, CallingConventions.Standard,
-                                                         Get.OptAttributes, ModFlags, flags, false);
+                               GetBuilder = Get.Define (container);
+                               if (GetBuilder == null)
+                                       return false;
 
                                //
                                // Setup iterator if we are one
@@ -4338,45 +5138,29 @@ namespace Mono.CSharp {
                                if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
                                        IteratorHandler ih = new  IteratorHandler (
                                                                                   "get", container, MemberType,
-                                                                                  parameters, ip, ModFlags, Location);
+                                                                                  TypeManager.NoTypes, Get.ParameterInfo, ModFlags, Location);
                                        
                                        Block new_block = ih.Setup (block);
                                        if (new_block == null)
                                                return false;
                                        block = new_block;
                                }
-                               
-                               if (!GetData.Define (container))
-                                       return false;
-
-                               GetBuilder = GetData.MethodBuilder;
                        }
 
                        if (Set != null) {
-                               Type [] parameters = new Type [1];
-                               parameters [0] = MemberType;
-
-                               Parameter [] parms = new Parameter [1];
-                               parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
-                               InternalParameters ip = new InternalParameters (
-                                       container, new Parameters (parms, null, Location));
-
-                               SetData = new MethodData (container, this, "set", TypeManager.void_type,
-                                                         parameters, ip, CallingConventions.Standard,
-                                                         Set.OptAttributes, ModFlags, flags, false);
-
-                               if (!SetData.Define (container))
+                               SetBuilder = Set.Define (container);
+                               if (SetBuilder == null)
                                        return false;
 
-                               SetBuilder = SetData.MethodBuilder;
                                SetBuilder.DefineParameter (1, ParameterAttributes.None, "value"); 
                        }
 
                        // FIXME - PropertyAttributes.HasDefault ?
                        
-                       PropertyAttributes prop_attr =
-                       PropertyAttributes.RTSpecialName |
-                       PropertyAttributes.SpecialName;
+                       PropertyAttributes prop_attr = PropertyAttributes.None;
+                       if (!IsInterface)
+                               prop_attr |= PropertyAttributes.RTSpecialName |
+                                       PropertyAttributes.SpecialName;
 
                        if (!IsExplicitImpl){
                                PropertyBuilder = container.TypeBuilder.DefineProperty (
@@ -4480,80 +5264,347 @@ namespace Mono.CSharp {
                        MyBuilder.SetRaiseMethod (raiseMethod);
                }
 
-               public void SetRemoveOnMethod (MethodBuilder removeMethod)
-               {
-                       remove = removeMethod;
-                       MyBuilder.SetRemoveOnMethod (removeMethod);
-               }
+               public void SetRemoveOnMethod (MethodBuilder removeMethod)
+               {
+                       remove = removeMethod;
+                       MyBuilder.SetRemoveOnMethod (removeMethod);
+               }
+
+               public void SetAddOnMethod (MethodBuilder addMethod)
+               {
+                       add = addMethod;
+                       MyBuilder.SetAddOnMethod (addMethod);
+               }
+
+               public void SetCustomAttribute (CustomAttributeBuilder cb)
+               {
+                       MyBuilder.SetCustomAttribute (cb);
+               }
+               
+               public override object [] GetCustomAttributes (bool inherit)
+               {
+                       // FIXME : There's nothing which can be seemingly done here because
+                       // we have no way of getting at the custom attribute objects of the
+                       // EventBuilder !
+                       return null;
+               }
+
+               public override object [] GetCustomAttributes (Type t, bool inherit)
+               {
+                       // FIXME : Same here !
+                       return null;
+               }
+
+               public override bool IsDefined (Type t, bool b)
+               {
+                       return true;
+               }
+
+               public override EventAttributes Attributes {
+                       get {
+                               return attributes;
+                       }
+               }
+
+               public override string Name {
+                       get {
+                               return name;
+                       }
+               }
+
+               public override Type DeclaringType {
+                       get {
+                               return declaring_type;
+                       }
+               }
+
+               public override Type ReflectedType {
+                       get {
+                               return reflected_type;
+                       }
+               }
+
+               public Type EventType {
+                       get {
+                               return event_type;
+                       }
+               }
+               
+               public void SetUsed ()
+               {
+                       if (my_event != null)
+                               my_event.status = (FieldBase.Status.ASSIGNED | FieldBase.Status.USED);
+               }
+       }
+       
+       /// <summary>
+       /// For case when event is declared like property (with add and remove accessors).
+       /// </summary>
+       public class EventProperty: Event {
+
+               static string[] attribute_targets = new string [] { "event", "property" };
+
+               public EventProperty (DeclSpace ds, Expression type, int mod_flags, bool is_iface, string name,
+                       Object init, Attributes attrs, Accessor add, Accessor remove, Location loc)
+                       : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+               {
+                       Add = new AddDelegateMethod (this, add);
+                       Remove = new RemoveDelegateMethod (this, remove);
+               }
+
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
+       }
+
+       /// <summary>
+       /// Event is declared like field.
+       /// </summary>
+       public class EventField: Event {
+
+               static string[] attribute_targets = new string [] { "method", "field", "event" };
+
+               public EventField (DeclSpace ds, Expression type, int mod_flags, bool is_iface, string name,
+                       Object init, Attributes attrs, Location loc)
+                       : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+               {
+                       Add = new AddDelegateMethod (this);
+                       Remove = new RemoveDelegateMethod (this);
+               }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.Target == "field") {
+                               FieldBuilder.SetCustomAttribute (cb);
+                               return;
+                       }
+
+                       if (a.Target == "method") {
+                               AddBuilder.SetCustomAttribute (cb);
+                               RemoveBuilder.SetCustomAttribute (cb);
+                               return;
+                       }
+
+                       base.ApplyAttributeBuilder (a, cb);
+               }
+
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
+       }
+
+       public abstract class Event : FieldBase {
+
+               protected sealed class AddDelegateMethod: DelegateMethod
+               {
+                       public AddDelegateMethod (Event method):
+                               base (method)
+                       {
+                       }
+
+                       public AddDelegateMethod (Event method, Accessor accessor):
+                               base (method, accessor)
+                       {
+                       }
+
+                       public override string MethodName {
+                               get {
+                                       return "add_" + method.ShortName;
+                               }
+                       }
+
+                       protected override MethodInfo DelegateMethodInfo {
+                               get {
+                                       return TypeManager.delegate_combine_delegate_delegate;
+                               }
+                       }
+
+               }
+
+               protected sealed class RemoveDelegateMethod: DelegateMethod
+               {
+                       public RemoveDelegateMethod (Event method):
+                               base (method)
+                       {
+                       }
+
+                       public RemoveDelegateMethod (Event method, Accessor accessor):
+                               base (method, accessor)
+                       {
+                       }
+
+                       public override string MethodName {
+                               get {
+                                       return "remove_" + method.ShortName;
+                               }
+                       }
+
+                       protected override MethodInfo DelegateMethodInfo {
+                               get {
+                                       return TypeManager.delegate_remove_delegate_delegate;
+                               }
+                       }
+
+               }
+
+               public abstract class DelegateMethod: Attributable, IMethodData
+               {
+                       protected readonly Event method;
+                       protected MethodData method_data;
+                       Block block;
+                       ReturnParameter return_attributes;
+                       ImplicitParameter param_attr;
+
+                       static string[] attribute_targets = new string [] { "method", "param", "return" };
+
+                       public DelegateMethod (Event method):
+                               base (null)
+                       {
+                               this.method = method;
+                       }
+
+                       public DelegateMethod (Event method, Accessor accessor):
+                               base (accessor.Attributes)
+                       {
+                               this.method = method;
+                               this.block = accessor.Block;
+                       }
+
+                       public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+                       {
+                               if (a.Target == "return") {
+                                       if (return_attributes == null)
+                                               return_attributes = new ReturnParameter (method_data.MethodBuilder, Location);
+
+                                       return_attributes.ApplyAttributeBuilder (a, cb);
+                                       return;
+                               }
+
+                               if (a.Target == "param") {
+                                       if (param_attr == null)
+                                               param_attr = new ImplicitParameter (method_data.MethodBuilder);
+
+                                       param_attr.ApplyAttributeBuilder (a, cb);
+                                       return;
+                               }
+
+                               method_data.MethodBuilder.SetCustomAttribute (cb);
+                       }
+
+                       public override AttributeTargets AttributeTargets {
+                               get {
+                                       return AttributeTargets.Method;
+                               }
+                       }
+
+                       public override bool IsClsCompliaceRequired(DeclSpace ds)
+                       {
+                               return method.IsClsCompliaceRequired (ds);
+                       }
+
+                       public MethodBuilder Define (TypeContainer container, InternalParameters ip)
+                       {
+                               method_data = new MethodData (method, ip, method.ModFlags,
+                                       method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, false, this);
 
-               public void SetAddOnMethod (MethodBuilder addMethod)
-               {
-                       add = addMethod;
-                       MyBuilder.SetAddOnMethod (addMethod);
-               }
+                               if (!method_data.Define (container))
+                                       return null;
 
-               public void SetCustomAttribute (CustomAttributeBuilder cb)
-               {
-                       MyBuilder.SetCustomAttribute (cb);
-               }
-               
-               public override object [] GetCustomAttributes (bool inherit)
-               {
-                       // FIXME : There's nothing which can be seemingly done here because
-                       // we have no way of getting at the custom attribute objects of the
-                       // EventBuilder !
-                       return null;
-               }
+                               MethodBuilder mb = method_data.MethodBuilder;
+                               mb.DefineParameter (1, ParameterAttributes.None, "value");
+                               return mb;
+                       }
 
-               public override object [] GetCustomAttributes (Type t, bool inherit)
-               {
-                       // FIXME : Same here !
-                       return null;
-               }
+                       #region IMethodData Members
 
-               public override bool IsDefined (Type t, bool b)
-               {
-                       return true;
-               }
+                       public Block Block {
+                               get {
+                                       return block;
+                               }
+                       }
 
-               public override EventAttributes Attributes {
-                       get {
-                               return attributes;
+                       public CallingConventions CallingConventions {
+                               get {
+                                       return CallingConventions.Standard;
+                               }
                        }
-               }
 
-               public override string Name {
-                       get {
-                               return name;
+                       public void Emit (TypeContainer tc)
+                       {
+                               if (block != null) {
+                                       method_data.Emit (tc, this);
+                                       block = null;
+                                       return;
+                               }
+
+                               ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
+                               EmitContext ec = CreateEmitContext (tc, ig);
+                               FieldInfo field_info = (FieldInfo)method.FieldBuilder;
+
+                               if ((method.ModFlags & Modifiers.STATIC) != 0) {
+                                       ig.Emit (OpCodes.Ldsfld, field_info);
+                                       ig.Emit (OpCodes.Ldarg_0);
+                                       ig.Emit (OpCodes.Call, DelegateMethodInfo);
+                                       ig.Emit (OpCodes.Castclass, method.MemberType);
+                                       ig.Emit (OpCodes.Stsfld, field_info);
+                               } else {
+                                       ig.Emit (OpCodes.Ldarg_0);
+                                       ig.Emit (OpCodes.Ldarg_0);
+                                       ig.Emit (OpCodes.Ldfld, field_info);
+                                       ig.Emit (OpCodes.Ldarg_1);
+                                       ig.Emit (OpCodes.Call, DelegateMethodInfo);
+                                       ig.Emit (OpCodes.Castclass, method.MemberType);
+                                       ig.Emit (OpCodes.Stfld, field_info);
+                               }
+                               ig.Emit (OpCodes.Ret);
                        }
-               }
 
-               public override Type DeclaringType {
-                       get {
-                               return declaring_type;
+                       protected abstract MethodInfo DelegateMethodInfo { get; }
+
+                       public Type[] ParameterTypes {
+                               get {
+                                       return new Type[] { method.MemberType };
+                               }
                        }
-               }
 
-               public override Type ReflectedType {
-                       get {
-                               return reflected_type;
+                       public Type ReturnType {
+                               get {
+                                       return TypeManager.void_type;
+                               }
                        }
-               }
 
-               public Type EventType {
-                       get {
-                               return event_type;
+                       public Location Location {
+                               get {
+                                       return method.Location;
+                               }
+                       }
+
+                       public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+                       {
+                               return new EmitContext (tc, method.ds, Location, ig, ReturnType, method.ModFlags, false);
+                       }
+
+                       public ObsoleteAttribute GetObsoleteAttribute ()
+                       {
+                               return method.GetObsoleteAttribute (method.ds);
+                       }
+
+                       public abstract string MethodName { get; }
+
+                       #endregion
+
+                       protected override string[] ValidAttributeTargets {
+                               get {
+                                       return attribute_targets;
+                               }
                        }
                }
-               
-               public void SetUsed ()
-               {
-                       if (my_event != null)
-                               my_event.status = (FieldBase.Status.ASSIGNED | FieldBase.Status.USED);
-               }
-       }
-       
-       public class Event : FieldBase {
+
+
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -4567,26 +5618,43 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.ABSTRACT;
 
-               public readonly Accessor  Add;
-               public readonly Accessor  Remove;
+               const int AllowedInterfaceModifiers =
+                       Modifiers.NEW;
+
+               protected DelegateMethod Add, Remove;
                public MyEventBuilder     EventBuilder;
+               public MethodBuilder AddBuilder, RemoveBuilder;
+               public DeclSpace ds;
 
-               MethodBuilder AddBuilder, RemoveBuilder;
-               MethodData AddData, RemoveData;
-               
-               public Event (Expression type, string name, Object init, int mod, Accessor add,
-                             Accessor remove, Attributes attrs, Location loc)
-                       : base (type, mod, AllowedModifiers, name, init, attrs, loc)
+               public Event (DeclSpace ds, Expression type, int mod_flags, bool is_iface, string name,
+                               Object init, Attributes attrs, Location loc)
+                       : base (type, mod_flags, is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+                               name, init, attrs, loc)
+               {
+                       IsInterface = is_iface;
+                       this.ds = ds;
+               }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
-                       Add = add;
-                       Remove = remove;
+                       EventBuilder.SetCustomAttribute (cb);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Event;
+                       }
                }
 
                public override bool Define (TypeContainer container)
                {
-                       EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
-                       MethodAttributes m_attr = MethodAttributes.HideBySig | MethodAttributes.SpecialName
-;
+                       EventAttributes e_attr;
+                       if (IsInterface)
+                               e_attr = EventAttributes.None;
+                       else
+                               e_attr = EventAttributes.RTSpecialName |
+                                       EventAttributes.SpecialName;
+
                        if (!DoDefine (container))
                                return false;
 
@@ -4602,9 +5670,6 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       Type [] parameter_types = new Type [1];
-                       parameter_types [0] = MemberType;
-
                        Parameter [] parms = new Parameter [1];
                        parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
                        InternalParameters ip = new InternalParameters (
@@ -4616,33 +5681,21 @@ namespace Mono.CSharp {
                        //
                        // Now define the accessors
                        //
-                       AddData = new MethodData (container, this, "add", TypeManager.void_type,
-                                                 parameter_types, ip, CallingConventions.Standard,
-                                                 (Add != null) ? Add.OptAttributes : null,
-                                                 ModFlags, flags | m_attr, false);
 
-                       if (!AddData.Define (container))
+                       AddBuilder = Add.Define (container, ip);
+                       if (AddBuilder == null)
                                return false;
 
-                       AddBuilder = AddData.MethodBuilder;
-                       AddBuilder.DefineParameter (1, ParameterAttributes.None, "value");
-
-                       RemoveData = new MethodData (container, this, "remove", TypeManager.void_type,
-                                                    parameter_types, ip, CallingConventions.Standard,
-                                                    (Remove != null) ? Remove.OptAttributes : null,
-                                                    ModFlags, flags | m_attr, false);
-
-                       if (!RemoveData.Define (container))
+                       RemoveBuilder = Remove.Define (container, ip);
+                       if (RemoveBuilder == null)
                                return false;
 
-                       RemoveBuilder = RemoveData.MethodBuilder;
-                       RemoveBuilder.DefineParameter (1, ParameterAttributes.None, "value");
-
                        if (!IsExplicitImpl){
                                EventBuilder = new MyEventBuilder (this,
                                        container.TypeBuilder, Name, e_attr, MemberType);
                                        
-                               if (Add == null && Remove == null) {
+                               if (Add.Block == null && Remove.Block == null &&
+                                   !IsInterface) {
                                        FieldBuilder = container.TypeBuilder.DefineField (
                                                Name, MemberType,
                                                FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
@@ -4666,60 +5719,20 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               void EmitDefaultMethod (EmitContext ec, bool is_add)
+               public override void Emit (TypeContainer tc)
                {
-                       ILGenerator ig = ec.ig;
-                       MethodInfo method = null;
-                       
-                       if (is_add)
-                               method = TypeManager.delegate_combine_delegate_delegate;
-                       else
-                               method = TypeManager.delegate_remove_delegate_delegate;
-
-                       if ((ModFlags & Modifiers.STATIC) != 0) {
-                               ig.Emit (OpCodes.Ldsfld, (FieldInfo) FieldBuilder);
-                               ig.Emit (OpCodes.Ldarg_0);
-                               ig.Emit (OpCodes.Call, method);
-                               ig.Emit (OpCodes.Castclass, MemberType);
-                               ig.Emit (OpCodes.Stsfld, (FieldInfo) FieldBuilder);
-                       } else {
-                               ig.Emit (OpCodes.Ldarg_0);
-                               ig.Emit (OpCodes.Ldarg_0);
-                               ig.Emit (OpCodes.Ldfld, (FieldInfo) FieldBuilder);
-                               ig.Emit (OpCodes.Ldarg_1);
-                               ig.Emit (OpCodes.Call, method);
-                               ig.Emit (OpCodes.Castclass, MemberType);
-                               ig.Emit (OpCodes.Stfld, (FieldInfo) FieldBuilder);
+                       if (OptAttributes != null) {
+                               EmitContext ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
+                               OptAttributes.Emit (ec, this);
                        }
-                       ig.Emit (OpCodes.Ret);
-               }
-
-               public void Emit (TypeContainer tc)
-               {
-                       EmitContext ec;
 
-                       ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
-                       Attribute.ApplyAttributes (ec, EventBuilder, this, OptAttributes);
-
-                       if (Add != null) {
-                               AddData.Emit (tc, Add.Block, Add);
-                               Add.Block = null;
-                       } else {
-                               ILGenerator ig = AddData.MethodBuilder.GetILGenerator ();
-                               ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
-                               EmitDefaultMethod (ec, true);
+                       if (!IsInterface) {
+                               Add.Emit (tc);
+                               Remove.Emit (tc);
                        }
 
-                       if (Remove != null) {
-                               RemoveData.Emit (tc, Remove.Block, Remove);
-                               Remove.Block = null;
-                       } else {
-                               ILGenerator ig = RemoveData.MethodBuilder.GetILGenerator ();
-                               ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
-                               EmitDefaultMethod (ec, false);
-                       }
+                       base.Emit (tc);
                }
-               
        }
 
        //
@@ -4734,6 +5747,74 @@ namespace Mono.CSharp {
  
        public class Indexer : PropertyBase {
 
+               class GetIndexerMethod: GetMethod
+               {
+                       public GetIndexerMethod (MethodCore method, Accessor accessor):
+                               base (method, accessor)
+                       {
+                       }
+
+                       public override Type[] ParameterTypes {
+                               get {
+                                       return method.ParameterTypes;
+                               }
+                       }
+               }
+
+               class SetIndexerMethod: SetMethod
+               {
+                       readonly Parameters parameters;
+
+                       public SetIndexerMethod (MethodCore method, Parameters parameters, Accessor accessor):
+                               base (method, accessor)
+                       {
+                               this.parameters = parameters;
+                       }
+
+                       public override Type[] ParameterTypes {
+                               get {
+                                       int top = method.ParameterTypes.Length;
+                                       Type [] set_pars = new Type [top + 1];
+                                       method.ParameterTypes.CopyTo (set_pars, 0);
+                                       set_pars [top] = method.MemberType;
+                                       return set_pars;
+                               }
+                       }
+
+                       protected override InternalParameters GetParameterInfo (TypeContainer container)
+                       {
+                               Parameter [] fixed_parms = parameters.FixedParameters;
+
+                               if (fixed_parms == null){
+                                       throw new Exception ("We currently do not support only array arguments in an indexer at: " + method.Location);
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       //
+                                       // Here is the problem: the `value' parameter has
+                                       // to come *after* the array parameter in the declaration
+                                       // like this:
+                                       // X (object [] x, Type value)
+                                       // .param [0]
+                                       //
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       
+                               }
+                               
+                               Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
+
+                               fixed_parms.CopyTo (tmp, 0);
+                               tmp [fixed_parms.Length] = new Parameter (
+                                       method.Type, "value", Parameter.Modifier.NONE, null);
+
+                               Parameters set_formal_params = new Parameters (tmp, null, method.Location);
+                               
+                               return new InternalParameters (container, set_formal_params);
+                       }
+
+               }
+
+
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -4747,21 +5828,31 @@ namespace Mono.CSharp {
                        Modifiers.EXTERN |
                        Modifiers.ABSTRACT;
 
+               const int AllowedInterfaceModifiers =
+                       Modifiers.NEW;
+
                public string IndexerName;
                public string InterfaceIndexerName;
 
                //
                // Are we implementing an interface ?
                //
-               public Indexer (DeclSpace ds, Expression type, string int_type, int flags,
-                               Parameters parameters, Accessor get_block, Accessor set_block,
-                               Attributes attrs, Location loc)
-                       : base (ds, type, "", flags, AllowedModifiers, parameters, get_block, set_block,
-                               attrs, loc)
+               public Indexer (DeclSpace ds, Expression type, string int_type, int mod_flags,
+                               bool is_iface, Parameters parameters, Attributes attrs,
+                               Accessor get_block, Accessor set_block, Location loc)
+                       : base (ds, type, mod_flags,
+                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+                               is_iface, "", parameters, attrs, loc)
                {
                        ExplicitInterfaceName = int_type;
-               }
 
+                       if (get_block != null)
+                               Get = new GetIndexerMethod (this, get_block);
+
+                       if (set_block != null)
+                               Set = new SetIndexerMethod (this, parameters, set_block);
+               }
+                      
                public override bool Define (TypeContainer container)
                {
                        PropertyAttributes prop_attr =
@@ -4771,13 +5862,23 @@ namespace Mono.CSharp {
                        if (!DoDefine (container))
                                return false;
 
-                       IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
+                       if (OptAttributes != null)
+                               IndexerName = OptAttributes.ScanForIndexerName (ec);
+
                        if (IndexerName == null)
                                IndexerName = "Item";
-                       else if (IsExplicitImpl)
-                               Report.Error (592, Location,
-                                             "Attribute 'IndexerName' is not valid on this declaration " +
-                                             "type. It is valid on `property' declarations only.");
+                       else {
+                               if (! Tokenizer.IsValidIdentifier (IndexerName)) {
+                                       Report.Error (633, Location, "The IndexerName specified is an invalid identifier");
+                                       return false;
+                               }
+                               
+                               if (IsExplicitImpl) {
+                                       Report.Error (592, Location,
+                                                     "Attribute 'IndexerName' is not valid on explicit implementations.");
+                                       return false;
+                               }
+                       }
 
                        ShortName = IndexerName;
                        if (IsExplicitImpl) {
@@ -4796,61 +5897,15 @@ namespace Mono.CSharp {
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
                        if (Get != null){
-                                InternalParameters ip = new InternalParameters (container, Parameters);
-
-                               GetData = new MethodData (container, this, "get", MemberType,
-                                                         ParameterTypes, ip, CallingConventions.Standard,
-                                                         Get.OptAttributes, ModFlags, flags, false);
-
-                               if (!GetData.Define (container))
+                               GetBuilder = Get.Define (container);
+                               if (GetBuilder == null)
                                        return false;
-
-                               GetBuilder = GetData.MethodBuilder;
                        }
                        
                        if (Set != null){
-                               int top = ParameterTypes.Length;
-                               Type [] set_pars = new Type [top + 1];
-                               ParameterTypes.CopyTo (set_pars, 0);
-                               set_pars [top] = MemberType;
-
-                               Parameter [] fixed_parms = Parameters.FixedParameters;
-
-                               if (fixed_parms == null){
-                                       throw new Exception ("We currently do not support only array arguments in an indexer at: " + Location);
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       //
-                                       // Here is the problem: the `value' parameter has
-                                       // to come *after* the array parameter in the declaration
-                                       // like this:
-                                       // X (object [] x, Type value)
-                                       // .param [0]
-                                       //
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       
-                               }
-                               
-                               Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
-
-
-                               fixed_parms.CopyTo (tmp, 0);
-                               tmp [fixed_parms.Length] = new Parameter (
-                                       Type, "value", Parameter.Modifier.NONE, null);
-
-                               Parameters set_formal_params = new Parameters (tmp, null, Location);
-                               
-                               InternalParameters ip = new InternalParameters (container, set_formal_params);
-
-                               SetData = new MethodData (container, this, "set", TypeManager.void_type,
-                                                         set_pars, ip, CallingConventions.Standard,
-                                                         Set.OptAttributes, ModFlags, flags, false);
-
-                               if (!SetData.Define (container))
+                               SetBuilder = Set.Define (container);
+                               if (SetBuilder == null)
                                        return false;
-
-                               SetBuilder = SetData.MethodBuilder;
                        }
 
                        //
@@ -4892,10 +5947,10 @@ namespace Mono.CSharp {
                                PropertyBuilder = container.TypeBuilder.DefineProperty (
                                        IndexerName, prop_attr, MemberType, ParameterTypes);
 
-                               if (GetData != null)
+                               if (Get != null)
                                        PropertyBuilder.SetGetMethod (GetBuilder);
 
-                               if (SetData != null)
+                               if (Set != null)
                                        PropertyBuilder.SetSetMethod (SetBuilder);
                                
                                TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder,
@@ -4945,9 +6000,16 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override string GetSignatureForError () {
+               public override string GetSignatureForError ()
+               {
                        return TypeManager.CSharpSignature (PropertyBuilder, true);
                }
+
+               protected override string RealMethodName {
+                       get {
+                               return IndexerName;
+                       }
+               }
        }
 
        public class Operator : MemberBase, IIteratorContainer {
@@ -5010,6 +6072,8 @@ namespace Mono.CSharp {
                public string MethodName;
                public Method OperatorMethod;
 
+               static string[] attribute_targets = new string [] { "method", "return" };
+
                public Operator (OpType type, Expression ret_type, int mod_flags,
                                 Expression arg1type, string arg1name,
                                 Expression arg2type, string arg2name,
@@ -5031,6 +6095,17 @@ namespace Mono.CSharp {
                        return container.Name + ".operator " + OperatorType + " (" + FirstArgType + "," +
                                SecondArgType + ")";
                }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb) 
+               {
+                       OperatorMethod.ApplyAttributeBuilder (a, cb);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Method; 
+                       }
+               }
                
                public override bool Define (TypeContainer container)
                {
@@ -5057,9 +6132,10 @@ namespace Mono.CSharp {
                                param_list[1] = new Parameter (SecondArgType, SecondArgName,
                                                               Parameter.Modifier.NONE, null);
                        
-                       OperatorMethod = new Method (container, ReturnType, ModFlags, MethodName,
-                                                    new Parameters (param_list, null, Location),
-                                                    OptAttributes, Location);
+                       OperatorMethod = new Method (
+                               container, ReturnType, ModFlags, false, MethodName,
+                               new Parameters (param_list, null, Location),
+                               OptAttributes, Location);
 
                        OperatorMethod.Block = Block;
                        OperatorMethod.IsOperator = true;                       
@@ -5168,7 +6244,7 @@ namespace Mono.CSharp {
                        return true;
                }
                
-               public void Emit (TypeContainer container)
+               public override void Emit (TypeContainer container)
                {
                        //
                        // abstract or extern methods have no bodies
@@ -5258,6 +6334,12 @@ namespace Mono.CSharp {
                                        param_types [0], param_types [1]);
                }
 
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
+
                public void SetYields ()
                {
                        ModFlags |= Modifiers.METHOD_YIELDS;
@@ -5276,22 +6358,7 @@ namespace Mono.CSharp {
                ///    This delegate is used to extract methods which have the
                ///    same signature as the argument
                /// </summary>
-               public static MemberFilter method_signature_filter;
-
-               /// <summary>
-               ///   This delegate is used to extract inheritable methods which
-               ///   have the same signature as the argument.  By inheritable,
-               ///   this means that we have permissions to override the method
-               ///   from the current assembly and class
-               /// </summary>
-               public static MemberFilter inheritable_method_signature_filter;
-
-               static MethodSignature ()
-               {
-                       method_signature_filter = new MemberFilter (MemberSignatureCompare);
-                       inheritable_method_signature_filter = new MemberFilter (
-                               InheritableMemberSignatureCompare);
-               }
+               public static MemberFilter method_signature_filter = new MemberFilter (MemberSignatureCompare);
                
                public MethodSignature (string name, Type ret_type, Type [] parameters)
                {
@@ -5398,50 +6465,5 @@ namespace Mono.CSharp {
                        }
                        return true;
                }
-
-               //
-               // This filter should be used when we are requesting methods that
-               // we want to override.
-               //
-               // This makes a number of assumptions, for example
-               // that the methods being extracted are of a parent
-               // class (this means we know implicitly that we are
-               // being called to find out about members by a derived
-               // class).
-               // 
-               static bool InheritableMemberSignatureCompare (MemberInfo m, object filter_criteria)
-               {
-                       MethodInfo mi;
-                       PropertyInfo pi = m as PropertyInfo;
-
-                       if (pi != null) {
-                               mi = pi.GetGetMethod (true);
-                               if (mi == null)
-                                       mi = pi.GetSetMethod (true);
-                       } else
-                               mi = m as MethodInfo;
-
-                       if (mi == null){
-                               Console.WriteLine ("Nothing found");
-                       }
-                       
-                       MethodAttributes prot = mi.Attributes & MethodAttributes.MemberAccessMask;
-
-                       // If only accessible to the current class.
-                       if (prot == MethodAttributes.Private)
-                               return false;
-
-                       if (!MemberSignatureCompare (m, filter_criteria))
-                               return false;
-
-                       // If only accessible to the defining assembly or 
-                       if (prot == MethodAttributes.FamANDAssem ||
-                           prot == MethodAttributes.Assembly){
-                               return m.DeclaringType.Assembly == CodeGen.Assembly.Builder;
-                       }
-
-                       // Anything else (FamOrAssembly and Public) is fine
-                       return true;
-               }
        }
 }