2007-01-28 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / mcs / class.cs
index 85e7f953629cf56e5b9eccf848759989dd6804c7..dd3ca4a533340b1e132f2168bbccd9f75b2cf43a 100644 (file)
@@ -74,8 +74,7 @@ namespace Mono.CSharp {
                                foreach (MemberCore mc in this) {
                                        try {
                                                mc.Define ();
-                                       }
-                                       catch (Exception e) {
+                                       } catch (Exception e) {
                                                throw new InternalErrorException (mc.Location, mc.GetSignatureForError (), e);
                                        }
                                }
@@ -138,7 +137,6 @@ namespace Mono.CSharp {
                                        Report.Warning (659, 3, container.Location, "`{0}' overrides Object.Equals(object) but does not override Object.GetHashCode()", container.GetSignatureForError ());
                                }
                        }
                }
 
                public sealed class IndexerArrayList : MemberCoreArrayList
@@ -434,8 +432,8 @@ namespace Mono.CSharp {
                // Holds the operators
                MemberCoreArrayList operators;
 
-               // Holds the iterators
-               ArrayList iterators;
+               // Holds the compiler generated classes
+               ArrayList compiler_generated;
 
                //
                // Pointers to the default constructor and the default static constructor
@@ -457,9 +455,12 @@ namespace Mono.CSharp {
                //
                TypeExpr base_type;
                TypeExpr[] iface_exprs;
+               Type GenericType;
 
                ArrayList type_bases;
 
+               bool members_resolved;
+               bool members_resolved_ok;
                bool members_defined;
                bool members_defined_ok;
 
@@ -472,7 +473,10 @@ namespace Mono.CSharp {
 
                public const string DefaultIndexerName = "Item";
 
-               public TypeContainer PartialContainer;
+#if GMCS_SOURCE
+               GenericTypeParameterBuilder[] gen_params;
+#endif
+
                ArrayList partial_parts;
 
                /// <remarks>
@@ -485,26 +489,26 @@ namespace Mono.CSharp {
                                      Attributes attrs, Kind kind)
                        : base (ns, parent, name, attrs)
                {
-                       if (parent != null && parent != RootContext.Tree.Types && parent.NamespaceEntry != ns)
+                       if (parent != null && parent.NamespaceEntry != ns)
                                throw new InternalErrorException ("A nested type should be in the same NamespaceEntry as its enclosing class");
 
                        this.Kind = kind;
                        this.PartialContainer = this;
                }
 
-               public bool AddToMemberContainer (MemberCore symbol)
+               public bool AddMember (MemberCore symbol)
                {
-                       return AddToContainer (symbol, symbol.Name);
+                       return AddToContainer (symbol, symbol.MemberName.MethodName);
                }
 
-               protected virtual bool AddToTypeContainer (DeclSpace ds)
+               protected virtual bool AddMemberType (DeclSpace ds)
                {
                        return AddToContainer (ds, ds.Basename);
                }
 
                public void AddConstant (Const constant)
                {
-                       if (!AddToMemberContainer (constant))
+                       if (!AddMember (constant))
                                return;
 
                        if (constants == null)
@@ -515,7 +519,7 @@ namespace Mono.CSharp {
 
                public void AddEnum (Mono.CSharp.Enum e)
                {
-                       if (!AddToTypeContainer (e))
+                       if (!AddMemberType (e))
                                return;
 
                        if (enums == null)
@@ -523,37 +527,36 @@ namespace Mono.CSharp {
 
                        enums.Add (e);
                }
-               
-               public bool AddClassOrStruct (TypeContainer c)
-               {
-                       if (!AddToTypeContainer (c))
-                               return false;
 
-                       if (types == null)
-                               types = new ArrayList (2);
+               public TypeContainer AddTypeContainer (TypeContainer tc, bool is_interface)
+               {
+                       if (!AddMemberType (tc))
+                               return tc;
 
-                       RootContext.Tree.RecordDecl (c.NamespaceEntry.NS, c.MemberName, c);
-                       types.Add (c);
-                       return true;
+                       if (is_interface) {
+                               if (interfaces == null)
+                                       interfaces = new MemberCoreArrayList ();
+                               interfaces.Add (tc);
+                       } else {
+                               if (types == null)
+                                       types = new ArrayList (2);
+                               types.Add (tc);
+                       }
+                       return tc;
                }
 
-               public virtual TypeContainer AddPartial (TypeContainer nextPart)
+               public virtual TypeContainer AddPartial (TypeContainer nextPart, bool is_interface)
                {
-                       return AddPartial (nextPart, nextPart.Basename);
+                       return AddPartial (nextPart, nextPart.Basename, is_interface);
                }
 
-               protected TypeContainer AddPartial (TypeContainer nextPart, string name)
+               protected TypeContainer AddPartial (TypeContainer nextPart, string name, bool is_interface)
                {
                        nextPart.ModFlags |= Modifiers.PARTIAL;
                        TypeContainer tc = defined_names [name] as TypeContainer;
 
-                       if (tc == null) {
-                               if (nextPart is Interface)
-                                       AddInterface (nextPart);
-                               else
-                                       AddClassOrStruct (nextPart);
-                               return nextPart;
-                       }
+                       if (tc == null)
+                               return AddTypeContainer (nextPart, is_interface);
 
                        if ((tc.ModFlags & Modifiers.PARTIAL) == 0) {
                                Report.SymbolRelatedToPreviousError (tc);
@@ -579,6 +582,21 @@ namespace Mono.CSharp {
                                return tc;
                        }
 
+                       if (tc.MemberName.IsGeneric) {
+                               TypeParameter[] tc_names = tc.TypeParameters;
+                               TypeParameterName[] part_names = nextPart.MemberName.TypeArguments.GetDeclarations ();
+
+                               for (int i = 0; i < tc_names.Length; ++i) {
+                                       if (tc_names[i].Name == part_names[i].Name)
+                                               continue;
+
+                                       Report.SymbolRelatedToPreviousError (part_names[i].Location, "");
+                                       Report.Error (264, tc.Location, "Partial declarations of `{0}' must have the same type parameter names in the same order",
+                                               tc.GetSignatureForError ());
+                                       return tc;
+                               }
+                       }
+
                        if (tc.partial_parts == null)
                                tc.partial_parts = new ArrayList (1);
 
@@ -597,18 +615,18 @@ namespace Mono.CSharp {
 
                public void AddDelegate (Delegate d)
                {
-                       if (!AddToTypeContainer (d))
+                       if (!AddMemberType (d))
                                return;
 
                        if (delegates == null)
                                delegates = new MemberCoreArrayList ();
-                       
+
                        delegates.Add (d);
                }
 
                public void AddMethod (Method method)
                {
-                       if (!AddToMemberContainer (method))
+                       if (!AddMember (method))
                                return;
 
                        if (methods == null)
@@ -627,7 +645,7 @@ namespace Mono.CSharp {
                //
                public void AppendMethod (Method method)
                {
-                       if (!AddToMemberContainer (method))
+                       if (!AddMember (method))
                                return;
 
                        if (methods == null)
@@ -638,7 +656,7 @@ namespace Mono.CSharp {
 
                public void AddConstructor (Constructor c)
                {
-                       if (c.Name != Basename)  {
+                       if (c.Name != MemberName.Name) {
                                Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
                        }
 
@@ -674,24 +692,10 @@ namespace Mono.CSharp {
                                return "`{0}' is already defined. Rename this member or use different parameter types";
                        }
                }
-               
-               public bool AddInterface (TypeContainer iface)
-               {
-                       if (!AddToTypeContainer (iface))
-                               return false;
-
-                       if (interfaces == null) {
-                               interfaces = new MemberCoreArrayList ();
-                       }
-
-                       RootContext.Tree.RecordDecl (iface.NamespaceEntry.NS, iface.MemberName, iface);
-                       interfaces.Add (iface);
-                       return true;
-               }
 
-               public void AddField (FieldMember field)
+               public void AddField (FieldBase field)
                {
-                       if (!AddToMemberContainer (field))
+                       if (!AddMember (field))
                                return;
 
                        if (fields == null)
@@ -719,8 +723,8 @@ namespace Mono.CSharp {
 
                public void AddProperty (Property prop)
                {
-                       if (!AddToMemberContainer (prop) || 
-                               !AddToMemberContainer (prop.Get) || !AddToMemberContainer (prop.Set))
+                       if (!AddMember (prop) || 
+                               !AddMember (prop.Get) || !AddMember (prop.Set))
                                return;
 
                        if (properties == null)
@@ -734,14 +738,14 @@ namespace Mono.CSharp {
 
                public void AddEvent (Event e)
                {
-                       if (!AddToMemberContainer (e))
+                       if (!AddMember (e))
                                return;
 
                        if (e is EventProperty) {
-                               if (!AddToMemberContainer (e.Add))
+                               if (!AddMember (e.Add))
                                        return;
 
-                               if (!AddToMemberContainer (e.Remove))
+                               if (!AddMember (e.Remove))
                                        return;
                        }
 
@@ -767,7 +771,7 @@ namespace Mono.CSharp {
 
                public void AddOperator (Operator op)
                {
-                       if (!AddToMemberContainer (op))
+                       if (!AddMember (op))
                                return;
 
                        if (operators == null)
@@ -776,12 +780,14 @@ namespace Mono.CSharp {
                        operators.Add (op);
                }
 
-               public void AddIterator (Iterator i)
+               public void AddCompilerGeneratedClass (CompilerGeneratedClass c)
                {
-                       if (iterators == null)
-                               iterators = new ArrayList ();
+                       Report.Debug (64, "ADD COMPILER GENERATED CLASS", this, c);
+
+                       if (compiler_generated == null)
+                               compiler_generated = new ArrayList ();
 
-                       iterators.Add (i);
+                       compiler_generated.Add (c);
                }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
@@ -826,9 +832,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               public ArrayList Iterators {
+               public ArrayList CompilerGenerated {
                        get {
-                               return iterators;
+                               return compiler_generated;
                        }
                }
 
@@ -917,18 +923,18 @@ namespace Mono.CSharp {
                        }
                }
 
-               public virtual void RegisterFieldForInitialization (FieldBase field)
+               public virtual void RegisterFieldForInitialization (MemberCore field, FieldInitializer expression)
                {
                        if ((field.ModFlags & Modifiers.STATIC) != 0){
                                if (initialized_static_fields == null)
                                        initialized_static_fields = new ArrayList (4);
 
-                               initialized_static_fields.Add (field);
+                               initialized_static_fields.Add (expression);
                        } else {
                                if (initialized_fields == null)
                                        initialized_fields = new ArrayList (4);
 
-                               initialized_fields.Add (field);
+                               initialized_fields.Add (expression);
                        }
                }
 
@@ -948,8 +954,8 @@ namespace Mono.CSharp {
                        if (fields == null)
                                return true;
 
-                       foreach (FieldBase f in fields) {
-                               f.EmitInitializer (ec);
+                       foreach (FieldInitializer f in fields) {
+                               f.EmitStatement (ec);
                        }
                        return true;
                }
@@ -978,6 +984,13 @@ namespace Mono.CSharp {
                        return base.GetClsCompliantAttributeValue ();
                }
 
+               public void AddBasesForPart (DeclSpace part, ArrayList bases)
+               {
+                       // FIXME: get rid of partial_parts and store lists of bases of each part here
+                       // assumed, not verified: 'part' is in 'partial_parts' 
+                       ((TypeContainer) part).Bases = bases;
+               }
+
                TypeExpr[] GetNormalBases (out TypeExpr base_class)
                {
                        base_class = null;
@@ -1005,7 +1018,7 @@ namespace Mono.CSharp {
                        TypeExpr [] ifaces = new TypeExpr [count-start];
                        
                        for (i = start, j = 0; i < count; i++, j++){
-                               TypeExpr resolved = ((Expression) Bases [i]).ResolveAsTypeTerminal (this, false);
+                               TypeExpr resolved = ((Expression) Bases [i]).ResolveAsBaseTerminal (this, false);
                                if (resolved == null) {
                                        return null;
                                }
@@ -1083,7 +1096,7 @@ namespace Mono.CSharp {
                                if (!iface.IsInterface) {
                                        if (Kind != Kind.Class) {
                                                // TODO: location of symbol related ....
-                                               Error_TypeInListIsNotInterface (Location, iface.FullName);
+                                               Error_TypeInListIsNotInterface (Location, iface.GetSignatureForError ());
                                        }
                                        else if (base_class != null)
                                                Report.Error (1721, Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')",
@@ -1117,6 +1130,36 @@ namespace Mono.CSharp {
                        return ifaces;
                }
 
+               bool CheckGenericInterfaces (Type[] ifaces)
+               {
+#if GMCS_SOURCE
+                       ArrayList already_checked = new ArrayList ();
+
+                       for (int i = 0; i < ifaces.Length; i++) {
+                               Type iface = ifaces [i];
+                               foreach (Type t in already_checked) {
+                                       if (iface == t)
+                                               continue;
+
+                                       Type[] inferred = new Type [CountTypeParameters];
+                                       if (!TypeManager.MayBecomeEqualGenericInstances (iface, t, inferred, null))
+                                               continue;
+
+                                       Report.Error (695, Location,
+                                               "`{0}' cannot implement both `{1}' and `{2}' " +
+                                               "because they may unify for some type parameter substitutions",
+                                               TypeManager.CSharpName (TypeBuilder), TypeManager.CSharpName (iface),
+                                               TypeManager.CSharpName (t));
+                                       return false;
+                               }
+
+                               already_checked.Add (iface);
+                       }
+#endif
+
+                       return true;
+               }
+
                bool error = false;
                
                protected void Error_TypeInListIsNotInterface (Location loc, string type)
@@ -1133,8 +1176,11 @@ namespace Mono.CSharp {
                                        }
 
                                        ModuleBuilder builder = CodeGen.Module.Builder;
+                                       Type default_parent = null;
+                                       if (Kind == Kind.Struct)
+                                               default_parent = TypeManager.value_type;
                                        TypeBuilder = builder.DefineType (
-                                               Name, TypeAttr, null, null);
+                                               Name, TypeAttr, default_parent, null);
                                } else {
                                        TypeBuilder builder = Parent.TypeBuilder;
 
@@ -1148,6 +1194,20 @@ namespace Mono.CSharp {
 
                        TypeManager.AddUserType (this);
 
+#if GMCS_SOURCE
+                       if (IsGeneric) {
+                               string[] param_names = new string [TypeParameters.Length];
+                               for (int i = 0; i < TypeParameters.Length; i++)
+                                       param_names [i] = TypeParameters [i].Name;
+
+                               gen_params = TypeBuilder.DefineGenericParameters (param_names);
+
+                               int offset = CountTypeParameters - CurrentTypeParameters.Length;
+                               for (int i = offset; i < gen_params.Length; i++)
+                                       CurrentTypeParameters [i - offset].Define (gen_params [i]);
+                       }
+#endif
+
                        iface_exprs = GetClassBases (out base_type);
                        if (partial_parts != null) {
                                iface_exprs = GetNormalPartialBases (ref base_type);
@@ -1163,32 +1223,45 @@ namespace Mono.CSharp {
                        // Let's do it as soon as possible, since code below can call DefineType() on classes
                        // that depend on us to be populated before they are.
                        //
-                       if (!(this is Iterator))
+                       if (!(this is CompilerGeneratedClass))
                                RootContext.RegisterOrder (this); 
 
+                       if (IsGeneric && base_type != null && TypeManager.IsAttributeType (base_type.Type)) {
+                               Report.Error (698, base_type.Location,
+                                             "A generic type cannot derive from `{0}' because it is an attribute class",
+                                             base_type.Name);
+                               return false;
+                       }
+
+                       if (!CheckRecursiveDefinition (this))
+                               return false;
 
                        if (base_type != null) {
                                TypeBuilder.SetParent (base_type.Type);
 
                                ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
-                               if (obsolete_attr != null && !IsInObsoleteScope) {
+                               if (obsolete_attr != null && !IsInObsoleteScope)
                                        AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
-                               }
-                       }
-
-                       if (!CheckRecursiveDefinition (this)) {
-                               return false;
                        }
 
                        // add interfaces that were not added at type creation
                        if (iface_exprs != null) {
                                ifaces = TypeManager.ExpandInterfaces (iface_exprs);
-                               if (ifaces == null) {
+                               if (ifaces == null)
                                        return false;
-                               }
 
                                foreach (Type itype in ifaces)
-                                       TypeBuilder.AddInterfaceImplementation (itype);
+                                       TypeBuilder.AddInterfaceImplementation (itype);
+
+                               foreach (TypeExpr ie in iface_exprs) {
+                                       ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (ie.Type);
+                                       if ((oa != null) && !IsInObsoleteScope)
+                                               AttributeTester.Report_ObsoleteMessage (
+                                                       oa, ie.GetSignatureForError (), Location);
+                               }
+
+                               if (!CheckGenericInterfaces (ifaces))
+                                       return false;
 
                                TypeManager.RegisterBuilder (TypeBuilder, ifaces);
                        }
@@ -1217,11 +1290,198 @@ namespace Mono.CSharp {
                                        part.TypeBuilder = TypeBuilder;
                        }
 
-                       DefineNestedTypes ();
+                       if (!(this is CompilerGeneratedClass)) {
+                               if (!ResolveMembers ()) {
+                                       error = true;
+                                       return null;
+                               }
+                       }
+
+                       if (!DefineNestedTypes ()) {
+                               error = true;
+                               return null;
+                       }
 
                        return TypeBuilder;
                }
 
+               public bool ResolveMembers ()
+               {
+                       if (members_resolved)
+                               return members_resolved_ok;
+
+                       members_resolved_ok = DoResolveMembers ();
+                       members_resolved = true;
+
+                       return members_resolved_ok;
+               }
+
+               protected virtual bool DoResolveMembers ()
+               {
+                       if (methods != null) {
+                               foreach (Method method in methods) {
+                                       if (!method.ResolveMembers ())
+                                               return false;
+                               }
+                       }
+
+                       if (instance_constructors != null) {
+                               foreach (Constructor c in instance_constructors) {
+                                       if (!c.ResolveMembers ())
+                                               return false;
+                               }
+                       }
+
+                       if (default_static_constructor != null) {
+                               if (!default_static_constructor.ResolveMembers ())
+                                       return false;
+                       }
+
+                       if (operators != null) {
+                               foreach (Operator o in operators) {
+                                       if (!o.ResolveMembers ())
+                                               return false;
+                               }
+                       }
+
+                       if (properties != null) {
+                               foreach (PropertyBase p in properties) {
+                                       if (!p.Get.IsDummy && !p.Get.ResolveMembers ())
+                                               return false;
+                                       if (!p.Set.IsDummy && !p.Set.ResolveMembers ())
+                                               return false;
+                               }
+                       }
+
+                       if (indexers != null) {
+                               foreach (PropertyBase p in indexers) {
+                                       if (!p.Get.IsDummy && !p.Get.ResolveMembers ())
+                                               return false;
+                                       if (!p.Set.IsDummy && !p.Set.ResolveMembers ())
+                                               return false;
+                               }
+                       }
+
+                       return true;
+               }
+
+               Constraints [] constraints;
+               public override void SetParameterInfo (ArrayList constraints_list)
+               {
+                       if (PartialContainer == this) {
+                               base.SetParameterInfo (constraints_list);
+                               return;
+                       }
+
+                       if (constraints_list == null)
+                               return;
+
+                       constraints = new Constraints [PartialContainer.CountCurrentTypeParameters];
+
+                       TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
+                       for (int i = 0; i < constraints.Length; i++) {
+                               foreach (Constraints constraint in constraints_list) {
+                                       if (constraint.TypeParameter == current_params [i].Name) {
+                                               constraints [i] = constraint;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+
+               bool UpdateTypeParameterConstraints ()
+               {
+                       if (constraints == null)
+                               return true;
+
+                       TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
+                       for (int i = 0; i < current_params.Length; i++) {
+                               if (!current_params [i].UpdateConstraints (this, constraints [i])) {
+                                       Report.SymbolRelatedToPreviousError (Location, "");
+                                       Report.Error (265, PartialContainer.Location,
+                                               "Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
+                                               PartialContainer.GetSignatureForError (), current_params [i].Name);
+                                       return false;
+                               }
+                       }
+
+                       return true;
+               }
+
+               public bool ResolveType ()
+               {
+                       if (!DoResolveType ())
+                               return false;
+
+                       if (compiler_generated != null) {
+                               foreach (CompilerGeneratedClass c in compiler_generated)
+                                       if (!c.ResolveType ())
+                                               return false;
+                       }
+
+                       return true;
+               }
+
+               protected virtual bool DoResolveType ()
+               {
+                       if ((base_type != null) &&
+                           (base_type.ResolveAsTypeTerminal (this, false) == null)) {
+                               error = true;
+                               return false;
+                       }
+
+                       if (!IsGeneric)
+                               return true;
+
+                       if (PartialContainer != this)
+                               throw new InternalErrorException ();
+
+                       TypeExpr current_type = null;
+
+                       foreach (TypeParameter type_param in CurrentTypeParameters) {
+                               if (!type_param.Resolve (this)) {
+                                       error = true;
+                                       return false;
+                               }
+                       }
+
+                       if (partial_parts != null) {
+                               foreach (TypeContainer part in partial_parts) {
+                                       if (!part.UpdateTypeParameterConstraints ()) {
+                                               error = true;
+                                               return false;
+                                       }
+                               }
+                       }
+
+                       foreach (TypeParameter type_param in TypeParameters) {
+                               if (!type_param.DefineType (this)) {
+                                       error = true;
+                                       return false;
+                               }
+                       }
+
+                       current_type = new ConstructedType (TypeBuilder, TypeParameters, Location);
+
+                       foreach (TypeParameter type_param in TypeParameters)
+                               if (!type_param.CheckDependencies ()) {
+                                       error = true;
+                                       return false;
+                               }
+
+                       if (current_type != null) {
+                               current_type = current_type.ResolveAsTypeTerminal (this, false);
+                               if (current_type == null) {
+                                       error = true;
+                                       return false;
+                               }
+
+                               CurrentType = current_type.Type;
+                       }
+
+                       return true;
+               }
+
                protected virtual bool DefineNestedTypes ()
                {
                        if (Interfaces != null) {
@@ -1248,6 +1508,13 @@ namespace Mono.CSharp {
                                                return false;
                        }
 
+                       if (compiler_generated != null) {
+                               foreach (CompilerGeneratedClass c in compiler_generated) {
+                                       if (c.DefineType () == null)
+                                               return false;
+                               }
+                       }
+
                        return true;
                }
 
@@ -1272,22 +1539,25 @@ namespace Mono.CSharp {
 
                        InTransit = tc;
 
-                       if (BaseType != null) {
-                               TypeContainer ptc = TypeManager.LookupTypeContainer (BaseType);
+                       if (base_type != null) {
+                               Type t = TypeManager.DropGenericTypeArguments (base_type.Type);
+                               TypeContainer ptc = TypeManager.LookupTypeContainer (t);
                                if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
                                        return false;
                        }
 
                        if (iface_exprs != null) {
                                foreach (TypeExpr iface in iface_exprs) {
-                                       Type itype = iface.Type;
-
+                                       Type itype = TypeManager.DropGenericTypeArguments (iface.Type);
                                        TypeContainer ptc = TypeManager.LookupTypeContainer (itype);
                                        if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
                                                return false;
                                }
                        }
 
+                       if (!IsTopLevel && !Parent.PartialContainer.CheckRecursiveDefinition (this))
+                               return false;
+
                        InTransit = null;
                        return true;
                }
@@ -1316,8 +1586,22 @@ namespace Mono.CSharp {
 
                protected virtual bool DoDefineMembers ()
                {
+                       if (iface_exprs != null) {
+                               foreach (TypeExpr iface in iface_exprs) {
+                                       ConstructedType ct = iface as ConstructedType;
+                                       if ((ct != null) && !ct.CheckConstraints (this))
+                                               return false;
+                               }
+                       }
+
+                       if (base_type != null) {
+                               ConstructedType ct = base_type as ConstructedType;
+                               if ((ct != null) && !ct.CheckConstraints (this))
+                                       return false;
+                       }
+
                        if (!IsTopLevel) {
-                               MemberInfo conflict_symbol = Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
+                               MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Basename, false);
                                if (conflict_symbol == null) {
                                        if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0))
                                                Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
@@ -1348,7 +1632,12 @@ namespace Mono.CSharp {
                        DefineContainerMembers (methods);
                        DefineContainerMembers (operators);
                        DefineContainerMembers (enums);
-                       DefineContainerMembers (delegates);                     
+                       DefineContainerMembers (delegates);
+
+                       if (CurrentType != null) {
+                               GenericType = CurrentType;
+                       }
+
 
 #if CACHE
                        member_cache = new MemberCache (this);
@@ -1357,17 +1646,6 @@ namespace Mono.CSharp {
                                        part.member_cache = member_cache;
                        }
 #endif
-                       if (iterators != null) {
-                               foreach (Iterator iterator in iterators) {
-                                       if (iterator.DefineType () == null)
-                                               return false;
-                               }
-
-                               foreach (Iterator iterator in iterators) {
-                                       if (!iterator.DefineMembers ())
-                                               return false;
-                               }
-                       }
 
                        return true;
                }
@@ -1380,9 +1658,9 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
-                       if (iterators != null) {
-                               foreach (Iterator iterator in iterators) {
-                                       if (!iterator.Define ())
+                       if (compiler_generated != null) {
+                               foreach (CompilerGeneratedClass c in compiler_generated) {
+                                       if (!c.Define ())
                                                return false;
                                }
                        }
@@ -1392,7 +1670,7 @@ namespace Mono.CSharp {
 
                public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
                {
-                       return BaseCache.FindMemberWithSameName (name, ignore_methods, null);
+                       return BaseCache == null ? null : BaseCache.FindMemberWithSameName (name, ignore_methods, null);
                }
 
                /// <summary>
@@ -1482,18 +1760,18 @@ namespace Mono.CSharp {
                
                // Indicated whether container has StructLayout attribute set Explicit
                public bool HasExplicitLayout {
-                       get {
-                               return (caching_flags & Flags.HasExplicitLayout) != 0;
-                       }
-                       set {
-                               caching_flags |= Flags.HasExplicitLayout;
-                       }
+                       get { return (caching_flags & Flags.HasExplicitLayout) != 0; }
+                       set { caching_flags |= Flags.HasExplicitLayout; }
                }
 
-               public override Type FindNestedType (string name)
+               //
+               // Return the nested type with name @name.  Ensures that the nested type
+               // is defined if necessary.  Do _not_ use this when you have a MemberCache handy.
+               //
+               public Type FindNestedType (string name)
                {
                        if (PartialContainer != this)
-                               return PartialContainer.FindNestedType (name);
+                               throw new InternalErrorException ("should not happen");
 
                        ArrayList [] lists = { types, enums, delegates, interfaces };
 
@@ -1604,7 +1882,7 @@ namespace Mono.CSharp {
                                if (fields != null) {
                                        int len = fields.Count;
                                        for (int i = 0; i < len; i++) {
-                                               FieldMember f = (FieldMember) fields [i];
+                                               FieldBase f = (FieldBase) fields [i];
                                                
                                                if ((f.ModFlags & modflags) == 0)
                                                        continue;
@@ -1688,6 +1966,31 @@ namespace Mono.CSharp {
                                        }
                                }
 
+                               if (events != null) {
+                                       foreach (Event e in events) {
+                                               if ((e.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((e.ModFlags & static_mask) != static_flags)
+                                                       continue;
+
+                                               MethodBuilder b = e.AddBuilder;
+                                               if (b != null && filter (b, criteria)) {
+                                                       if (members == null)
+                                                               members = new ArrayList (4);
+
+                                                       members.Add (b);
+                                               }
+
+                                               b = e.RemoveBuilder;
+                                               if (b != null && filter (b, criteria)) {
+                                                       if (members == null) 
+                                                               members = new ArrayList (4);
+
+                                                       members.Add (b);
+                                               }
+                                       }
+                               }
+
                                if (properties != null) {
                                        int len = properties.Count;
                                        for (int i = 0; i < len; i++) {
@@ -1858,17 +2161,6 @@ namespace Mono.CSharp {
                                                members.AddRange (list);
                                        }
                                }
-                               if (ifaces != null) {
-                                       foreach (Type base_type in ifaces) {
-                                               MemberList list = TypeContainer.FindMembers (base_type, mt, bf, filter, criteria);
-
-                                               if (list.Count > 0) {
-                                                       if (members == null)
-                                                               members = new ArrayList ();
-                                                       members.AddRange (list);
-                                               }
-                                       }
-                               }
                        }
 
                        Timer.StopTimer (TimerType.TcFindMembers);
@@ -1933,7 +2225,7 @@ namespace Mono.CSharp {
                                CheckMemberUsage (constants, "constant");
 
                                if (fields != null){
-                                       foreach (FieldMember f in fields) {
+                                       foreach (FieldBase f in fields) {
                                                if ((f.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
                                                        continue;
                                                
@@ -1961,8 +2253,9 @@ namespace Mono.CSharp {
                                                if ((f.caching_flags & Flags.IsAssigned) != 0)
                                                        continue;
                                                
+                                               Constant c = New.Constantify (f.Type.Type);
                                                Report.Warning (649, 4, f.Location, "Field `{0}' is never assigned to, and will always have its default value `{1}'",
-                                                       f.GetSignatureForError (), f.Type.Type.IsValueType ? Activator.CreateInstance (f.Type.Type).ToString() : "null");
+                                                       f.GetSignatureForError (), c == null ? "null" : c.AsString ());
                                        }
                                }
                        }
@@ -2001,7 +2294,15 @@ namespace Mono.CSharp {
                {
                        if (OptAttributes != null)
                                OptAttributes.Emit ();
-                               
+
+#if GMCS_SOURCE
+                       if (IsGeneric) {
+                               int offset = CountTypeParameters - CurrentTypeParameters.Length;
+                               for (int i = offset; i < gen_params.Length; i++)
+                                       CurrentTypeParameters [i - offset].EmitAttributes ();
+                       }
+#endif
+
                        //
                        // Structs with no fields need to have at least one byte.
                        // The right thing would be to set the PackingSize in a DefineType
@@ -2053,7 +2354,7 @@ namespace Mono.CSharp {
                        }
                        
                        if (fields != null)
-                               foreach (FieldMember f in fields)
+                               foreach (FieldBase f in fields)
                                        f.Emit ();
 
                        if (events != null){
@@ -2077,11 +2378,19 @@ namespace Mono.CSharp {
                                if (pending.VerifyPendingMethods ())
                                        return;
 
-                       if (iterators != null)
-                               foreach (Iterator iterator in iterators)
-                                       iterator.EmitType ();
-               }
+                       if (Report.Errors > 0)
+                               return;
 
+                       if (compiler_generated != null) {
+                               foreach (CompilerGeneratedClass c in compiler_generated) {
+                                       if (!c.DefineMembers ())
+                                               throw new InternalErrorException ();
+                               }
+                               foreach (CompilerGeneratedClass c in compiler_generated)
+                                       c.EmitType ();
+                       }
+               }
+               
                public override void CloseType ()
                {
                        if ((caching_flags & Flags.CloseTypeCreated) != 0)
@@ -2119,10 +2428,10 @@ namespace Mono.CSharp {
                                foreach (Delegate d in Delegates)
                                        d.CloseType ();
 
-                       if (Iterators != null)
-                               foreach (Iterator i in Iterators)
-                                       i.CloseType ();
-
+                       if (CompilerGenerated != null)
+                               foreach (CompilerGeneratedClass c in CompilerGenerated)
+                                       c.CloseType ();
+                       
                        types = null;
                        properties = null;
                        enums = null;
@@ -2136,7 +2445,7 @@ namespace Mono.CSharp {
                        events = null;
                        indexers = null;
                        operators = null;
-                       iterators = null;
+                       compiler_generated = null;
                        default_constructor = null;
                        default_static_constructor = null;
                        type_bases = null;
@@ -2241,11 +2550,6 @@ namespace Mono.CSharp {
                        if (base_type != null && !AttributeTester.IsClsCompliant (base_type)) {
                                Report.Error (3009, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
                        }
-
-                       if (!Parent.IsClsComplianceRequired ()) {
-                               Report.Error (3018, Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'", 
-                                       GetSignatureForError (), Parent.GetSignatureForError ());
-                       }
                        return true;
                }
 
@@ -2288,7 +2592,11 @@ namespace Mono.CSharp {
                                } else {
                                        Report.SymbolRelatedToPreviousError ((MemberCore) found);
                                }
+#if GMCS_SOURCE
+                               Report.Warning (3005, 1, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
+#else
                                Report.Error (3005, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
+#endif
                        }
                }
 
@@ -2298,7 +2606,7 @@ namespace Mono.CSharp {
                ///   checks whether the `interface_type' is a base inteface implementation.
                ///   Then it checks whether `name' exists in the interface type.
                /// </summary>
-               public virtual bool VerifyImplements (MemberBase mb)
+               public virtual bool VerifyImplements (InterfaceMemberBase mb)
                {
                        if (ifaces != null) {
                                foreach (Type t in ifaces){
@@ -2353,7 +2661,13 @@ namespace Mono.CSharp {
 
                MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
                {
-                       return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
+                       BindingFlags new_bf = bf | BindingFlags.DeclaredOnly;
+
+                       if (GenericType != null)
+                               return TypeManager.FindMembers (GenericType, mt, new_bf,
+                                                               null, null);
+                       else
+                               return FindMembers (mt, new_bf, null, null);
                }
 
                //
@@ -2393,7 +2707,14 @@ namespace Mono.CSharp {
 
                protected override bool AddToContainer (MemberCore symbol, string name)
                {
-                       if (name == Basename) {
+                       if (name == MemberName.Name) {
+                               if (symbol is TypeParameter) {
+                                       Report.Error (694, symbol.Location,
+                                                     "Type parameter `{0}' has same name as " +
+                                                     "containing type, or method", name);
+                                       return false;
+                               }
+
                                Report.SymbolRelatedToPreviousError (this);
                                Report.Error (542, symbol.Location, "`{0}': member names cannot be the same as their enclosing type",
                                        symbol.GetSignatureForError ());
@@ -2409,7 +2730,10 @@ namespace Mono.CSharp {
 
                        if ((events != null) && (RootContext.WarningLevel >= 3)) {
                                foreach (Event e in events){
-                                       if ((e.caching_flags & Flags.IsAssigned) == 0)
+                                       if ((e.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
+                                               continue;
+
+                                       if ((e.caching_flags & Flags.IsUsed) == 0)
                                                Report.Warning (67, 3, e.Location, "The event `{0}' is never used", e.GetSignatureForError ());
                                }
                        }
@@ -2460,10 +2784,13 @@ namespace Mono.CSharp {
                void DefineFieldInitializers ()
                {
                        if (initialized_fields != null) {
+                               EmitContext ec = new EmitContext (this, this, Location, null, null, ModFlags);
+                               ec.IsFieldInitializer = true;
+
                                for (int i = 0; i < initialized_fields.Count; ++i) {
-                                       FieldBase fb = (FieldBase)initialized_fields[i];
-                                       fb.ResolveInitializer ();
-                                       if (fb.HasDefaultInitializer && RootContext.Optimize) {
+                                       FieldInitializer fi = (FieldInitializer)initialized_fields[i];
+                                       fi.ResolveStatement (ec);
+                                       if (fi.IsDefaultInitializer && RootContext.Optimize) {
                                                // Field is re-initialized to its default value => removed
                                                initialized_fields.RemoveAt (i);
                                                --i;
@@ -2473,9 +2800,13 @@ namespace Mono.CSharp {
 
                        if (initialized_static_fields != null) {
                                bool has_complex_initializer = false;
+                               EmitContext ec = new EmitContext (this, this, Location, null, null, ModFlags);
+                               ec.IsStatic = true;
+                               ec.IsFieldInitializer = true;
 
-                               foreach (FieldBase fb in initialized_static_fields) {
-                                       if (fb.ResolveInitializer () is Constant)
+                               foreach (FieldInitializer fi in initialized_static_fields) {
+                                       fi.ResolveStatement (ec);
+                                       if (!fi.IsComplexInitializer)
                                                continue;
 
                                        has_complex_initializer = true;
@@ -2486,8 +2817,8 @@ namespace Mono.CSharp {
                                // static int b = 0;
                                if (!has_complex_initializer && RootContext.Optimize) {
                                        for (int i = 0; i < initialized_static_fields.Count; ++i) {
-                                               FieldBase fb = (FieldBase)initialized_static_fields[i];
-                                               if (fb.HasDefaultInitializer) {
+                                               FieldInitializer fi = (FieldInitializer)initialized_static_fields[i];
+                                               if (fi.IsDefaultInitializer) {
                                                        initialized_static_fields.RemoveAt (i);
                                                        --i;
                                                }
@@ -2554,7 +2885,7 @@ namespace Mono.CSharp {
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
 
                        if (IsStatic && RootContext.Version == LanguageVersion.ISO_1) {
-                               Report.FeatureIsNotStandardized (Location, "static classes");
+                               Report.FeatureIsNotISO1 (Location, "static classes");
                        }
                }
 
@@ -2669,6 +3000,14 @@ namespace Mono.CSharp {
                                else if (Name != "System.Object")
                                        base_class = TypeManager.system_object_expr;
                        } else {
+                               if (Kind == Kind.Class && base_class is TypeParameterExpr){
+                                       Report.Error (
+                                               689, base_class.Location,
+                                               "Cannot derive from `{0}' because it is a type parameter",
+                                               base_class.GetSignatureForError ());
+                                       return ifaces;
+                               }
+
                                if (base_class.Type.IsArray || base_class.Type.IsPointer) {
                                        Report.Error (1521, base_class.Location, "Invalid base type");
                                        return ifaces;
@@ -2832,14 +3171,14 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override void RegisterFieldForInitialization (FieldBase field)
+               public override void RegisterFieldForInitialization (MemberCore field, FieldInitializer expression)
                {
                        if ((field.ModFlags & Modifiers.STATIC) == 0) {
                                Report.Error (573, field.Location, "`{0}': Structs cannot have instance field initializers",
                                        field.GetSignatureForError ());
                                return;
                        }
-                       base.RegisterFieldForInitialization (field);
+                       base.RegisterFieldForInitialization (field, expression);
                }
 
        }
@@ -2922,25 +3261,50 @@ namespace Mono.CSharp {
                }
        }
 
-       public abstract class MethodCore : MemberBase {
+       // It is used as a base class for all property based members
+       // This includes properties, indexers, and events
+       public abstract class PropertyBasedMember : InterfaceMemberBase
+       {
+               public PropertyBasedMember (DeclSpace parent, GenericMethod generic,
+                       Expression type, int mod, int allowed_mod, bool is_iface,
+                       MemberName name, Attributes attrs)
+                       : base (parent, generic, type, mod, allowed_mod, is_iface, name, attrs)
+               {
+               }
+
+               protected override bool CheckForDuplications ()
+               {
+                       throw new NotSupportedException ();
+               }
+
+               protected override bool VerifyClsCompliance ()
+               {
+                       if (!base.VerifyClsCompliance ())
+                               return false;
+
+                       if (!AttributeTester.IsClsCompliant (MemberType)) {
+                               Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant",
+                                       GetSignatureForError ());
+                       }
+                       return true;
+               }
+
+       }
+
+
+       public abstract class MethodCore : InterfaceMemberBase
+       {
                public readonly Parameters Parameters;
                protected ToplevelBlock block;
 
-               //
-               // The method we're overriding if this is an override method.
-               //
-               protected MethodInfo base_method = null;
-
-               public MethodCore (DeclSpace parent, Expression type, int mod,
-                                  int allowed_mod, bool is_interface, MemberName name,
-                                  Attributes attrs, Parameters parameters)
-                       : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE, name,
-                               attrs)
+               public MethodCore (DeclSpace parent, GenericMethod generic,
+                       Expression type, int mod, int allowed_mod, bool is_iface,
+                       MemberName name, Attributes attrs, Parameters parameters)
+                       : base (parent, generic, type, mod, allowed_mod, is_iface, name, attrs)
                {
                        Parameters = parameters;
-                       IsInterface = is_interface;
                }
-               
+
                //
                //  Returns the System.Type array for the parameters of this method
                //
@@ -2967,20 +3331,202 @@ namespace Mono.CSharp {
                        }
                }
 
-               public void SetYields ()
+               protected bool DoDefineParameters ()
                {
-                       ModFlags |= Modifiers.METHOD_YIELDS;
+                       IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
+
+                       // Check if arguments were correct
+                       if (!Parameters.Resolve (rc))
+                               return false;
+
+                       return CheckParameters (Parameters);
                }
 
                protected override bool CheckBase ()
                {
+                       // Check whether arguments were correct.
+                       if (!DoDefineParameters ())
+                               return false;
+
                        if (!base.CheckBase ())
                                return false;
+
+                       return true;
+               }
+
+               // TODO: create a special method for operators only to make code better
+               protected bool IsDuplicateImplementation (MethodCore method)
+               {
+                       if (method == this)
+                               return false;
+
+                       Operator op2 = null;
+                       Operator op1 = null;
+
+                       if (!(method.MemberName.Equals (MemberName)))
+                       {
+                               op1 = this as Operator;
+                               if (op1 == null || !(op1.OperatorType == Operator.OpType.Explicit || op1.OperatorType == Operator.OpType.Implicit))
+                                       return false;
+
+                               op2 = method as Operator;
+                               if (op2 == null || !(op2.OperatorType == Operator.OpType.Explicit || op2.OperatorType == Operator.OpType.Implicit))
+                                       return false;
+                       } else {
+                               op1 = this as Operator;
+                               op2 = method as Operator;
+                       }
+
+                       Type[] param_types = method.ParameterTypes;
+                       // This never happen. Rewrite this as Equal
+                       if (param_types == null && ParameterTypes == null)
+                               return true;
+                       if (param_types == null || ParameterTypes == null)
+                               return false;
+
+                       if (param_types.Length != ParameterTypes.Length)
+                               return false;
+
+                       if (method.Parameters.HasArglist != Parameters.HasArglist)
+                               return false;
                        
-                       // Check whether arguments were correct.
-                       if (!DoDefineParameters ())
+                       bool equal = true;
+
+                       for (int i = 0; i < param_types.Length; i++) {
+                               if (param_types [i] != ParameterTypes [i])
+                                       equal = false;
+                       }
+
+                       if (IsExplicitImpl && (method.InterfaceType != InterfaceType))
+                               equal = false;
+
+                       // TODO: make operator compatible with MethodCore to avoid this
+                       if (op1 != null && op2 != null) {
+                               if (MemberType != method.MemberType)
+                                       equal = false;
+                       }
+
+                       if (equal) {
+                               //
+                               // Try to report 663: method only differs on out/ref
+                               //
+                               Parameters info = ParameterInfo;
+                               Parameters other_info = method.ParameterInfo;
+                               for (int i = 0; i < info.Count; i++){
+                                       if (info.ParameterModifier (i) != other_info.ParameterModifier (i)){
+                                               Report.SymbolRelatedToPreviousError (method);
+                                               Report.Error (663, Location, "`{0}': Methods cannot differ only on their use of ref and out on a parameters",
+                                                             GetSignatureForError ());
+                                               return false;
+                                       }
+                               }
+
+                               Report.SymbolRelatedToPreviousError (method);
+                               if (this is Operator && method is Operator)
+                                       Report.Error (557, Location, "Duplicate user-defined conversion in type `{0}'", Parent.Name);
+                               else
+                                       Report.Error (111, Location, TypeContainer.Error111, GetSignatureForError ());
+
+                               return true;
+                       }
+
+                       return false;
+               }
+
+               //
+               // Returns a string that represents the signature for this 
+               // member which should be used in XML documentation.
+               //
+               public override string GetDocCommentName (DeclSpace ds)
+               {
+                       return DocUtil.GetMethodDocCommentName (this, Parameters, ds);
+               }
+
+               //
+               // Raised (and passed an XmlElement that contains the comment)
+               // when GenerateDocComment is writing documentation expectedly.
+               //
+               // FIXME: with a few effort, it could be done with XmlReader,
+               // that means removal of DOM use.
+               //
+               internal override void OnGenerateDocComment (XmlElement el)
+               {
+                       DocUtil.OnMethodGenerateDocComment (this, el);
+               }
+
+               //
+               //   Represents header string for documentation comment.
+               //
+               public override string DocCommentHeader 
+               {
+                       get { return "M:"; }
+               }
+
+               public virtual void SetYields ()
+               {
+                       ModFlags |= Modifiers.METHOD_YIELDS;
+               }
+
+               protected override bool VerifyClsCompliance ()
+               {
+                       if (!base.VerifyClsCompliance ())
                                return false;
 
+                       if (Parameters.HasArglist) {
+                               Report.Error (3000, Location, "Methods with variable arguments are not CLS-compliant");
+                       }
+
+                       if (!AttributeTester.IsClsCompliant (MemberType)) {
+                               Report.Error (3002, Location, "Return type of `{0}' is not CLS-compliant",
+                                       GetSignatureForError ());
+                       }
+
+                       Parameters.VerifyClsCompliance ();
+                       return true;
+               }
+
+       }
+
+       public abstract class InterfaceMemberBase : MemberBase {
+               //
+               // Whether this is an interface member.
+               //
+               public bool IsInterface;
+
+               //
+               // If true, this is an explicit interface implementation
+               //
+               public bool IsExplicitImpl;
+
+               //
+               // The interface type we are explicitly implementing
+               //
+               public Type InterfaceType;
+
+               //
+               // The method we're overriding if this is an override method.
+               //
+               protected MethodInfo base_method;
+
+               readonly int explicit_mod_flags;
+               public MethodAttributes flags;
+
+               public InterfaceMemberBase (DeclSpace parent, GenericMethod generic,
+                                  Expression type, int mod, int allowed_mod, bool is_iface,
+                                  MemberName name, Attributes attrs)
+                       : base (parent, generic, type, mod, allowed_mod, Modifiers.PRIVATE,
+                               name, attrs)
+               {
+                       IsInterface = is_iface;
+                       IsExplicitImpl = (MemberName.Left != null);
+                       explicit_mod_flags = mod;
+               }
+               
+               protected override bool CheckBase ()
+               {
+                       if (!base.CheckBase ())
+                               return false;
+                       
                        if ((caching_flags & Flags.TestMethodDuplication) != 0 && !CheckForDuplications ())
                                return false;
 
@@ -2988,8 +3534,8 @@ namespace Mono.CSharp {
                                return true;
 
                        // Is null for System.Object while compiling corlib and base interfaces
-                       if (ParentContainer.BaseCache == null) {
-                               if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
+                       if (Parent.PartialContainer.BaseCache == null) {
+                               if ((ModFlags & Modifiers.NEW) != 0) {
                                        Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
                                }
                                return true;
@@ -3000,65 +3546,41 @@ namespace Mono.CSharp {
 
                        // method is override
                        if (base_method != null) {
-
-                               if (!CheckMethodAgainstBase ())
-                                       return false;
-
-                               if ((ModFlags & Modifiers.NEW) == 0) {
-                                       if (MemberType != TypeManager.TypeToCoreType (base_ret_type)) {
-                                               Report.SymbolRelatedToPreviousError (base_method);
-                                               if (this is PropertyBase) {
-                                                       Report.Error (1715, Location, "`{0}': type must be `{1}' to match overridden member `{2}'", 
-                                                               GetSignatureForError (), TypeManager.CSharpName (base_ret_type), TypeManager.CSharpSignature (base_method));
-                                               }
-                                               else {
-                                                       Report.Error (508, Location, "`{0}': return type must be `{1}' to match overridden member `{2}'",
-                                                               GetSignatureForError (), TypeManager.CSharpName (base_ret_type), TypeManager.CSharpSignature (base_method));
-                                               }
-                                               return false;
-                                       }
-                               } else {
-                                       if (base_method.IsAbstract && !IsInterface) {
-                                               Report.SymbolRelatedToPreviousError (base_method);
-                                               Report.Error (533, Location, "`{0}' hides inherited abstract member `{1}'",
-                                                       GetSignatureForError (), TypeManager.CSharpSignature (base_method));
-                                               return false;
-                                       }
-                               }
-
-                               if (base_method.IsSpecialName && !(this is PropertyBase)) {
-                                       Report.Error (115, Location, "`{0}': no suitable method found to override", GetSignatureForError ());
+                               if (!CheckMethodAgainstBase (base_ret_type))
                                        return false;
-                               }
-
-                               if (Name == "Equals" && Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type)
-                                       ParentContainer.Mark_HasEquals ();
-                               else if (Name == "GetHashCode" && Parameters.Empty)
-                                       ParentContainer.Mark_HasGetHashCode ();
 
                                if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                        ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (base_method);
                                        if (oa != null) {
                                                if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type)) {
                                                        Report.SymbolRelatedToPreviousError (base_method);
-                                                       Report.Warning (672, 1, Location, "Member `{0}' overrides obsolete member `{1}'. Add the Obsolete attribute to `{0}'",
-                                                               GetSignatureForError (), TypeManager.CSharpSignature (base_method) );
+                                                               Report.Warning (672, 1, Location, "Member `{0}' overrides obsolete member `{1}'. Add the Obsolete attribute to `{0}'",
+                                                                       GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+                                               }
+                                       } else {
+                                               if (OptAttributes != null && OptAttributes.Contains (TypeManager.obsolete_attribute_type)) {
+                                                       Report.Warning (809, 1, Location, "Obsolete member `{0}' overrides non-obsolete member `{1}'",
+                                                               GetSignatureForError (), TypeManager.CSharpSignature (base_method));
                                                }
                                        }
                                }
                                return true;
                        }
 
-                       MemberInfo conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, !(this is Property));
+                       MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Name, !((this is Event) || (this is Property)));
                        if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                if (conflict_symbol != null) {
                                        Report.SymbolRelatedToPreviousError (conflict_symbol);
-                                       if (this is PropertyBase)
+                                       if (this is Event)
+                                               Report.Error (72, Location, "`{0}': cannot override because `{1}' is not an event", GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
+                                       else if (this is PropertyBase)
                                                Report.Error (544, Location, "`{0}': cannot override because `{1}' is not a property", GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
                                        else
                                                Report.Error (505, Location, "`{0}': cannot override because `{1}' is not a method", GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
-                               } else
-                                       Report.Error (115, Location, "`{0}': no suitable method found to override", GetSignatureForError ());
+                               } else {
+                                       Report.Error (115, Location, "`{0}' is marked as an override but no suitable {1} found to override",
+                                               GetSignatureForError (), SimpleName.GetMemberType (this));
+                               }
                                return false;
                        }
 
@@ -3088,7 +3610,7 @@ namespace Mono.CSharp {
                // `name' is the user visible name for reporting errors (this is used to
                // provide the right name regarding method names and properties)
                //
-               bool CheckMethodAgainstBase ()
+               bool CheckMethodAgainstBase (Type baseMethodType)
                {
                        bool ok = true;
 
@@ -3118,17 +3640,39 @@ namespace Mono.CSharp {
                                        Error_CannotChangeAccessModifiers (base_method, base_classp, null);
                                        ok = false;
                                }
+
+                               if (!TypeManager.IsEqual (MemberType, TypeManager.TypeToCoreType (baseMethodType))) {
+                                       Report.SymbolRelatedToPreviousError (base_method);
+                                       if (this is PropertyBasedMember) {
+                                               Report.Error (1715, Location, "`{0}': type must be `{1}' to match overridden member `{2}'", 
+                                                       GetSignatureForError (), TypeManager.CSharpName (baseMethodType), TypeManager.CSharpSignature (base_method));
+                                       }
+                                       else {
+                                               Report.Error (508, Location, "`{0}': return type must be `{1}' to match overridden member `{2}'",
+                                                       GetSignatureForError (), TypeManager.CSharpName (baseMethodType), TypeManager.CSharpSignature (base_method));
+                                       }
+                                       ok = false;
+                               }
                        }
 
-                       if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0 && Name != "Finalize") {
-                               ModFlags |= Modifiers.NEW;
-                               Report.SymbolRelatedToPreviousError (base_method);
-                               if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
-                                       Report.Warning (114, 2, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword",
-                                               GetSignatureForError (), TypeManager.CSharpSignature (base_method));
-                               } else {
-                                       Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+                       if ((ModFlags & Modifiers.NEW) == 0) {
+                               if ((ModFlags & Modifiers.OVERRIDE) == 0 && Name != "Finalize") {
+                                       ModFlags |= Modifiers.NEW;
+                                       Report.SymbolRelatedToPreviousError (base_method);
+                                       if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
+                                               Report.Warning (114, 2, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword",
+                                                       GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+                                       } else {
+                                               Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+                                                       GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+                                       }
+                               }
+                       } else {
+                               if (base_method.IsAbstract && !IsInterface) {
+                                       Report.SymbolRelatedToPreviousError (base_method);
+                                       Report.Error (533, Location, "`{0}' hides inherited abstract member `{1}'",
                                                GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+                                       return ok = false;
                                }
                        }
 
@@ -3183,7 +3727,7 @@ namespace Mono.CSharp {
 
                public bool CheckAbstractAndExtern (bool has_block)
                {
-                       if (ParentContainer.Kind == Kind.Interface)
+                       if (Parent.PartialContainer.Kind == Kind.Interface)
                                return true;
 
                        if (has_block) {
@@ -3209,65 +3753,18 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected void Error_CannotChangeAccessModifiers (MemberInfo base_method, MethodAttributes ma, string suffix)
+               protected bool CheckParameters (Parameters parameters)
                {
-                       Report.SymbolRelatedToPreviousError (base_method);
-                       string base_name = TypeManager.GetFullNameSignature (base_method);
-                       string this_name = GetSignatureForError ();
-                       if (suffix != null) {
-                               base_name += suffix;
-                               this_name += suffix;
-                       }
+                       bool error = false;
 
-                       Report.Error (507, Location, "`{0}': cannot change access modifiers when overriding `{1}' inherited member `{2}'",
-                               this_name, Modifiers.GetDescription (ma), base_name);
-               }
+                       foreach (Type partype in parameters.Types){
+                               if (partype.IsPointer){
+                                       if (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
+                                               error = true;
+                               }
 
-               protected static string Error722 {
-                       get {
-                               return "`{0}': static types cannot be used as return types";
-                       }
-               }
-
-               /// <summary>
-               /// For custom member duplication search in a container
-               /// </summary>
-               protected abstract bool CheckForDuplications ();
-
-               /// <summary>
-               /// Gets base method and its return type
-               /// </summary>
-               protected abstract MethodInfo FindOutBaseMethod (ref Type base_ret_type);
-
-               protected bool DoDefineParameters ()
-               {
-                       // Check if arguments were correct
-                       if (!Parameters.Resolve (this))
-                               return false;
-
-                       return CheckParameters (ParameterTypes);
-               }
-
-               bool CheckParameters (Type [] parameters)
-               {
-                       bool error = false;
-                       DeclSpace ds = Parent;
-
-                       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 (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
-                                               error = true;
-                               }
-
-                               if (ds.AsAccessible (partype, ModFlags))
-                                       continue;
+                               if (ds.AsAccessible (partype, ModFlags))
+                                       continue;
 
                                Report.SymbolRelatedToPreviousError (partype);
                                if (this is Indexer)
@@ -3291,113 +3788,137 @@ namespace Mono.CSharp {
                        return !error;
                }
 
-               protected override bool VerifyClsCompliance ()
+               protected override bool DoDefine()
                {
-                       if (!base.VerifyClsCompliance ()) {
-                               if ((ModFlags & Modifiers.ABSTRACT) != 0 && IsExposedFromAssembly () && Parent.IsClsComplianceRequired ()) {
-                                       Report.Error (3011, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
-                               }
+                       if (!base.DoDefine ())
                                return false;
-                       }
-
-                       if (Parameters.HasArglist) {
-                               Report.Error (3000, Location, "Methods with variable arguments are not CLS-compliant");
-                       }
 
-                       if (!AttributeTester.IsClsCompliant (MemberType)) {
-                               if (this is PropertyBase)
-                                       Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant",
-                                                     GetSignatureForError ());
-                               else
-                                       Report.Error (3002, Location, "Return type of `{0}' is not CLS-compliant",
-                                                     GetSignatureForError ());
-                       }
+                       if (IsExplicitImpl) {
+                               Expression expr = MemberName.Left.GetTypeExpression ();
+                               TypeExpr texpr = expr.ResolveAsTypeTerminal (this, false);
+                               if (texpr == null)
+                                       return false;
 
-                       Parameters.VerifyClsCompliance ();
+                               InterfaceType = texpr.Type;
 
+                               if (!InterfaceType.IsInterface) {
+                                       Report.Error (538, Location, "`{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
+                                       return false;
+                               }
+                               
+                               if (!Parent.PartialContainer.VerifyImplements (this))
+                                       return false;
+                               
+                       }
                        return true;
                }
 
-               protected bool IsDuplicateImplementation (MethodCore method)
+               protected virtual bool DoDefineBase ()
                {
-                       if (method == this || !(method.MemberName.Equals (MemberName)))
-                               return false;
-
-                       Type[] param_types = method.ParameterTypes;
-                       // This never happen. Rewrite this as Equal
-                       if (param_types == null && ParameterTypes == null)
-                               return true;
-                       if (param_types == null || ParameterTypes == null)
-                               return false;
+                       if (Name == null)
+                               throw new InternalErrorException ();
 
-                       if (param_types.Length != ParameterTypes.Length)
-                               return false;
+                       if (IsInterface) {
+                               ModFlags = Modifiers.PUBLIC |
+                                       Modifiers.ABSTRACT |
+                                       Modifiers.VIRTUAL | (ModFlags & Modifiers.UNSAFE) | (ModFlags & Modifiers.NEW);
 
-                       if (method.Parameters.HasArglist != Parameters.HasArglist)
-                               return false;
-                       
-                       for (int i = 0; i < param_types.Length; i++)
-                               if (param_types [i] != ParameterTypes [i])
+                               flags = MethodAttributes.Public |
+                                       MethodAttributes.Abstract |
+                                       MethodAttributes.HideBySig |
+                                       MethodAttributes.NewSlot |
+                                       MethodAttributes.Virtual;
+                       } else {
+                               if (!Parent.PartialContainer.MethodModifiersValid (this))
                                        return false;
 
-                       // TODO: make operator compatible with MethodCore to avoid this
-                       if (this is Operator && method is Operator) {
-                               if (MemberType != method.MemberType)
-                                       return false;
+                               flags = Modifiers.MethodAttr (ModFlags);
                        }
 
-                       //
-                       // Try to report 663: method only differs on out/ref
-                       //
-                       Parameters info = ParameterInfo;
-                       Parameters other_info = method.ParameterInfo;
-                       for (int i = 0; i < info.Count; i++){
-                               if (info.ParameterModifier (i) != other_info.ParameterModifier (i)){
-                                       Report.SymbolRelatedToPreviousError (method);
-                                       Report.Error (663, Location, "`{0}': Methods cannot differ only on their use of ref and out on a parameters",
-                                               GetSignatureForError ());
+                       if (IsExplicitImpl) {
+                               Expression expr = MemberName.Left.GetTypeExpression ();
+                               TypeExpr iface_texpr = expr.ResolveAsTypeTerminal (this, false);
+                               if (iface_texpr == null)
+                                       return false;
+
+                               InterfaceType = iface_texpr.Type;
+
+                               if (!InterfaceType.IsInterface) {
+                                       Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
                                        return false;
                                }
+
+                               if (!Parent.PartialContainer.VerifyImplements (this))
+                                       return false;
+                               
+                               Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
                        }
 
-                       Report.SymbolRelatedToPreviousError (method);
-                       if (this is Operator && method is Operator)
-                               Report.Error (557, Location, "Duplicate user-defined conversion in type `{0}'", Parent.Name);
-                       else
-                               Report.Error (111, Location, TypeContainer.Error111, GetSignatureForError ());
                        return true;
                }
 
-               public override bool IsUsed {
-                       get { return IsExplicitImpl || base.IsUsed; }
+               protected void Error_CannotChangeAccessModifiers (MemberInfo base_method, MethodAttributes ma, string suffix)
+               {
+                       Report.SymbolRelatedToPreviousError (base_method);
+                       string base_name = TypeManager.GetFullNameSignature (base_method);
+                       string this_name = GetSignatureForError ();
+                       if (suffix != null) {
+                               base_name += suffix;
+                               this_name += suffix;
+                       }
+
+                       Report.Error (507, Location, "`{0}': cannot change access modifiers when overriding `{1}' inherited member `{2}'",
+                               this_name, Modifiers.GetDescription (ma), base_name);
+               }
+
+               protected static string Error722 {
+                       get {
+                               return "`{0}': static types cannot be used as return types";
+                       }
                }
 
+               /// <summary>
+               /// For custom member duplication search in a container
+               /// </summary>
+               protected abstract bool CheckForDuplications ();
+
+               /// <summary>
+               /// Gets base method and its return type
+               /// </summary>
+               protected abstract MethodInfo FindOutBaseMethod (ref Type base_ret_type);
+
                //
-               // Returns a string that represents the signature for this 
-               // member which should be used in XML documentation.
+               // The "short" name of this property / indexer / event.  This is the
+               // name without the explicit interface.
                //
-               public override string GetDocCommentName (DeclSpace ds)
+               public string ShortName 
                {
-                       return DocUtil.GetMethodDocCommentName (this, ds);
+                       get { return MemberName.Name; }
+                       set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
                }
 
-               //
-               // Raised (and passed an XmlElement that contains the comment)
-               // when GenerateDocComment is writing documentation expectedly.
-               //
-               // FIXME: with a few effort, it could be done with XmlReader,
-               // that means removal of DOM use.
-               //
-               internal override void OnGenerateDocComment (XmlElement el)
+               protected override bool VerifyClsCompliance ()
                {
-                       DocUtil.OnMethodGenerateDocComment (this, el);
+                       if (!base.VerifyClsCompliance ()) {
+                               if (IsInterface && HasClsCompliantAttribute && Parent.IsClsComplianceRequired ()) {
+                                       Report.Error (3010, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
+                               }
+
+                               if ((ModFlags & Modifiers.ABSTRACT) != 0 && Parent.TypeBuilder.IsClass && IsExposedFromAssembly () && Parent.IsClsComplianceRequired ()) {
+                                       Report.Error (3011, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
+                               }
+                               return false;
+                       }
+
+                       if (GenericMethod != null)
+                               GenericMethod.VerifyClsCompliance ();
+
+                       return true;
                }
 
-               //
-               //   Represents header string for documentation comment.
-               //
-               public override string DocCommentHeader {
-                       get { return "M:"; }
+               public override bool IsUsed 
+               {
+                       get { return IsExplicitImpl || base.IsUsed; }
                }
 
        }
@@ -3409,12 +3930,15 @@ namespace Mono.CSharp {
                ListDictionary declarative_security;
                protected MethodData MethodData;
 
+               Iterator iterator;
+               ArrayList anonymous_methods;
+
                static string[] attribute_targets = new string [] { "method", "return" };
 
-               protected MethodOrOperator (DeclSpace parent, Expression type, int mod,
+               protected MethodOrOperator (DeclSpace parent, GenericMethod generic, Expression type, int mod,
                                int allowed_mod, bool is_interface, MemberName name,
                                Attributes attrs, Parameters parameters)
-                       : base (parent, type, mod, allowed_mod, is_interface, name,
+                       : base (parent, generic, type, mod, allowed_mod, is_interface, name,
                                        attrs, parameters)
                {
                }
@@ -3459,15 +3983,62 @@ namespace Mono.CSharp {
                        }
                }
 
-               public EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
+               public virtual EmitContext CreateEmitContext (DeclSpace tc, ILGenerator ig)
+               {
+                       return new EmitContext (
+                               this, tc, this.ds, Location, ig, MemberType, ModFlags, false);
+               }
+
+               public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
+               {
+                       if (anonymous_methods == null)
+                               anonymous_methods = new ArrayList ();
+                       anonymous_methods.Add (anonymous);
+               }
+
+               protected bool DefineGenericMethod ()
+               {
+                       if (!DoDefineBase ())
+                               return false;
+
+#if GMCS_SOURCE
+                       if (GenericMethod != null) {
+                               string method_name = MemberName.Name;
+
+                               if (IsExplicitImpl) {
+                                       method_name = TypeManager.CSharpName (InterfaceType) +
+                                               '.' + method_name;
+                               }
+
+                               MethodBuilder = Parent.TypeBuilder.DefineMethod (method_name, flags);
+
+                               if (!GenericMethod.Define (MethodBuilder, block))
+                                       return false;
+                       }
+#endif
+
+                       return true;
+               }
+
+               public bool ResolveMembers ()
                {
-                       EmitContext ec = new EmitContext (this, ds, Parent, Location, ig, MemberType, ModFlags, false);
+                       if (!DefineGenericMethod ())
+                               return false;
+
+                       if ((ModFlags & Modifiers.METHOD_YIELDS) != 0) {
+                               iterator = Iterator.CreateIterator (this, Parent, GenericMethod, ModFlags);
+                               if (iterator == null)
+                                       return false;
+                       }
 
-                       ec.CurrentIterator = ds as Iterator;
-                       if (ec.CurrentIterator != null)
-                               ec.CurrentAnonymousMethod = ec.CurrentIterator.Host;
+                       if (anonymous_methods != null) {
+                               foreach (AnonymousMethodExpression ame in anonymous_methods) {
+                                       if (!ame.CreateAnonymousHelpers ())
+                                               return false;
+                               }
+                       }
 
-                       return ec;
+                       return true;
                }
 
                public override bool Define ()
@@ -3481,9 +4052,10 @@ namespace Mono.CSharp {
                        if (!CheckBase ())
                                return false;
 
-                       MethodData = new MethodData (this, ModFlags, flags, this);
+                       MethodData = new MethodData (
+                               this, ModFlags, flags, this, MethodBuilder, GenericMethod, base_method);
 
-                       if (!MethodData.Define (ParentContainer))
+                       if (!MethodData.Define (Parent.PartialContainer))
                                return false;
 
                        MethodBuilder = MethodData.MethodBuilder;
@@ -3559,13 +4131,18 @@ namespace Mono.CSharp {
                        }
                }
 
+               public Iterator Iterator {
+                       get { return iterator; }
+               }
+
                public new Location Location {
                        get {
                                return base.Location;
                        }
                }
 
-               protected override bool CheckBase() {
+               protected override bool CheckBase ()
+               {
                        if (!base.CheckBase ())
                                return false;
 
@@ -3626,6 +4203,12 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               GenericMethod IMethodData.GenericMethod {
+                       get {
+                               return GenericMethod;
+                       }
+               }
+
                #endregion
 
        }
@@ -3693,7 +4276,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class Method : MethodOrOperator, IIteratorContainer {
+       public class Method : MethodOrOperator, IAnonymousHost {
 
                /// <summary>
                ///   Modifiers allowed in a class declaration
@@ -3719,9 +4302,10 @@ namespace Mono.CSharp {
                //
                // return_type can be "null" for VOID values.
                //
-               public Method (DeclSpace parent, Expression return_type, int mod, bool is_iface,
+               public Method (DeclSpace parent, GenericMethod generic,
+                              Expression return_type, int mod, bool is_iface,
                               MemberName name, Parameters parameters, Attributes attrs)
-                       : base (parent, return_type, mod,
+                       : base (parent, generic, return_type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, attrs, parameters)
                {
@@ -3739,27 +4323,27 @@ namespace Mono.CSharp {
                                CodeGen.FileName, TypeManager.CSharpSignature(b));
                }
 
-                bool IsEntryPoint (MethodBuilder b, Parameters pinfo)
-                {
-                        if (b.ReturnType != TypeManager.void_type &&
-                            b.ReturnType != TypeManager.int32_type)
-                                return false;
+               bool IsEntryPoint (Parameters pinfo)
+               {
+                       if (ReturnType != TypeManager.void_type &&
+                               ReturnType != TypeManager.int32_type)
+                               return false;
 
-                        if (pinfo.Count == 0)
-                                return true;
+                       if (pinfo.Count == 0)
+                               return true;
 
-                        if (pinfo.Count > 1)
-                                return false;
+                       if (pinfo.Count > 1)
+                               return false;
 
-                        Type t = pinfo.ParameterType(0);
-                        if (t.IsArray &&
-                            (t.GetArrayRank() == 1) &&
-                            (TypeManager.GetElementType(t) == TypeManager.string_type) &&
-                            (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
-                                return true;
-                        else
-                                return false;
-                }
+                       Type t = pinfo.ParameterType (0);
+                       if (t.IsArray &&
+                               (t.GetArrayRank () == 1) &&
+                               (TypeManager.GetElementType (t) == TypeManager.string_type) &&
+                               (pinfo.ParameterModifier (0) == Parameter.Modifier.NONE))
+                               return true;
+                       else
+                               return false;
+               }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
@@ -3803,7 +4387,7 @@ namespace Mono.CSharp {
 
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = ParentContainer.Methods;
+                       ArrayList ar = Parent.PartialContainer.Methods;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -3814,7 +4398,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Properties;
+                       ar = Parent.PartialContainer.Properties;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        PropertyBase pb = (PropertyBase) ar [i];
@@ -3823,7 +4407,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Indexers;
+                       ar = Parent.PartialContainer.Indexers;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        PropertyBase pb = (PropertyBase) ar [i];
@@ -3832,7 +4416,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Events;
+                       ar = Parent.PartialContainer.Events;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        Event ev = (Event) ar [i];
@@ -3862,44 +4446,40 @@ namespace Mono.CSharp {
                                Report.Warning (465, 1, Location, "Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
                        }
 
-                       //
-                       // Setup iterator if we are one
-                       //
-                       if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
-                               Iterator iterator = new Iterator (this,
-                                       Parent,
-                                       ModFlags);
-
-                               if (!iterator.DefineIterator ())
-                                       return false;
+                       if (base_method != null) {
+                               if (Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type && Name == "Equals")
+                                       Parent.PartialContainer.Mark_HasEquals ();
+                               else if (Parameters.Empty && Name == "GetHashCode")
+                                       Parent.PartialContainer.Mark_HasGetHashCode ();
                        }
 
                        //
                        // This is used to track the Entry Point,
                        //
-                       if (Name == "Main" &&
-                               ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint && 
+                       if (RootContext.NeedsEntryPoint &&  ((ModFlags & Modifiers.STATIC) != 0) &&
+                               Name == "Main" &&
                                (RootContext.MainClass == null ||
                                RootContext.MainClass == Parent.TypeBuilder.FullName)){
-                               if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
-                                       IMethodData md = TypeManager.GetMethod (MethodBuilder);
-                                       md.SetMemberIsUsed ();
+                               if (IsEntryPoint (ParameterInfo)) {
 
                                        if (RootContext.EntryPoint == null) {
-                                               if (Parent.IsGeneric){
-                                                       Report.Error (-201, Location,
-                                                                     "Entry point can not be defined in a generic class");
-                                               }
+                                               if (Parent.IsGeneric || MemberName.IsGeneric) {
+                                                       Report.Warning (402, 4, Location, "`{0}': an entry point cannot be generic or in a generic type",
+                                                               GetSignatureForError ());
+                                               } else {
+                                                       IMethodData md = TypeManager.GetMethod (MethodBuilder);
+                                                       md.SetMemberIsUsed ();
 
-                                               RootContext.EntryPoint = MethodBuilder;
-                                               RootContext.EntryPointLocation = Location;
+                                                       RootContext.EntryPoint = MethodBuilder;
+                                                       RootContext.EntryPointLocation = Location;
+                                               }
                                        } else {
                                                Error_DuplicateEntryPoint (RootContext.EntryPoint, RootContext.EntryPointLocation);
                                                Error_DuplicateEntryPoint (MethodBuilder, Location);
                                        }
                                } else {
-                                       if (RootContext.WarningLevel >= 4)
-                                               Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point", TypeManager.CSharpSignature(MethodBuilder));
+                                       Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point",
+                                               GetSignatureForError ());
                                }
                        }
 
@@ -3911,6 +4491,7 @@ namespace Mono.CSharp {
                // 
                public override void Emit ()
                {
+                       Report.Debug (64, "METHOD EMIT", this, MethodBuilder, Location, Block, MethodData);
                        MethodData.Emit (Parent);
                        base.Emit ();
 
@@ -3925,8 +4506,8 @@ namespace Mono.CSharp {
 
                protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
-                       MethodInfo mi = (MethodInfo) ParentContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, ParameterTypes, false);
+                       MethodInfo mi = (MethodInfo) Parent.PartialContainer.BaseCache.FindMemberToOverride (
+                               Parent.TypeBuilder, Name, ParameterTypes, GenericMethod, false);
 
                        if (mi == null)
                                return null;
@@ -3944,7 +4525,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (ParameterInfo.Count > 0) {
-                               ArrayList al = (ArrayList)ParentContainer.MemberCache.Members [Name];
+                               ArrayList al = (ArrayList)Parent.PartialContainer.MemberCache.Members [Name];
                                if (al.Count > 1)
                                        MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
                        }
@@ -3996,8 +4577,18 @@ namespace Mono.CSharp {
                                                "`{0}': Struct constructors cannot call base constructors", TypeManager.CSharpSignature (caller_builder));
                                        return false;
                                }
-                       } else
+                       } else {
+                               //
+                               // It is legal to have "this" initializers that take no arguments
+                               // in structs, they are just no-ops.
+                               //
+                               // struct D { public D (int a) : this () {}
+                               //
+                               if (ec.ContainerType.IsValueType && argument_list == null)
+                                       return true;
+                               
                                t = ec.ContainerType;
+                       }
 
                        base_constructor_group = Expression.MemberLookup (
                                ec.ContainerType, t, ".ctor", MemberTypes.Constructor,
@@ -4026,11 +4617,12 @@ namespace Mono.CSharp {
                        }
 
                        if (error) {
+                               Report.SymbolRelatedToPreviousError (base_constructor);
                                Expression.ErrorIsInaccesible (loc, TypeManager.CSharpSignature (base_constructor));
                                base_constructor = null;
                                return false;
                        }
-
+                       
                        if (base_constructor == caller_builder){
                                Report.Error (516, loc, "Constructor `{0}' cannot call itself", TypeManager.CSharpSignature (caller_builder));
                                return false;
@@ -4072,10 +4664,11 @@ namespace Mono.CSharp {
                }
        }
        
-       public class Constructor : MethodCore, IMethodData {
+       public class Constructor : MethodCore, IMethodData, IAnonymousHost {
                public ConstructorBuilder ConstructorBuilder;
                public ConstructorInitializer Initializer;
                ListDictionary declarative_security;
+               ArrayList anonymous_methods;
 
                // <summary>
                //   Modifiers allowed for a constructor.
@@ -4091,6 +4684,10 @@ namespace Mono.CSharp {
 
                static string[] attribute_targets = new string [] { "method" };
 
+               public Iterator Iterator {
+                       get { return null; }
+               }
+
                bool has_compliant_args = false;
                //
                // The spec claims that static is not permitted, but
@@ -4098,8 +4695,8 @@ namespace Mono.CSharp {
                //
                public Constructor (DeclSpace parent, string name, int mod, Parameters args,
                                    ConstructorInitializer init, Location loc)
-                       : base (parent, null, mod, AllowedModifiers, false, new MemberName (name, loc),
-                               null, args)
+                       : base (parent, null, null, mod, AllowedModifiers, false,
+                               new MemberName (name, loc), null, args)
                {
                        Initializer = init;
                }
@@ -4143,10 +4740,29 @@ namespace Mono.CSharp {
 
                        ConstructorBuilder.SetCustomAttribute (cb);
                }
-               
+
+               public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
+               {
+                       if (anonymous_methods == null)
+                               anonymous_methods = new ArrayList ();
+                       anonymous_methods.Add (anonymous);
+               }
+
+               public bool ResolveMembers ()
+               {
+                       if (anonymous_methods != null) {
+                               foreach (AnonymousMethodExpression ame in anonymous_methods) {
+                                       if (!ame.CreateAnonymousHelpers ())
+                                               return false;
+                               }
+                       }
+
+                       return true;
+               }
+
                protected override bool CheckForDuplications ()
-               {
-                       ArrayList ar = ParentContainer.InstanceConstructors;
+               {
+                       ArrayList ar = Parent.PartialContainer.InstanceConstructors;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -4179,7 +4795,7 @@ namespace Mono.CSharp {
                        if (!CheckForDuplications ())
                                return false;
 
-                       if (ParentContainer.Kind == Kind.Struct) {
+                       if (Parent.PartialContainer.Kind == Kind.Struct) {
                                if (ParameterTypes.Length == 0) {
                                        Report.Error (568, Location, 
                                                "Structs cannot contain explicit parameterless constructors");
@@ -4242,7 +4858,7 @@ namespace Mono.CSharp {
                        if ((ModFlags & Modifiers.UNSAFE) != 0)
                                ConstructorBuilder.InitLocals = false;
 
-                       if (ParentContainer.IsComImport) {
+                       if (Parent.PartialContainer.IsComImport) {
                                if (!IsDefault ()) {
                                        Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
                                                Parent.GetSignatureForError ());
@@ -4269,7 +4885,7 @@ namespace Mono.CSharp {
                        if (block != null) {
                                // If this is a non-static `struct' constructor and doesn't have any
                                // initializer, it must initialize all of the struct's fields.
-                               if ((ParentContainer.Kind == Kind.Struct) &&
+                               if ((Parent.PartialContainer.Kind == Kind.Struct) &&
                                        ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
                                        block.AddThisVariable (Parent, Location);
 
@@ -4278,7 +4894,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.STATIC) == 0){
-                               if (ParentContainer.Kind == Kind.Class && Initializer == null)
+                               if (Parent.PartialContainer.Kind == Kind.Class && Initializer == null)
                                        Initializer = new GeneratedBaseInitializer (Location);
 
 
@@ -4301,7 +4917,7 @@ namespace Mono.CSharp {
                        //
                        // Classes can have base initializers and instance field initializers.
                        //
-                       if (ParentContainer.Kind == Kind.Class){
+                       if (Parent.PartialContainer.Kind == Kind.Class){
                                if ((ModFlags & Modifiers.STATIC) == 0){
 
                                        //
@@ -4309,17 +4925,30 @@ namespace Mono.CSharp {
                                        // do not emit field initializers, they are initialized in the other constructor
                                        //
                                        if (!(Initializer != null && Initializer is ConstructorThisInitializer))
-                                               ParentContainer.EmitFieldInitializers (ec);
+                                               Parent.PartialContainer.EmitFieldInitializers (ec);
+                               }
+                       }
+
+                       bool unreachable = false;
+                       if (block != null) {
+                               ec.ResolveTopBlock (null, block, ParameterInfo, this, out unreachable);
+                               ec.EmitMeta (block);
+
+                               if (block.ScopeInfo != null) {
+                                       ExpressionStatement init = block.ScopeInfo.GetScopeInitializer (ec);
+                                       init.EmitStatement (ec);
                                }
                        }
+
                        if (Initializer != null) {
                                Initializer.Emit (ec);
                        }
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
-                               ParentContainer.EmitFieldInitializers (ec);
+                               Parent.PartialContainer.EmitFieldInitializers (ec);
 
-                       ec.EmitTopBlock (this, block);
+                       if (block != null)
+                               ec.EmitResolvedTopBlock (block, unreachable);
 
                        if (source != null)
                                source.CloseMethod ();
@@ -4381,7 +5010,7 @@ namespace Mono.CSharp {
                        get {
                                CallingConventions cc = Parameters.CallingConvention;
 
-                               if (ParentContainer.Kind == Kind.Class)
+                               if (Parent.PartialContainer.Kind == Kind.Class)
                                        if ((ModFlags & Modifiers.STATIC) == 0)
                                                cc |= CallingConventions.HasThis;
 
@@ -4420,7 +5049,13 @@ namespace Mono.CSharp {
                        return false;
                }
 
-               #endregion
+               GenericMethod IMethodData.GenericMethod {
+                       get {
+                               return null;
+                       }
+               }
+
+               #endregion
        }
 
        /// <summary>
@@ -4432,8 +5067,11 @@ namespace Mono.CSharp {
                Location Location { get; }
                MemberName MethodName { get; }
                Type ReturnType { get; }
+               GenericMethod GenericMethod { get; }
                Parameters ParameterInfo { get; }
 
+               Iterator Iterator { get; }
+
                Attributes OptAttributes { get; }
                ToplevelBlock Block { get; set; }
 
@@ -4452,6 +5090,8 @@ namespace Mono.CSharp {
 
                readonly IMethodData method;
 
+               public readonly GenericMethod GenericMethod;
+
                //
                // Are we implementing an interface ?
                //
@@ -4460,9 +5100,11 @@ namespace Mono.CSharp {
                //
                // Protected data.
                //
-               protected MemberBase member;
+               protected InterfaceMemberBase member;
                protected int modifiers;
                protected MethodAttributes flags;
+               protected Type declaring_type;
+               protected MethodInfo parent_method;
 
                MethodBuilder builder = null;
                public MethodBuilder MethodBuilder {
@@ -4471,7 +5113,13 @@ namespace Mono.CSharp {
                        }
                }
 
-               public MethodData (MemberBase member,
+               public Type DeclaringType {
+                       get {
+                               return declaring_type;
+                       }
+               }
+
+               public MethodData (InterfaceMemberBase member,
                                   int modifiers, MethodAttributes flags, IMethodData method)
                {
                        this.member = member;
@@ -4481,12 +5129,23 @@ namespace Mono.CSharp {
                        this.method = method;
                }
 
+               public MethodData (InterfaceMemberBase member, 
+                                  int modifiers, MethodAttributes flags, 
+                                  IMethodData method, MethodBuilder builder,
+                                  GenericMethod generic, MethodInfo parent_method)
+                       : this (member, modifiers, flags, method)
+               {
+                       this.builder = builder;
+                       this.GenericMethod = generic;
+                       this.parent_method = parent_method;
+               }
+
                public bool Define (DeclSpace parent)
                {
-                       string name = method.MethodName.Name;
-                       string method_name = name;
+                       string name = method.MethodName.Basename;
+                       string method_name = method.MethodName.FullName;
 
-                       TypeContainer container = ((TypeContainer) parent).PartialContainer;
+                       TypeContainer container = parent.PartialContainer;
 
                        PendingImplementation pending = container.PendingImplementations;
                        if (pending != null){
@@ -4517,11 +5176,21 @@ namespace Mono.CSharp {
                                                        member.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
                                                return false;
                                        }
-                                       method_name = member.InterfaceType.FullName + "." + name;
+
+                                       method_name = TypeManager.GetFullName (member.InterfaceType) +
+                                               '.' + method_name;
                                } else {
                                        if (implementing != null) {
                                                AbstractPropertyEventMethod prop_method = method as AbstractPropertyEventMethod;
-                                               if (prop_method != null) {
+                                               if (prop_method == null) {
+                                                       if (implementing.IsSpecialName) {
+                                                               Report.SymbolRelatedToPreviousError (implementing);
+                                                               Report.Error (470, method.Location, "Method `{0}' cannot implement interface accessor `{1}.{2}'",
+                                                                       method.GetSignatureForError (), TypeManager.CSharpSignature (implementing),
+                                                                       implementing.Name.StartsWith ("get_") ? "get" : "set");
+                                                               return false;
+                                                       }
+                                               } else if (implementing.DeclaringType.IsInterface) {
                                                        if (!implementing.IsSpecialName) {
                                                                Report.SymbolRelatedToPreviousError (implementing);
                                                                Report.Error (686, method.Location, "Accessor `{0}' cannot implement interface member `{1}' for type `{2}'. Use an explicit interface implementation",
@@ -4553,17 +5222,20 @@ namespace Mono.CSharp {
                                // but it wont get cleared
                                //
                                if (member.IsExplicitImpl){
-                                       if ((modifiers & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
-                                               Modifiers.Error_InvalidModifier (method.Location, "public, virtual or abstract");
-                                               implementing = null;
+                                       if (method.ParameterInfo.HasParams && !TypeManager.GetParameterData (implementing).HasParams) {
+                                               Report.SymbolRelatedToPreviousError (implementing);
+                                               Report.Error (466, method.Location, "`{0}': the explicit interface implementation cannot introduce the params modifier",
+                                                       method.GetSignatureForError ());
+                                               return false;
                                        }
-                               } else if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public){
-                                       if (TypeManager.IsInterfaceType (implementing.DeclaringType)){
+                               } else {
+                                       if (implementing.DeclaringType.IsInterface) {
                                                //
                                                // If this is an interface method implementation,
                                                // check for public accessibility
                                                //
-                                               implementing = null;
+                                               if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public)
+                                                       implementing = null;
                                        } else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private){
                                                // We may never be private.
                                                implementing = null;
@@ -4573,7 +5245,7 @@ namespace Mono.CSharp {
                                                //
                                                implementing = null;
                                        }
-                               } 
+                               }
                                        
                                //
                                // Static is not allowed
@@ -4604,11 +5276,18 @@ namespace Mono.CSharp {
                                        flags |= MethodAttributes.Final;
                        }
 
+                       EmitContext ec = method.CreateEmitContext (container, null);
+
                        DefineMethodBuilder (container, method_name, method.ParameterInfo.Types);
 
                        if (builder == null)
                                return false;
 
+                       if (container.CurrentType != null)
+                               declaring_type = container.CurrentType;
+                       else
+                               declaring_type = container.TypeBuilder;
+
                        if ((modifiers & Modifiers.UNSAFE) != 0)
                                builder.InitLocals = false;
 
@@ -4633,6 +5312,17 @@ namespace Mono.CSharp {
 
                        TypeManager.AddMethod (builder, method);
 
+                       if (GenericMethod != null) {
+                               bool is_override = member.IsExplicitImpl |
+                                       ((modifiers & Modifiers.OVERRIDE) != 0);
+
+                               if (implementing != null)
+                                       parent_method = implementing;
+
+                               if (!GenericMethod.DefineType (ec, builder, parent_method, is_override))
+                                       return false;
+                       }
+
                        return true;
                }
 
@@ -4642,9 +5332,7 @@ namespace Mono.CSharp {
                /// </summary>
                void DefineMethodBuilder (TypeContainer container, string method_name, Type[] ParameterTypes)
                {
-                       const int extern_static = Modifiers.EXTERN | Modifiers.STATIC;
-
-                       if ((modifiers & extern_static) == extern_static) {
+                       if ((modifiers & Modifiers.EXTERN) != 0) {
 
                                if (method.OptAttributes != null) {
                                        Attribute dllimport_attribute = method.OptAttributes.Search (TypeManager.dllimport_type);
@@ -4662,15 +5350,25 @@ namespace Mono.CSharp {
                                // We are more strict than Microsoft and report CS0626 like error
                                if (method.OptAttributes == null ||
                                        !method.OptAttributes.Contains (TypeManager.methodimpl_attr_type)) {
-                                       Report.Error (626, method.Location, "Method, operator, or accessor `{0}' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation",
-                                               method.GetSignatureForError ());
+                                       Report.Error (626, method.Location,
+                                               "`{0}' is marked as an external but has no DllImport attribute. Consider adding a DllImport attribute to specify the external implementation",
+                                               member.GetSignatureForError ());
                                        return;
                                }
                        }
 
-                       builder = container.TypeBuilder.DefineMethod (
-                               method_name, flags, method.CallingConventions,
+                       if (builder == null) {
+                               builder = container.TypeBuilder.DefineMethod (
+                                       method_name, flags, method.CallingConventions,
+                                       method.ReturnType, ParameterTypes);
+                               return;
+                       }
+
+#if GMCS_SOURCE && !MS_COMPATIBLE
+                       builder.SetGenericMethodSignature (
+                               flags, method.CallingConventions,
                                method.ReturnType, ParameterTypes);
+#endif
                }
 
                //
@@ -4686,6 +5384,9 @@ namespace Mono.CSharp {
 
                        method.ParameterInfo.ApplyAttributes (MethodBuilder);
 
+                       if (GenericMethod != null)
+                               GenericMethod.EmitAttributes ();
+
                        ToplevelBlock block = method.Block;
                        
                        SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
@@ -4747,7 +5448,7 @@ namespace Mono.CSharp {
                public Destructor (DeclSpace parent, Expression return_type, int mod,
                                   string name, Parameters parameters, Attributes attrs,
                                   Location l)
-                       : base (parent, return_type, mod, false, new MemberName (name, l),
+                       : base (parent, null, return_type, mod, false, new MemberName (name, l),
                                parameters, attrs)
                { }
 
@@ -4775,32 +5476,18 @@ namespace Mono.CSharp {
        
        abstract public class MemberBase : MemberCore {
                public Expression Type;
-
-               public MethodAttributes flags;
-                       
-               protected readonly int explicit_mod_flags;
-
-               //
-               // The "short" name of this property / indexer / event.  This is the
-               // name without the explicit interface.
-               //
-               public string ShortName {
-                       get { return MemberName.Name; }
-                       set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
-               }
-
-               public TypeContainer ParentContainer {
-                       get { return ((TypeContainer) Parent).PartialContainer; }
-               }
+               public readonly DeclSpace ds;
+               public readonly GenericMethod GenericMethod;
 
                //
                // The type of this property / indexer / event
                //
-               Type member_type;
+               protected Type member_type;
                public Type MemberType {
                        get {
                                if (member_type == null && Type != null) {
-                                       Type = Type.ResolveAsTypeTerminal (ResolveContext, false);
+                                       IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
+                                       Type = Type.ResolveAsTypeTerminal (rc, false);
                                        if (Type != null) {
                                                member_type = Type.Type;
                                        }
@@ -4809,38 +5496,25 @@ namespace Mono.CSharp {
                        }
                }
 
-               //
-               // Whether this is an interface member.
-               //
-               public bool IsInterface;
-
-               //
-               // If true, this is an explicit interface implementation
-               //
-               public bool IsExplicitImpl;
-
-               //
-               // The interface type we are explicitly implementing
-               //
-               public Type InterfaceType = null;
-
                //
                // The constructor is only exposed to our children
                //
-               protected MemberBase (DeclSpace parent, Expression type, int mod,
-                                     int allowed_mod, int def_mod, MemberName name,
-                                     Attributes attrs)
+               protected MemberBase (DeclSpace parent, GenericMethod generic,
+                                     Expression type, int mod, int allowed_mod, int def_mod,
+                                     MemberName name, Attributes attrs)
                        : base (parent, name, attrs)
                {
-                       explicit_mod_flags = mod;
+                       this.ds = generic != null ? generic : (DeclSpace) parent;
                        Type = type;
                        ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, Location);
-                       IsExplicitImpl = (MemberName.Left != null);
+                       GenericMethod = generic;
+                       if (GenericMethod != null)
+                               GenericMethod.ModFlags = ModFlags;
                }
 
                protected virtual bool CheckBase ()
                {
-                       if ((ModFlags & Modifiers.PROTECTED) != 0 && ParentContainer.Kind == Kind.Struct) {
+                       if ((ModFlags & Modifiers.PROTECTED) != 0 && Parent.PartialContainer.Kind == Kind.Struct) {
                                Report.Error (666, Location, "`{0}': new protected member declared in struct", GetSignatureForError ());
                                return false;
                        }
@@ -4851,31 +5525,11 @@ namespace Mono.CSharp {
                            ((ModFlags & Modifiers.OVERRIDE) == 0) && (Name != "Finalize")) {
                                Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class", GetSignatureForError ());
                        }
-                       return true;
-       }
+                               return true;
+               }
 
                protected virtual bool DoDefine ()
                {
-                       if (Name == null)
-                               throw new InternalErrorException ();
-
-                       if (IsInterface) {
-                               ModFlags = Modifiers.PUBLIC |
-                                       Modifiers.ABSTRACT |
-                                       Modifiers.VIRTUAL | (ModFlags & Modifiers.UNSAFE) | (ModFlags & Modifiers.NEW);
-
-                               flags = MethodAttributes.Public |
-                                       MethodAttributes.Abstract |
-                                       MethodAttributes.HideBySig |
-                                       MethodAttributes.NewSlot |
-                                       MethodAttributes.Virtual;
-                       } else {
-                               if (!ParentContainer.MethodModifiersValid (this))
-                                       return false;
-
-                               flags = Modifiers.MethodAttr (ModFlags);
-                       }
-
                        if (MemberType == null)
                                return false;
 
@@ -4919,25 +5573,6 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (IsExplicitImpl) {
-                               Expression expr = MemberName.Left.GetTypeExpression ();
-                               TypeExpr texpr = expr.ResolveAsTypeTerminal (ResolveContext, false);
-                               if (texpr == null)
-                                       return false;
-
-                               InterfaceType = texpr.Type;
-
-                               if (!InterfaceType.IsInterface) {
-                                       Report.Error (538, Location, "`{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
-                                       return false;
-                               }
-                               
-                               if (!ParentContainer.VerifyImplements (this))
-                                       return false;
-                               
-                               Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
-                               
-                       }
                        return true;
                }
 
@@ -4949,48 +5584,30 @@ namespace Mono.CSharp {
                        }
                        return true;
                }
-
-               protected override bool VerifyClsCompliance()
-               {
-                       if (base.VerifyClsCompliance ()) {
-                               return true;
-                       }
-
-                       if (IsInterface && HasClsCompliantAttribute && Parent.IsClsComplianceRequired ()) {
-                               Report.Error (3010, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
-                       }
-                       return false;
-               }
-
        }
 
        //
-       // Fields and Events both generate FieldBuilders, we use this to share 
-       // their common bits.  This is also used to flag usage of the field
+       // Abstract class for all fields
        //
        abstract public class FieldBase : MemberBase {
-               public FieldBuilder  FieldBuilder;
+               public FieldBuilder FieldBuilder;
                public Status status;
                protected Expression initializer;
-               ExpressionStatement initializerStatement;
 
                [Flags]
                public enum Status : byte {
                        HAS_OFFSET = 4          // Used by FieldMember.
                }
 
-               static string[] attribute_targets = new string [] { "field" };
-
-               /// <summary>
-               ///  Symbol with same name in base class/struct
-               /// </summary>
-               public MemberInfo conflict_symbol;
+               static readonly string[] attribute_targets = new string [] { "field" };
 
                protected FieldBase (DeclSpace parent, Expression type, int mod,
                                     int allowed_mod, MemberName name, Attributes attrs)
-                       : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE,
+                       : base (parent, null, type, mod, allowed_mod | Modifiers.ABSTRACT, Modifiers.PRIVATE,
                                name, attrs)
                {
+                       if ((mod & Modifiers.ABSTRACT) != 0)
+                               Report.Error (681, Location, "The modifier 'abstract' is not valid on fields. Try using a property instead");
                }
 
                public override AttributeTargets AttributeTargets {
@@ -5001,6 +5618,27 @@ namespace Mono.CSharp {
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
+                       if (a.Type == TypeManager.field_offset_attribute_type) {
+                               status |= Status.HAS_OFFSET;
+
+                               if (!Parent.PartialContainer.HasExplicitLayout) {
+                                       Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
+                                       return;
+                               }
+
+                               if ((ModFlags & Modifiers.STATIC) != 0 || this is Const) {
+                                       Report.Error (637, Location, "The FieldOffset attribute is not allowed on static or const fields");
+                                       return;
+                               }
+                       }
+
+#if NET_2_0
+                       if (a.Type == TypeManager.fixed_buffer_attr_type) {
+                               Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
+                               return;
+                       }
+#endif
+
                        if (a.Type == TypeManager.marshal_as_attr_type) {
                                UnmanagedMarshal marshal = a.GetMarshal (this);
                                if (marshal != null) {
@@ -5017,23 +5655,14 @@ namespace Mono.CSharp {
                        FieldBuilder.SetCustomAttribute (cb);
                }
 
-               public void EmitInitializer (EmitContext ec)
-               {
-                       initializerStatement.EmitStatement (ec);
-               }
-
                protected override bool CheckBase ()
                {
                        if (!base.CheckBase ())
                                return false;
  
-                       // TODO: Implement
-                       if (IsInterface)
-                               return true;
-                       conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, false);
+                       MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Name, false);
                        if (conflict_symbol == null) {
-                               if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
+                               if ((ModFlags & Modifiers.NEW) != 0) {
                                        Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
                                }
                                return true;
@@ -5048,52 +5677,80 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public Expression Initializer {
-                       set {
-                               if (value != null) {
-                                       this.initializer = value;
-                                       ParentContainer.RegisterFieldForInitialization (this);
-                               }
+               public override bool Define()
+               {
+                       if (MemberType == null || Type == null)
+                               return false;
+
+                       if (MemberType == TypeManager.void_type) {
+                               // TODO: wrong location
+                               Expression.Error_VoidInvalidInTheContext (Location);
+                               return false;
                        }
-               }
 
-               protected virtual bool IsFieldClsCompliant {
-                       get {
-                               if (FieldBuilder == null)
-                                       return true;
+                       if (MemberType.IsSealed && MemberType.IsAbstract) {
+                               Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType);
+                               return false;
+                       }
 
-                               return AttributeTester.IsClsCompliant (FieldBuilder.FieldType);
+                       if (!CheckBase ())
+                               return false;
+                       
+                       if (!Parent.AsAccessible (MemberType, ModFlags)) {
+                               Report.Error (52, Location,
+                                       "Inconsistent accessibility: field type `" +
+                                       TypeManager.CSharpName (MemberType) + "' is less " +
+                                       "accessible than field `" + GetSignatureForError () + "'");
+                               return false;
                        }
+
+                       if (!IsTypePermitted ())
+                               return false;
+
+                       return true;
+               }
+
+               //
+               //   Represents header string for documentation comment.
+               //
+               public override string DocCommentHeader {
+                       get { return "F:"; }
                }
 
-               public Expression ResolveInitializer ()
+               public override void Emit ()
                {
-                       // TODO: again it's too heavy-weight
-                       EmitContext ec = new EmitContext (this, Parent, Location, null, null, ModFlags);
-                       ec.IsFieldInitializer = true;
-                       initializer = initializer.Resolve (ec);
-                       if (initializer == null)
-                               return null;
+                       if (OptAttributes != null) {
+                               OptAttributes.Emit ();
+                       }
 
-                       FieldExpr fe = new FieldExpr (FieldBuilder, Location, true);
-                       if ((ModFlags & Modifiers.STATIC) == 0) 
-                       {
-                               fe.InstanceExpression = CompilerGeneratedThis.Instance;
+                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && Parent.PartialContainer.HasExplicitLayout) {
+                               Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
                        }
 
-                       initializerStatement = new Assign (fe, initializer, Location).ResolveStatement (ec);
-                       return initializer;
+                       base.Emit ();
                }
 
-               public bool HasDefaultInitializer
+               public static void Error_VariableOfStaticClass (Location loc, string variableName, Type staticClass)
                {
-                       get
-                       {
-                               Constant c = initializer as Constant;
-                               if (c == null)
-                                       return false;
+                       Report.SymbolRelatedToPreviousError (staticClass);
+                       Report.Error (723, loc, "`{0}': cannot declare variables of static types",
+                               variableName);
+               }
+
+               public Expression Initializer {
+                       set {
+                               if (value != null) {
+                                       this.initializer = value;
+                               }
+                       }
+               }
 
-                               return c.IsDefaultInitializer (MemberType);
+               protected virtual bool IsFieldClsCompliant {
+                       get {
+                               if (FieldBuilder == null)
+                                       return true;
+
+                               return AttributeTester.IsClsCompliant (FieldBuilder.FieldType);
                        }
                }
 
@@ -5115,124 +5772,38 @@ namespace Mono.CSharp {
                        return true;
                }
 
-
                public void SetAssigned ()
                {
                        caching_flags |= Flags.IsAssigned;
                }
        }
 
-       public abstract class FieldMember : FieldBase
+       interface IFixedBuffer
        {
-               protected FieldMember (DeclSpace parent, Expression type, int mod,
-                       int allowed_mod, MemberName name, Attributes attrs)
-                       : base (parent, type, mod, allowed_mod | Modifiers.ABSTRACT, name, attrs)
-               {
-                       if ((mod & Modifiers.ABSTRACT) != 0)
-                               Report.Error (681, Location, "The modifier 'abstract' is not valid on fields. Try using a property instead");
-               }
+               FieldInfo Element { get; }
+               Type ElementType { get; }
+       }
 
-               public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+       public class FixedFieldExternal: IFixedBuffer
+       {
+               FieldInfo element_field;
+
+               public FixedFieldExternal (FieldInfo fi)
                {
-                       if (a.Type == TypeManager.field_offset_attribute_type)
-                       {
-                               status |= Status.HAS_OFFSET;
+                       element_field = fi.FieldType.GetField (FixedField.FixedElementName);
+               }
 
-                               if (!ParentContainer.HasExplicitLayout) {
-                                       Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
-                                       return;
-                               }
+               #region IFixedField Members
 
-                               if ((ModFlags & Modifiers.STATIC) != 0 || this is Const) {
-                                       Report.Error (637, Location, "The FieldOffset attribute is not allowed on static or const fields");
-                                       return;
-                               }
+               public FieldInfo Element {
+                       get {
+                               return element_field;
                        }
+               }
 
-#if NET_2_0
-                       if (a.Type == TypeManager.fixed_buffer_attr_type) {
-                               Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
-                               return;
-                       }
-#endif
-
-                       base.ApplyAttributeBuilder (a, cb);
-               }
-
-               public override bool Define()
-               {
-                       if (MemberType == null || Type == null)
-                               return false;
-
-                       if (MemberType == TypeManager.void_type) {
-                               Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
-                               return false;
-                       }
-
-                       if (!CheckBase ())
-                               return false;
-                       
-                       if (!Parent.AsAccessible (MemberType, ModFlags)) {
-                               Report.Error (52, Location,
-                                       "Inconsistent accessibility: field type `" +
-                                       TypeManager.CSharpName (MemberType) + "' is less " +
-                                       "accessible than field `" + GetSignatureForError () + "'");
-                               return false;
-                       }
-
-                       if (!IsTypePermitted ())
-                               return false;
-
-                       return true;
-               }
-
-               public override void Emit ()
-               {
-                       if (OptAttributes != null) {
-                               OptAttributes.Emit ();
-                       }
-
-                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && ParentContainer.HasExplicitLayout) {
-                               Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
-                       }
-
-                       base.Emit ();
-               }
-
-               //
-               //   Represents header string for documentation comment.
-               //
-               public override string DocCommentHeader {
-                       get { return "F:"; }
-               }
-       }
-
-       interface IFixedBuffer
-       {
-               FieldInfo Element { get; }
-               Type ElementType { get; }
-       }
-
-       public class FixedFieldExternal: IFixedBuffer
-       {
-               FieldInfo element_field;
-
-               public FixedFieldExternal (FieldInfo fi)
-               {
-                       element_field = fi.FieldType.GetField (FixedField.FixedElementName);
-               }
-
-               #region IFixedField Members
-
-               public FieldInfo Element {
-                       get {
-                               return element_field;
-                       }
-               }
-
-               public Type ElementType {
-                       get {
-                               return element_field.FieldType;
+               public Type ElementType {
+                       get {
+                               return element_field.FieldType;
                        }
                }
 
@@ -5242,7 +5813,7 @@ namespace Mono.CSharp {
        /// <summary>
        /// Fixed buffer implementation
        /// </summary>
-       public class FixedField : FieldMember, IFixedBuffer
+       public class FixedField : FieldBase, IFixedBuffer
        {
                public const string FixedElementName = "FixedElementField";
                static int GlobalCounter = 0;
@@ -5266,7 +5837,7 @@ namespace Mono.CSharp {
                        base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
                {
                        if (RootContext.Version == LanguageVersion.ISO_1)
-                               Report.FeatureIsNotStandardized (loc, "fixed size buffers");
+                               Report.FeatureIsNotISO1 (loc, "fixed size buffers");
 
                        this.size_expr = size_expr;
                }
@@ -5278,7 +5849,7 @@ namespace Mono.CSharp {
                                Report.Warning (-23, 1, Location, "Only private or internal fixed sized buffers are supported by .NET 1.x");
 #endif
 
-                       if (ParentContainer.Kind != Kind.Struct) {
+                       if (Parent.PartialContainer.Kind != Kind.Struct) {
                                Report.Error (1642, Location, "`{0}': Fixed size buffer fields may only be members of structs",
                                        GetSignatureForError ());
                                return false;
@@ -5298,7 +5869,7 @@ namespace Mono.CSharp {
                        if (c == null)
                                return false;
 
-                       IntConstant buffer_size_const = c.ToInt (Location);
+                       IntConstant buffer_size_const = c.ImplicitConversionRequired (TypeManager.int32_type, Location) as IntConstant;
                        if (buffer_size_const == null)
                                return false;
 
@@ -5378,7 +5949,7 @@ namespace Mono.CSharp {
        //
        // The Field class is used to represents class/struct fields during parsing.
        //
-       public class Field : FieldMember {
+       public class Field : FieldBase {
                // <summary>
                //   Modifiers allowed in a class declaration
                // </summary>
@@ -5450,7 +6021,7 @@ namespace Mono.CSharp {
 
                        FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
 
-                       if (ParentContainer.Kind == Kind.Struct && 
+                       if (Parent.PartialContainer.Kind == Kind.Struct && 
                            ((fa & FieldAttributes.Static) == 0) &&
                            MemberType == Parent.TypeBuilder &&
                            !TypeManager.IsBuiltinType (MemberType)){
@@ -5470,6 +6041,10 @@ namespace Mono.CSharp {
                                return false;
                        }
 
+                       if (initializer != null)
+                               Parent.PartialContainer.RegisterFieldForInitialization (this,
+                                       new FieldInitializer (FieldBuilder, initializer));
+
                        return true;
                }
 
@@ -5489,7 +6064,7 @@ namespace Mono.CSharp {
        //
        // `set' and `get' accessors are represented with an Accessor.
        // 
-       public class Accessor : IIteratorContainer {
+       public class Accessor : IAnonymousHost {
                //
                // Null if the accessor is empty, or a Block if not
                //
@@ -5504,6 +6079,7 @@ namespace Mono.CSharp {
                public Location Location;
                public int ModFlags;
                public bool Yields;
+               public ArrayList AnonymousMethods;
                
                public Accessor (ToplevelBlock b, int mod, Attributes attrs, Location loc)
                {
@@ -5517,6 +6093,13 @@ namespace Mono.CSharp {
                {
                        Yields = true;
                }
+
+               public void AddAnonymousMethod (AnonymousMethodExpression ame)
+               {
+                       if (AnonymousMethods == null)
+                               AnonymousMethods = new ArrayList ();
+                       AnonymousMethods.Add (ame);
+               }
        }
 
        // Ooouh Martin, templates are missing here.
@@ -5535,14 +6118,14 @@ namespace Mono.CSharp {
 
                ReturnParameter return_attributes;
 
-               public AbstractPropertyEventMethod (MemberBase member, string prefix)
+               public AbstractPropertyEventMethod (PropertyBasedMember member, string prefix)
                        : base (member.Parent, SetupName (prefix, member, member.Location), null)
                {
                        this.prefix = prefix;
                        IsDummy = true;
                }
 
-               public AbstractPropertyEventMethod (MemberBase member, Accessor accessor,
+               public AbstractPropertyEventMethod (InterfaceMemberBase member, Accessor accessor,
                                                    string prefix)
                        : base (member.Parent, SetupName (prefix, member, accessor.Location),
                                accessor.Attributes)
@@ -5551,18 +6134,22 @@ namespace Mono.CSharp {
                        this.block = accessor.Block;
                }
 
-               static MemberName SetupName (string prefix, MemberBase member, Location loc)
+               static MemberName SetupName (string prefix, InterfaceMemberBase member, Location loc)
                {
                        return new MemberName (member.MemberName.Left, prefix + member.ShortName, loc);
                }
 
-               public void UpdateName (MemberBase member)
+               public void UpdateName (InterfaceMemberBase member)
                {
                        SetMemberName (SetupName (prefix, member, Location));
                }
 
                #region IMethodData Members
 
+               public abstract Iterator Iterator {
+                       get;
+               }
+
                public ToplevelBlock Block {
                        get {
                                return block;
@@ -5584,6 +6171,12 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               GenericMethod IMethodData.GenericMethod {
+                       get {
+                               return null;
+                       }
+               }
+
                public MemberName MethodName {
                        get {
                                return MemberName;
@@ -5640,7 +6233,8 @@ namespace Mono.CSharp {
                        System.Diagnostics.Debug.Fail ("You forgot to define special attribute target handling");
                }
 
-               public override bool Define()
+               // It is not supported for the accessors
+               public sealed override bool Define()
                {
                        throw new NotSupportedException ();
                }
@@ -5719,18 +6313,18 @@ namespace Mono.CSharp {
        // Properties and Indexers both generate PropertyBuilders, we use this to share 
        // their common bits.
        //
-       abstract public class PropertyBase : MethodCore {
+       abstract public class PropertyBase : PropertyBasedMember {
 
                public class GetMethod : PropertyMethod
                {
                        static string[] attribute_targets = new string [] { "method", "return" };
 
-                       public GetMethod (MethodCore method):
+                       public GetMethod (PropertyBase method):
                                base (method, "get_")
                        {
                        }
 
-                       public GetMethod (MethodCore method, Accessor accessor):
+                       public GetMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor, "get_")
                        {
                        }
@@ -5772,12 +6366,12 @@ namespace Mono.CSharp {
                        ImplicitParameter param_attr;
                        protected Parameters parameters;
 
-                       public SetMethod (MethodCore method):
+                       public SetMethod (PropertyBase method):
                                base (method, "set_")
                        {
                        }
 
-                       public SetMethod (MethodCore method, Accessor accessor):
+                       public SetMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor, "set_")
                        {
                        }
@@ -5797,6 +6391,8 @@ namespace Mono.CSharp {
 
                        public override Parameters ParameterInfo {
                                get {
+                                       if (parameters == null)
+                                               DefineParameters ();
                                        return parameters;
                                }
                        }
@@ -5810,7 +6406,6 @@ namespace Mono.CSharp {
 
                        public override MethodBuilder Define (DeclSpace parent)
                        {
-                               DefineParameters ();
                                if (IsDummy)
                                        return null;
 
@@ -5841,46 +6436,71 @@ namespace Mono.CSharp {
 
                public abstract class PropertyMethod : AbstractPropertyEventMethod
                {
-                       protected readonly MethodCore method;
+                       protected readonly PropertyBase method;
                        protected MethodAttributes flags;
+                       Iterator iterator;
+                       ArrayList anonymous_methods;
                        bool yields;
 
-                       public PropertyMethod (MethodCore method, string prefix)
+                       public PropertyMethod (PropertyBase method, string prefix)
                                : base (method, prefix)
                        {
                                this.method = method;
                        }
 
-                       public PropertyMethod (MethodCore method, Accessor accessor,
+                       public PropertyMethod (PropertyBase method, Accessor accessor,
                                               string prefix)
                                : base (method, accessor, prefix)
                        {
                                this.method = method;
                                this.ModFlags = accessor.ModFlags;
                                yields = accessor.Yields;
+                               anonymous_methods = accessor.AnonymousMethods;
 
                                if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
-                                       Report.FeatureIsNotStandardized (Location, "access modifiers on properties");
+                                       Report.FeatureIsNotISO1 (Location, "access modifiers on properties");
                                }
                        }
 
+                       public override Iterator Iterator {
+                               get { return iterator; }
+                       }
+
                        public override AttributeTargets AttributeTargets {
                                get {
                                        return AttributeTargets.Method;
                                }
                        }
 
-                       public override bool IsClsComplianceRequired()
+                       public override bool IsClsComplianceRequired ()
                        {
                                return method.IsClsComplianceRequired ();
                        }
 
+                       public bool ResolveMembers ()
+                       {
+                               if (yields) {
+                                       iterator = Iterator.CreateIterator (this, Parent, null, ModFlags);
+                                       if (iterator == null)
+                                               return false;
+                               }
+
+                               if (anonymous_methods != null) {
+                                       foreach (AnonymousMethodExpression ame in anonymous_methods) {
+                                               if (!ame.CreateAnonymousHelpers ())
+                                                       return false;
+                                       }
+                               }
+
+                               return true;
+                       }
+
                        public virtual MethodBuilder Define (DeclSpace parent)
                        {
                                if (!method.CheckAbstractAndExtern (block != null))
                                        return null;
 
-                               TypeContainer container = ((TypeContainer) parent).PartialContainer;
+                               TypeContainer container = parent.PartialContainer;
 
                                //
                                // Check for custom access modifier
@@ -5904,16 +6524,6 @@ namespace Mono.CSharp {
                                        flags |= (method.flags & (~MethodAttributes.MemberAccessMask));
                                }
 
-                               //
-                               // Setup iterator if we are one
-                               //
-                               if (yields) {
-                                       Iterator iterator = new Iterator (this, Parent as TypeContainer, ModFlags);
-                                       
-                                       if (!iterator.DefineIterator ())
-                                               return null;
-                               }
-
                                return null;
                        }
 
@@ -5927,7 +6537,7 @@ namespace Mono.CSharp {
                        public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                        {
                                return new EmitContext (method,
-                                       ds, method.Parent, method.Location, ig, ReturnType,
+                                       ds, method.ds, method.Location, ig, ReturnType,
                                        method.ModFlags, false);
                        }
 
@@ -5976,14 +6586,14 @@ namespace Mono.CSharp {
                public PropertyBuilder PropertyBuilder;
                public MethodBuilder GetBuilder, SetBuilder;
 
-               protected EmitContext ec;
+               protected bool define_set_first = false;
 
                public PropertyBase (DeclSpace parent, Expression type, int mod_flags,
                                     int allowed_mod, bool is_iface, MemberName name,
-                                    Parameters parameters, Attributes attrs)
-                       : base (parent, type, mod_flags, allowed_mod, is_iface, name,
-                               attrs, parameters)
+                                    Attributes attrs, bool define_set_first)
+                       : base (parent, null, type, mod_flags, allowed_mod, is_iface, name,     attrs)
                {
+                        this.define_set_first = define_set_first;
                }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
@@ -6043,39 +6653,37 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected override bool CheckForDuplications ()
+               bool DefineGet ()
                {
-                       ArrayList ar = ParentContainer.Indexers;
-                       if (ar != null) {
-                               int arLen = ar.Count;
-                                       
-                               for (int i = 0; i < arLen; i++) {
-                                       Indexer m = (Indexer) ar [i];
-                                       if (IsDuplicateImplementation (m))
-                                               return false;
-                               }
-                       }
+                       if (Get.IsDummy)
+                               return true;
 
-                       ar = ParentContainer.Properties;
-                       if (ar != null) {
-                               int arLen = ar.Count;
-                                       
-                               for (int i = 0; i < arLen; i++) {
-                                       Property m = (Property) ar [i];
-                                       if (IsDuplicateImplementation (m))
-                                               return false;
-                               }
-                       }
+                       GetBuilder = Get.Define (Parent);
+                       return GetBuilder != null;
+               }
 
-                       return true;
+               bool DefineSet (bool define)
+               {
+                       if (!define || Set.IsDummy)
+                               return true;
+
+                       SetBuilder = Set.Define (Parent);
+                       return SetBuilder != null;
                }
 
+               protected bool DefineAccessors ()
+               {
+                       return DefineSet (define_set_first) &&
+                               DefineGet () &&
+                               DefineSet (!define_set_first);
+               }
+
+               protected abstract PropertyInfo ResolveBaseProperty ();
+
                // TODO: rename to Resolve......
                protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
-                       PropertyInfo base_property = ParentContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, ParameterTypes, true) as PropertyInfo;
-  
+                       PropertyInfo base_property = ResolveBaseProperty ();
                        if (base_property == null)
                                return null;
   
@@ -6206,10 +6814,10 @@ namespace Mono.CSharp {
 
                public Property (DeclSpace parent, Expression type, int mod, bool is_iface,
                                 MemberName name, Attributes attrs, Accessor get_block,
-                                Accessor set_block)
+                                Accessor set_block, bool define_set_first)
                        : base (parent, type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
-                               is_iface, name, Parameters.EmptyReadOnlyParameters, attrs)
+                               is_iface, name, attrs, define_set_first)
                {
                        if (get_block == null)
                                Get = new GetMethod (this);
@@ -6224,6 +6832,9 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
+                       if (!DoDefineBase ())
+                               return false;
+
                        if (!base.Define ())
                                return false;
 
@@ -6232,23 +6843,14 @@ namespace Mono.CSharp {
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
-                       if (!Get.IsDummy) {
-                               GetBuilder = Get.Define (Parent);
-                               if (GetBuilder == null)
-                                       return false;
-                       }
-
-                       SetBuilder = Set.Define (Parent);
-                       if (!Set.IsDummy) {
-                               if (SetBuilder == null)
-                                       return false;
-                       }
+                       if (!DefineAccessors ())
+                               return false;
 
                        // FIXME - PropertyAttributes.HasDefault ?
 
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
-                            Name, PropertyAttributes.None, MemberType, null);
-                       
+                               MemberName.ToString (), PropertyAttributes.None, MemberType, null);
+
                        if (!Get.IsDummy)
                                PropertyBuilder.SetGetMethod (GetBuilder);
                                
@@ -6258,6 +6860,12 @@ namespace Mono.CSharp {
                        TypeManager.RegisterProperty (PropertyBuilder, this);
                        return true;
                }
+
+               protected override PropertyInfo ResolveBaseProperty ()
+               {
+                       return Parent.PartialContainer.BaseCache.FindMemberToOverride (
+                               Parent.TypeBuilder, Name, Parameters.EmptyReadOnlyParameters.Types, null, true) as PropertyInfo;
+               }
        }
 
        /// </summary>
@@ -6400,7 +7008,7 @@ namespace Mono.CSharp {
                public void SetUsed ()
                {
                        if (my_event != null) {
-                               my_event.SetAssigned ();
+//                             my_event.SetAssigned ();
                                my_event.SetMemberIsUsed ();
                        }
                }
@@ -6410,8 +7018,50 @@ namespace Mono.CSharp {
        /// For case when event is declared like property (with add and remove accessors).
        /// </summary>
        public class EventProperty: Event {
+               abstract class AEventPropertyAccessor : AEventAccessor
+               {
+                       public AEventPropertyAccessor (Event method, Accessor accessor, string prefix):
+                               base (method, accessor, prefix)
+                       {
+                       }
+
+                       public override MethodBuilder Define (DeclSpace ds)
+                       {
+                               method.CheckAbstractAndExtern (block != null);
+                               return base.Define (ds);
+                       }
+               }
+
+               sealed class AddDelegateMethod: AEventPropertyAccessor
+               {
+                       public AddDelegateMethod (Event method, Accessor accessor):
+                               base (method, accessor, "add_")
+                       {
+                       }
+
+                       protected override MethodInfo DelegateMethodInfo {
+                               get {
+                                       return TypeManager.delegate_combine_delegate_delegate;
+                               }
+                       }
+               }
+
+               sealed class RemoveDelegateMethod: AEventPropertyAccessor
+               {
+                       public RemoveDelegateMethod (Event method, Accessor accessor):
+                               base (method, accessor, "remove_")
+                       {
+                       }
+
+                       protected override MethodInfo DelegateMethodInfo {
+                               get {
+                                       return TypeManager.delegate_remove_delegate_delegate;
+                               }
+                       }
+               }
 
-               static string[] attribute_targets = new string [] { "event" }; // "property" target was disabled for 2.0 version
+
+               static readonly string[] attribute_targets = new string [] { "event" }; // "property" target was disabled for 2.0 version
 
                public EventProperty (DeclSpace parent, Expression type, int mod_flags,
                                      bool is_iface, MemberName name,
@@ -6420,10 +7070,17 @@ namespace Mono.CSharp {
                {
                        Add = new AddDelegateMethod (this, add);
                        Remove = new RemoveDelegateMethod (this, remove);
+               }
+
+               public override bool Define()
+               {
+                       if (!base.Define ())
+                               return false;
 
-                       // For this event syntax we don't report error CS0067
-                       // because it is hard to do it.
-                       SetAssigned ();
+                       if (IsExplicitImpl)
+                               SetMemberIsUsed ();
+
+                       return true;
                }
 
                public override string[] ValidAttributeTargets {
@@ -6437,9 +7094,77 @@ namespace Mono.CSharp {
        /// Event is declared like field.
        /// </summary>
        public class EventField : Event {
+               abstract class EventFieldAccessor : AEventAccessor
+               {
+                       protected EventFieldAccessor (Event method, string prefix)
+                               : base (method, prefix)
+                       {
+                       }
 
-               static string[] attribute_targets = new string [] { "event", "field", "method" };
-               static string[] attribute_targets_interface = new string[] { "event", "method" };
+                       protected override void EmitMethod(DeclSpace parent)
+                       {
+                               if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
+                                       return;
+
+                               ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
+
+                               // TODO: because we cannot use generics yet
+                               FieldInfo field_info = ((EventField)method).FieldBuilder;
+
+                               method_data.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Synchronized);
+                               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);
+                       }
+               }
+
+               sealed class AddDelegateMethod: EventFieldAccessor
+               {
+                       public AddDelegateMethod (Event method):
+                               base (method, "add_")
+                       {
+                       }
+
+                       protected override MethodInfo DelegateMethodInfo {
+                               get {
+                                       return TypeManager.delegate_combine_delegate_delegate;
+                               }
+                       }
+               }
+
+               sealed class RemoveDelegateMethod: EventFieldAccessor
+               {
+                       public RemoveDelegateMethod (Event method):
+                               base (method, "remove_")
+                       {
+                       }
+
+                       protected override MethodInfo DelegateMethodInfo {
+                               get {
+                                       return TypeManager.delegate_remove_delegate_delegate;
+                               }
+                       }
+               }
+
+
+               static readonly string[] attribute_targets = new string [] { "event", "field", "method" };
+               static readonly string[] attribute_targets_interface = new string[] { "event", "method" };
+
+               public FieldBuilder FieldBuilder;
+               public Expression Initializer;
 
                public EventField (DeclSpace parent, Expression type, int mod_flags,
                                   bool is_iface, MemberName name,
@@ -6458,8 +7183,10 @@ namespace Mono.CSharp {
                        }
 
                        if (a.Target == AttributeTargets.Method) {
+                               int errors = Report.Errors;
                                Add.ApplyAttributeBuilder (a, cb);
-                               Remove.ApplyAttributeBuilder (a, cb);
+                               if (errors == Report.Errors)
+                                       Remove.ApplyAttributeBuilder (a, cb);
                                return;
                        }
 
@@ -6471,86 +7198,66 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
-                       if (initializer != null) {
+                       if (IsInterface)
+                               return true;
+
+                       // FIXME: We are unable to detect whether generic event is used because
+                       // we are using FieldExpr instead of EventExpr for event access in that
+                       // case.  When this issue will be fixed this hack can be removed.
+                       if (TypeManager.IsGenericType (MemberType))
+                               SetMemberIsUsed();
+
+                       FieldBuilder = Parent.TypeBuilder.DefineField (
+                               Name, MemberType,
+                               FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
+                       TypeManager.RegisterEventField (EventBuilder, this);
+
+                       if (Initializer != null) {
                                if (((ModFlags & Modifiers.ABSTRACT) != 0)) {
                                        Report.Error (74, Location, "`{0}': abstract event cannot have an initializer",
                                                GetSignatureForError ());
                                        return false;
                                }
+
+                               Parent.PartialContainer.RegisterFieldForInitialization (this,
+                                       new FieldInitializer (FieldBuilder, Initializer));
                        }
 
                        return true;
                }
 
-               public override string[] ValidAttributeTargets {
+               public override string[] ValidAttributeTargets 
+               {
                        get {
                                return IsInterface ? attribute_targets_interface : attribute_targets;
                        }
                }
        }
 
-       public abstract class Event : FieldBase {
-
-               protected sealed class AddDelegateMethod: DelegateMethod
-               {
-
-                       public AddDelegateMethod (Event method):
-                               base (method, "add_")
-                       {
-                       }
-
-                       public AddDelegateMethod (Event method, Accessor accessor):
-                               base (method, accessor, "add_")
-                       {
-                       }
-
-                       protected override MethodInfo DelegateMethodInfo {
-                               get {
-                                       return TypeManager.delegate_combine_delegate_delegate;
-                               }
-                       }
-
-               }
-
-               protected sealed class RemoveDelegateMethod: DelegateMethod
-               {
-                       public RemoveDelegateMethod (Event method):
-                               base (method, "remove_")
-                       {
-                       }
-
-                       public RemoveDelegateMethod (Event method, Accessor accessor):
-                               base (method, accessor, "remove_")
-                       {
-                       }
-
-                       protected override MethodInfo DelegateMethodInfo {
-                               get {
-                                       return TypeManager.delegate_remove_delegate_delegate;
-                               }
-                       }
-
-               }
-
-               public abstract class DelegateMethod : AbstractPropertyEventMethod
+       public abstract class Event : PropertyBasedMember {
+               public abstract class AEventAccessor : AbstractPropertyEventMethod
                {
                        protected readonly Event method;
                        ImplicitParameter param_attr;
 
-                       static string[] attribute_targets = new string [] { "method", "param", "return" };
+                       static readonly string[] attribute_targets = new string [] { "method", "param", "return" };
 
-                       public DelegateMethod (Event method, string prefix)
+                       protected AEventAccessor (Event method, string prefix)
                                : base (method, prefix)
                        {
                                this.method = method;
                        }
 
-                       public DelegateMethod (Event method, Accessor accessor, string prefix)
+                       protected AEventAccessor (Event method, Accessor accessor, string prefix)
                                : base (method, accessor, prefix)
                        {
                                this.method = method;
                        }
 
+                       public override Iterator Iterator {
+                               get { return null; }
+                       }
+
                        protected override void ApplyToExtraTarget(Attribute a, CustomAttributeBuilder cb)
                        {
                                if (a.Target == AttributeTargets.Parameter) {
@@ -6575,7 +7282,7 @@ namespace Mono.CSharp {
                                return method.IsClsComplianceRequired ();
                        }
 
-                       public MethodBuilder Define (DeclSpace parent)
+                       public virtual MethodBuilder Define (DeclSpace parent)
                        {
                                method_data = new MethodData (method, method.ModFlags,
                                        method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
@@ -6588,39 +7295,6 @@ namespace Mono.CSharp {
                                return mb;
                        }
 
-
-                       protected override void EmitMethod (DeclSpace parent)
-                       {
-                               if (block != null) {
-                                       base.EmitMethod (parent);
-                                       return;
-                               }
-
-                               if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
-                                       return;
-
-                               ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
-                               FieldInfo field_info = (FieldInfo)method.FieldBuilder;
-
-                               method_data.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Synchronized);
-                               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);
-                       }
-
                        protected abstract MethodInfo DelegateMethodInfo { get; }
 
                        public override Type ReturnType {
@@ -6631,7 +7305,7 @@ namespace Mono.CSharp {
 
                        public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                        {
-                               return new EmitContext (method,
+                               return new EmitContext (
                                        ds, method.Parent, Location, ig, ReturnType,
                                        method.ModFlags, false);
                        }
@@ -6652,7 +7326,6 @@ namespace Mono.CSharp {
                                        return method.parameters;
                                }
                        }
-
                }
 
 
@@ -6667,23 +7340,24 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.OVERRIDE |
                        Modifiers.UNSAFE |
-                       Modifiers.ABSTRACT;
+                       Modifiers.ABSTRACT |
+                       Modifiers.EXTERN;
 
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
-               public DelegateMethod Add, Remove;
+               public AEventAccessor Add, Remove;
                public MyEventBuilder     EventBuilder;
                public MethodBuilder AddBuilder, RemoveBuilder;
+
                Parameters parameters;
 
                protected Event (DeclSpace parent, Expression type, int mod_flags,
                              bool is_iface, MemberName name, Attributes attrs)
-                       : base (parent, type, mod_flags,
-                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+                       : base (parent, null, type, mod_flags,
+                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers, is_iface,
                                name, attrs)
                {
-                       IsInterface = is_iface;
                }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
@@ -6709,8 +7383,8 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
-                       EventAttributes e_attr;
-                       e_attr = EventAttributes.None;
+                       if (!DoDefineBase ())
+                               return false;
 
                        if (!DoDefine ())
                                return false;
@@ -6739,40 +7413,12 @@ namespace Mono.CSharp {
                        if (RemoveBuilder == null)
                                return false;
 
-                       EventBuilder = new MyEventBuilder (this, Parent.TypeBuilder, Name, e_attr, MemberType);
-                       
-                       if (Add.Block == null && Remove.Block == null && !IsInterface) {
-                               FieldBuilder = Parent.TypeBuilder.DefineField (
-                                       Name, MemberType,
-                                       FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
-                               TypeManager.RegisterPrivateFieldOfEvent (
-                                       (EventInfo) EventBuilder, FieldBuilder);
-                               TypeManager.RegisterFieldBase (FieldBuilder, this);
-                       }
-                       
+                       EventBuilder = new MyEventBuilder (this, Parent.TypeBuilder, Name, EventAttributes.None, MemberType);                                           
                        EventBuilder.SetAddOnMethod (AddBuilder);
                        EventBuilder.SetRemoveOnMethod (RemoveBuilder);
-
-                       TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder);
                        return true;
                }
 
-               protected override bool CheckBase ()
-               {
-                       if (!base.CheckBase ())
-                               return false;
-                       if (conflict_symbol != null && (ModFlags & Modifiers.NEW) == 0) {
-                               if (!(conflict_symbol is EventInfo)) {
-                                       Report.SymbolRelatedToPreviousError (conflict_symbol);
-                                       Report.Error (72, Location, "Event `{0}' can override only event", GetSignatureForError ());
-                                       return false;
-                               }
-                       }
-                       return true;
-               }
-
                public override void Emit ()
                {
                        if (OptAttributes != null) {
@@ -6785,9 +7431,17 @@ namespace Mono.CSharp {
                        base.Emit ();
                }
 
-               public override string GetSignatureForError ()
+               protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
-                       return base.GetSignatureForError ();
+                       MethodInfo mi = (MethodInfo) Parent.PartialContainer.BaseCache.FindBaseEvent (
+                               Parent.TypeBuilder, Name);
+
+                       if (mi == null)
+                               return null;
+
+                       ParameterData pd = TypeManager.GetParameterData (mi);
+                       base_ret_type = pd.ParameterType (0);
+                       return mi;
                }
 
                //
@@ -6798,43 +7452,43 @@ namespace Mono.CSharp {
                }
        }
 
-
        public class Indexer : PropertyBase {
 
                class GetIndexerMethod : GetMethod
                {
-                       public GetIndexerMethod (MethodCore method):
+                       public GetIndexerMethod (PropertyBase method):
                                base (method)
                        {
                        }
 
-                       public GetIndexerMethod (MethodCore method, Accessor accessor):
+                       public GetIndexerMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor)
                        {
                        }
 
                        public override Parameters ParameterInfo {
                                get {
-                                       return method.ParameterInfo;
+                                       return ((Indexer)method).parameters;
                                }
                        }
                }
 
                class SetIndexerMethod: SetMethod
                {
-                       public SetIndexerMethod (MethodCore method):
+                       public SetIndexerMethod (PropertyBase method):
                                base (method)
                        {
                        }
 
-                       public SetIndexerMethod (MethodCore method, Accessor accessor):
+                       public SetIndexerMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor)
                        {
                        }
 
                        protected override void DefineParameters ()
                        {
-                               parameters = Parameters.MergeGenerated (method.Parameters,
+                               parameters = Parameters.MergeGenerated (((Indexer)method).parameters,
                                        new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location));
                        }
                }
@@ -6855,14 +7509,17 @@ namespace Mono.CSharp {
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
+               public readonly Parameters parameters;
 
                public Indexer (DeclSpace parent, Expression type, MemberName name, int mod,
                                bool is_iface, Parameters parameters, Attributes attrs,
-                               Accessor get_block, Accessor set_block)
+                               Accessor get_block, Accessor set_block, bool define_set_first)
                        : base (parent, type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
-                               is_iface, name, parameters, attrs)
+                               is_iface, name, attrs, define_set_first)
                {
+                       this.parameters = parameters;
+
                        if (get_block == null)
                                Get = new GetIndexerMethod (this);
                        else
@@ -6873,12 +7530,64 @@ namespace Mono.CSharp {
                        else
                                Set = new SetIndexerMethod (this, set_block);
                }
-                      
+               
+               protected override bool CheckForDuplications ()
+               {
+                       ArrayList ar = Parent.PartialContainer.Indexers;
+                       if (ar != null) {
+                               int arLen = ar.Count;
+                                       
+                               for (int i = 0; i < arLen; i++) {
+                                       Indexer m = (Indexer) ar [i];
+                                       if (IsDuplicateImplementation (m))
+                                               return false;
+                               }
+                       }
+
+                       return true;
+               }
+
+               bool IsDuplicateImplementation (Indexer indexer)
+               {
+                       if (this == indexer)
+                               return false;
+
+                       if (!MemberName.Equals (indexer.MemberName))
+                               return false;
+
+                       Type[] param_types = indexer.parameters.Types;
+
+                       // When it is not yet defined
+                       if (param_types == null)
+                               return false;
+
+                       if (param_types.Length != parameters.Count)
+                               return false;
+
+                       for (int i = 0; i < param_types.Length; i++)
+                               if (param_types [i] != parameters.Types [i])
+                                       return false;
+
+                       Report.SymbolRelatedToPreviousError (indexer);
+                       Report.Error (111, Location, TypeContainer.Error111, indexer.GetSignatureForError ());
+                       return true;
+               }
+
+
                public override bool Define ()
                {
+                       if (!DoDefineBase ())
+                               return false;
+
                        if (!base.Define ())
                                return false;
 
+                       if (!parameters.Resolve (ds))
+                               return false;
+
+                       if (!CheckParameters (parameters))
+                               return false;
+
                        if (MemberType == TypeManager.void_type) {
                                Report.Error (620, Location, "Indexers cannot have void type");
                                return false;
@@ -6917,40 +7626,41 @@ namespace Mono.CSharp {
                                        ShortName = base_IndexerName;
                        }
 
-                       if (!ParentContainer.AddToMemberContainer (this) ||
-                               !ParentContainer.AddToMemberContainer (Get) || !ParentContainer.AddToMemberContainer (Set))
+                       if (!Parent.PartialContainer.AddMember (this) ||
+                               !Parent.PartialContainer.AddMember (Get) || !Parent.PartialContainer.AddMember (Set))
                                return false;
 
                        if (!CheckBase ())
                                return false;
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
-                       if (!Get.IsDummy){
-                               GetBuilder = Get.Define (Parent);
-                               if (GetBuilder == null)
-                                       return false;
-                       }
                        
-                       SetBuilder = Set.Define (Parent);
-                       if (!Set.IsDummy){
-                               if (SetBuilder == null)
-                                       return false;
+                       if (!DefineAccessors ())
+                               return false;
+
+                       if (!Get.IsDummy) {
+                               // Setup iterator if we are one
+                               if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
+                                       Iterator iterator = Iterator.CreateIterator (Get, Parent, null, ModFlags);
+                                       if (iterator == null)
+                                               return false;
+                               }
                        }
 
                        //
                        // Now name the parameters
                        //
-                       Parameter [] p = Parameters.FixedParameters;
+                       Parameter [] p = parameters.FixedParameters;
                        if (p != null) {
                                // TODO: should be done in parser and it needs to do cycle
                                if ((p [0].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
-                                       Report.Error (631, Location, "ref and out are not valid in this context");
+                                       CSharpParser.Error_ParameterModifierNotValid (Location);
                                        return false;
                                }
                        }
 
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
-                               Name, PropertyAttributes.None, MemberType, ParameterTypes);
+                               Name, PropertyAttributes.None, MemberType, parameters.Types);
                        
                        if (!Get.IsDummy)
                                PropertyBuilder.SetGetMethod (GetBuilder);
@@ -6958,11 +7668,16 @@ namespace Mono.CSharp {
                        if (!Set.IsDummy)
                                PropertyBuilder.SetSetMethod (SetBuilder);
                                
-                       TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder, ParameterTypes);
+                       TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder, parameters.Types);
 
                        return true;
                }
 
+               public override string GetDocCommentName (DeclSpace ds)
+               {
+                       return DocUtil.GetMethodDocCommentName (this, parameters, ds);
+               }
+
                public override string GetSignatureForError ()
                {
                        StringBuilder sb = new StringBuilder (Parent.GetSignatureForError ());
@@ -6972,7 +7687,7 @@ namespace Mono.CSharp {
                        }
 
                        sb.Append (".this");
-                       sb.Append (Parameters.GetSignatureForError ().Replace ('(', '[').Replace (')', ']'));
+                       sb.Append (parameters.GetSignatureForError ().Replace ('(', '[').Replace (')', ']'));
                        return sb.ToString ();
                }
 
@@ -6981,9 +7696,24 @@ namespace Mono.CSharp {
                        caching_flags |= Flags.TestMethodDuplication;
                        return true;
                }
+
+               protected override PropertyInfo ResolveBaseProperty ()
+               {
+                       return Parent.PartialContainer.BaseCache.FindMemberToOverride (
+                               Parent.TypeBuilder, Name, parameters.Types, null, true) as PropertyInfo;
+               }
+
+               protected override bool VerifyClsCompliance ()
+               {
+                       if (!base.VerifyClsCompliance ())
+                               return false;
+
+                       parameters.VerifyClsCompliance ();
+                       return true;
+               }
        }
 
-       public class Operator : MethodOrOperator, IIteratorContainer {
+       public class Operator : MethodOrOperator, IAnonymousHost {
 
                const int AllowedModifiers =
                        Modifiers.PUBLIC |
@@ -7037,8 +7767,8 @@ namespace Mono.CSharp {
                public Operator (DeclSpace parent, OpType type, Expression ret_type,
                                 int mod_flags, Parameters parameters,
                                 ToplevelBlock block, Attributes attrs, Location loc)
-                       : base (parent, ret_type, mod_flags, AllowedModifiers, false,
-                               new MemberName ("op_" + type, loc), attrs, parameters)
+                       : base (parent, null, ret_type, mod_flags, AllowedModifiers, false,
+                               new MemberName ("op_" + type.ToString(), loc), attrs, parameters)
                {
                        OperatorType = type;
                        Block = block;
@@ -7056,7 +7786,7 @@ namespace Mono.CSharp {
                
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = ParentContainer.Operators;
+                       ArrayList ar = Parent.PartialContainer.Operators;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -7067,7 +7797,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Methods;
+                       ar = Parent.PartialContainer.Methods;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -7089,6 +7819,10 @@ namespace Mono.CSharp {
                                return false;
                        }
 
+                       // imlicit and explicit operator of same types are not allowed
+                       if (OperatorType == OpType.Explicit || OperatorType == OpType.Implicit)
+                               MarkForDuplicationCheck ();
+
                        if (!base.Define ())
                                return false;
 
@@ -7097,7 +7831,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       Type declaring_type = MethodBuilder.DeclaringType;
+                       Type declaring_type = MethodData.DeclaringType;
                        Type return_type = MemberType;
                        Type first_arg_type = ParameterTypes [0];
 
@@ -7110,7 +7844,9 @@ namespace Mono.CSharp {
                                        return false;
                                }
                                
-                               if (first_arg_type != declaring_type && return_type != declaring_type){
+                               if ((first_arg_type != declaring_type) && (return_type != declaring_type) &&
+                                   !TypeManager.IsNullableTypeOf (first_arg_type, declaring_type) &&
+                                   !TypeManager.IsNullableTypeOf (return_type, declaring_type)) {
                                        Report.Error (
                                                556, Location, 
                                                "User-defined conversion must convert to or from the " +
@@ -7143,7 +7879,7 @@ namespace Mono.CSharp {
                                // Checks for Unary operators
 
                                if (OperatorType == OpType.Increment || OperatorType == OpType.Decrement) {
-                                       if (return_type != declaring_type && !return_type.IsSubclassOf (declaring_type)) {
+                                       if (return_type != declaring_type && !TypeManager.IsSubclassOf (return_type, declaring_type)) {
                                                Report.Error (448, Location,
                                                        "The return type for ++ or -- operator must be the containing type or derived from the containing type");
                                                return false;