* tree.cs (Tree.RecordDecl): Remove.
[mono.git] / mcs / mcs / class.cs
index c1f0c450f76d4645018d38cf95313e50bded452c..eeb2353b13ba099188eb4c964ae90ef9f6a0817e 100644 (file)
@@ -72,7 +72,12 @@ namespace Mono.CSharp {
                        public virtual void DefineContainerMembers ()
                        {
                                foreach (MemberCore mc in this) {
-                                       mc.Define ();
+                                       try {
+                                               mc.Define ();
+                                       }
+                                       catch (Exception e) {
+                                               throw new InternalErrorException (mc.Location, mc.GetSignatureForError (), e);
+                                       }
                                }
                        }
 
@@ -232,8 +237,8 @@ namespace Mono.CSharp {
                                {
                                        flags = f;
 
-                                       ret_type = o.OperatorMethod.ReturnType;
-                                       Type [] pt = o.OperatorMethod.ParameterTypes;
+                                       ret_type = o.MemberType;
+                                       Type [] pt = o.ParameterTypes;
                                        type1 = pt [0];
                                        type2 = pt [1];
                                        op = o;
@@ -280,7 +285,7 @@ namespace Mono.CSharp {
                                        int reg = 0;
 
                                        // Skip erroneous code.
-                                       if (op.OperatorMethod == null)
+                                       if (op.MethodBuilder == null)
                                                continue;
 
                                        switch (op.OperatorType){
@@ -388,7 +393,7 @@ namespace Mono.CSharp {
                public readonly Kind Kind;
 
                // Holds a list of classes and structures
-               ArrayList types;
+               protected ArrayList types;
 
                // Holds the list of properties
                MemberCoreArrayList properties;
@@ -432,9 +437,6 @@ namespace Mono.CSharp {
                // Holds the iterators
                ArrayList iterators;
 
-               // Holds the parts of a partial class;
-               ArrayList parts;
-
                //
                // Pointers to the default constructor and the default static constructor
                //
@@ -453,7 +455,6 @@ namespace Mono.CSharp {
                // This one is computed after we can distinguish interfaces
                // from classes from the arraylist `type_bases' 
                //
-               string base_class_name;
                TypeExpr base_type;
                TypeExpr[] iface_exprs;
 
@@ -464,7 +465,6 @@ namespace Mono.CSharp {
 
                // The interfaces we implement.
                protected Type[] ifaces;
-               protected Type ptype;
 
                // The base member cache and our member cache
                MemberCache base_cache;
@@ -472,7 +472,16 @@ namespace Mono.CSharp {
 
                public const string DefaultIndexerName = "Item";
 
-               public TypeContainer (NamespaceEntry ns, TypeContainer parent, MemberName name,
+               public TypeContainer PartialContainer;
+               ArrayList partial_parts;
+
+               /// <remarks>
+               ///  The pending methods that need to be implemented
+               //   (interfaces or abstract methods)
+               /// </remarks>
+               PendingImplementation pending;
+
+               public TypeContainer (NamespaceEntry ns, DeclSpace parent, MemberName name,
                                      Attributes attrs, Kind kind)
                        : base (ns, parent, name, attrs)
                {
@@ -480,10 +489,7 @@ namespace Mono.CSharp {
                                throw new InternalErrorException ("A nested type should be in the same NamespaceEntry as its enclosing class");
 
                        this.Kind = kind;
-
-                       types = new ArrayList ();
-
-                       base_class_name = null;
+                       this.PartialContainer = this;
                }
 
                public bool AddToMemberContainer (MemberCore symbol)
@@ -523,10 +529,71 @@ namespace Mono.CSharp {
                        if (!AddToTypeContainer (c))
                                return false;
 
+                       if (types == null)
+                               types = new ArrayList (2);
+
                        types.Add (c);
                        return true;
                }
 
+               public virtual TypeContainer AddPartial (TypeContainer nextPart)
+               {
+                       return AddPartial (nextPart, nextPart.Basename);
+               }
+
+               protected TypeContainer AddPartial (TypeContainer nextPart, string name)
+               {
+                       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.ModFlags & Modifiers.PARTIAL) == 0) {
+                               Report.SymbolRelatedToPreviousError (tc);
+                               Error_MissingPartialModifier (nextPart);
+                               return tc;
+                       }
+
+                       if (tc.Kind != nextPart.Kind) {
+                               Report.SymbolRelatedToPreviousError (tc);
+                               Report.Error (261, nextPart.Location,
+                                       "Partial declarations of `{0}' must be all classes, all structs or all interfaces",
+                                       nextPart.GetSignatureForError ());
+                               return tc;
+                       }
+
+                       if ((tc.ModFlags & Modifiers.Accessibility) != (nextPart.ModFlags & Modifiers.Accessibility) &&
+                               ((tc.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) == 0 &&
+                                (nextPart.ModFlags & Modifiers.DEFAULT_ACCESS_MODIFER) == 0)) {
+                               Report.SymbolRelatedToPreviousError (tc);
+                               Report.Error (262, nextPart.Location,
+                                       "Partial declarations of `{0}' have conflicting accessibility modifiers",
+                                       nextPart.GetSignatureForError ());
+                               return tc;
+                       }
+
+                       if (tc.partial_parts == null)
+                               tc.partial_parts = new ArrayList (1);
+
+                       tc.ModFlags |= nextPart.ModFlags;
+                       if (nextPart.attributes != null) {
+                               if (tc.attributes == null)
+                                       tc.attributes = nextPart.attributes;
+                               else
+                                       tc.attributes.AddAttributes (nextPart.attributes.Attrs);
+                       }
+
+                       nextPart.PartialContainer = tc;
+                       tc.partial_parts.Add (nextPart);
+                       return tc;
+               }
+
                public void AddDelegate (Delegate d)
                {
                        if (!AddToTypeContainer (d))
@@ -534,7 +601,7 @@ namespace Mono.CSharp {
 
                        if (delegates == null)
                                delegates = new MemberCoreArrayList ();
-                       
+
                        delegates.Add (d);
                }
 
@@ -552,6 +619,22 @@ namespace Mono.CSharp {
                                methods.Add (method);
                }
 
+               //
+               // Do not use this method: use AddMethod.
+               //
+               // This is only used by iterators.
+               //
+               public void AppendMethod (Method method)
+               {
+                       if (!AddToMemberContainer (method))
+                               return;
+
+                       if (methods == null)
+                               methods = new MethodArrayList (this);
+
+                       methods.Add (method);
+               }
+
                public void AddConstructor (Constructor c)
                {
                        if (c.Name != Basename)  {
@@ -569,7 +652,7 @@ namespace Mono.CSharp {
 
                                default_static_constructor = c;
                        } else {
-                               if (c.IsDefault ()){
+                               if (c.Parameters.Empty){
                                        if (default_constructor != null) {
                                                Report.SymbolRelatedToPreviousError (default_constructor);
                                                Report.Error (111, c.Location, Error111, c.GetSignatureForError ());
@@ -596,9 +679,8 @@ namespace Mono.CSharp {
                        if (!AddToTypeContainer (iface))
                                return false;
 
-                       if (interfaces == null) {
+                       if (interfaces == null)
                                interfaces = new MemberCoreArrayList ();
-                       }
 
                        interfaces.Add (iface);
                        return true;
@@ -614,9 +696,6 @@ namespace Mono.CSharp {
 
                        fields.Add (field);
 
-                       if (field.HasInitializer)
-                               RegisterFieldForInitialization (field);
-                       
                        if ((field.ModFlags & Modifiers.STATIC) != 0)
                                return;
 
@@ -669,7 +748,6 @@ namespace Mono.CSharp {
                        events.Add (e);
                }
 
-
                /// <summary>
                /// Indexer has special handling in constrast to other AddXXX because the name can be driven by IndexerNameAttribute
                /// </summary>
@@ -703,19 +781,6 @@ namespace Mono.CSharp {
                        iterators.Add (i);
                }
 
-               public void AddType (TypeContainer tc)
-               {
-                       types.Add (tc);
-               }
-
-               public void AddPart (ClassPart part)
-               {
-                       if (parts == null)
-                               parts = new ArrayList ();
-
-                       parts.Add (part);
-               }
-
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
                        if (a.Type == TypeManager.default_member_type) {
@@ -730,16 +795,7 @@ namespace Mono.CSharp {
 
                public override AttributeTargets AttributeTargets {
                        get {
-                               switch (Kind) {
-                               case Kind.Class:
-                                       return AttributeTargets.Class;
-                               case Kind.Struct:
-                                       return AttributeTargets.Struct;
-                               case Kind.Interface:
-                                       return AttributeTargets.Interface;
-                               default:
-                                       throw new NotSupportedException ();
-                               }
+                               throw new NotSupportedException ();
                        }
                }
 
@@ -772,10 +828,10 @@ namespace Mono.CSharp {
                                return iterators;
                        }
                }
-               
-               public string Base {
+
+               protected Type BaseType {
                        get {
-                               return base_class_name;
+                               return TypeBuilder.BaseType;
                        }
                }
                
@@ -836,16 +892,10 @@ namespace Mono.CSharp {
                                return delegates;
                        }
                }
-
-               public ArrayList Parts {
-                       get {
-                               return parts;
-                       }
-               }
-
+               
                protected override TypeAttributes TypeAttr {
                        get {
-                               return Modifiers.TypeAttr (ModFlags, this) | base.TypeAttr;
+                               return Modifiers.TypeAttr (ModFlags, IsTopLevel) | base.TypeAttr;
                        }
                }
 
@@ -860,179 +910,82 @@ namespace Mono.CSharp {
                                if (OptAttributes == null)
                                        return false;
 
-                               return OptAttributes.Contains (TypeManager.comimport_attr_type, EmitContext);
+                               return OptAttributes.Contains (TypeManager.comimport_attr_type);
                        }
                }
 
-               public virtual void RegisterFieldForInitialization (FieldMember field)
+               public virtual void RegisterFieldForInitialization (FieldBase field)
                {
                        if ((field.ModFlags & Modifiers.STATIC) != 0){
                                if (initialized_static_fields == null)
-                                       initialized_static_fields = new ArrayList ();
+                                       initialized_static_fields = new ArrayList (4);
 
                                initialized_static_fields.Add (field);
                        } else {
                                if (initialized_fields == null)
-                                       initialized_fields = new ArrayList ();
+                                       initialized_fields = new ArrayList (4);
 
                                initialized_fields.Add (field);
                        }
                }
 
-               bool CanElideInitializer (Type field_type, Constant c)
-               {
-                       if (field_type == c.Type)
-                               return true;
-                       if (TypeManager.IsValueType (field_type) || TypeManager.HasElementType (field_type))
-                               return false;
-                       // Reference type with null initializer.
-                       return c.Type == TypeManager.null_type;
-               }
-
                //
                // Emits the instance field initializers
                //
-               public virtual bool EmitFieldInitializers (EmitContext ec)
+               public bool EmitFieldInitializers (EmitContext ec)
                {
                        ArrayList fields;
-                       Expression instance_expr;
                        
                        if (ec.IsStatic){
                                fields = initialized_static_fields;
-                               instance_expr = null;
                        } else {
                                fields = initialized_fields;
-                               instance_expr = new This (Location.Null).Resolve (ec);
                        }
 
                        if (fields == null)
                                return true;
 
-                       foreach (FieldMember f in fields){
-                               Expression e = f.GetInitializerExpression (ec);
-                               if (e == null)
-                                       return false;
-
-                               Location l = f.Location;
-                               FieldExpr fe = new FieldExpr (f.FieldBuilder, l, true);
-                               fe.InstanceExpression = instance_expr;
-                               ExpressionStatement a = new Assign (fe, e, l);
-
-                               a = a.ResolveStatement (ec);
-                               if (a == null)
-                                       return false;
-
-                               Constant c = e as Constant;
-                               if (c != null && c.IsDefaultValue && CanElideInitializer (f.MemberType, c))
-                                       continue;
-
-                               a.EmitStatement (ec);
+                       foreach (FieldBase f in fields) {
+                               f.EmitInitializer (ec);
                        }
-
                        return true;
                }
                
-               //
-               // Defines the default constructors
-               //
-               protected void DefineDefaultConstructor (bool is_static)
-               {
-                       Constructor c;
-
-                       // The default constructor is public
-                       // If the class is abstract, the default constructor is protected
-                       // The default static constructor is private
-
-                       int mods = Modifiers.PUBLIC;
-                       if (is_static)
-                               mods = Modifiers.STATIC | Modifiers.PRIVATE;
-                       else if ((ModFlags & Modifiers.ABSTRACT) != 0)
-                               mods = Modifiers.PROTECTED;
-
-                       TypeContainer constructor_parent = this;
-                       if (Parts != null)
-                               constructor_parent = (TypeContainer) Parts [0];
+               public override string DocComment {
+                       get {
+                               return comment;
+                       }
+                       set {
+                               if (value == null)
+                                       return;
 
-                       c = new Constructor (constructor_parent, Basename, mods,
-                                            Parameters.EmptyReadOnlyParameters,
-                                            new GeneratedBaseInitializer (Location),
-                                            Location);
-                       
-                       AddConstructor (c);
-                       
-                       c.Block = new ToplevelBlock (null, Location);
-                       
+                               comment += value;
+                       }
                }
 
-               /// <remarks>
-               ///  The pending methods that need to be implemented
-               //   (interfaces or abstract methods)
-               /// </remarks>
-               public PendingImplementation Pending;
-
-               public abstract PendingImplementation GetPendingImplementations ();
+               public PendingImplementation PendingImplementations {
+                       get { return pending; }
+               }
 
-               TypeExpr[] GetPartialBases (out TypeExpr base_class)
+               public override bool GetClsCompliantAttributeValue ()
                {
-                       ArrayList ifaces = new ArrayList ();
-
-                       base_class = null;
-
-                       foreach (ClassPart part in parts) {
-                               TypeExpr new_base_class;
-                               TypeExpr[] new_ifaces;
-
-                               new_ifaces = part.GetClassBases (out new_base_class);
-                               if (new_ifaces == null && new_base_class != null)
-                                       return null;
-
-                               if ((base_class != null) && (new_base_class != null) &&
-                                   !base_class.Equals (new_base_class)) {
-                                       Report.SymbolRelatedToPreviousError (base_class.Location, "");
-                                       Report.Error (263, part.Location,
-                                                     "Partial declarations of `{0}' must " +
-                                                     "not specify different base classes",
-                                                     Name);
-
-                                       return null;
-                               }
-
-                               if ((base_class == null) && (new_base_class != null)) {
-                                       base_class = new_base_class;
-                               }
-
-                               if (new_ifaces == null)
-                                       continue;
-
-                               foreach (TypeExpr iface in new_ifaces) {
-                                       bool found = false;
-                                       foreach (TypeExpr old_iface in ifaces) {
-                                               if (old_iface.Equals (iface)) {
-                                                       found = true;
-                                                       break;
-                                               }
-                                       }
-
-                                       if (!found)
-                                               ifaces.Add (iface);
-                               }
-                       }
+                       if (PartialContainer != this)
+                               return PartialContainer.GetClsCompliantAttributeValue ();
 
-                       TypeExpr[] retval = new TypeExpr [ifaces.Count];
-                       ifaces.CopyTo (retval, 0);
-                       return retval;
+                       return base.GetClsCompliantAttributeValue ();
                }
 
                TypeExpr[] GetNormalBases (out TypeExpr base_class)
                {
                        base_class = null;
+                       if (Bases == null)
+                               return null;
 
                        int count = Bases.Count;
                        int start = 0, i, j;
 
                        if (Kind == Kind.Class){
-                               TypeExpr name = ResolveBaseTypeExpr (
-                                       (Expression) Bases [0], false, Location);
+                               TypeExpr name = ((Expression) Bases [0]).ResolveAsBaseTerminal (this, false);
 
                                if (name == null){
                                        return null;
@@ -1049,7 +1002,7 @@ namespace Mono.CSharp {
                        TypeExpr [] ifaces = new TypeExpr [count-start];
                        
                        for (i = start, j = 0; i < count; i++, j++){
-                               TypeExpr resolved = ResolveBaseTypeExpr ((Expression) Bases [i], false, Location);
+                               TypeExpr resolved = ((Expression) Bases [i]).ResolveAsTypeTerminal (this, false);
                                if (resolved == null) {
                                        return null;
                                }
@@ -1057,7 +1010,49 @@ namespace Mono.CSharp {
                                ifaces [j] = resolved;
                        }
 
-                       return ifaces;
+                       return ifaces.Length == 0 ? null : ifaces;
+               }
+
+
+               TypeExpr[] GetNormalPartialBases (ref TypeExpr base_class)
+               {
+                       ArrayList ifaces = new ArrayList (0);
+                       if (iface_exprs != null)
+                               ifaces.AddRange (iface_exprs);
+
+                       foreach (TypeContainer part in partial_parts) {
+                               TypeExpr new_base_class;
+                               TypeExpr[] new_ifaces = part.GetClassBases (out new_base_class);
+                               if (new_base_class != TypeManager.system_object_expr) {
+                                       if (base_class == TypeManager.system_object_expr)
+                                               base_class = new_base_class;
+                                       else {
+                                               if (new_base_class != null && !new_base_class.Equals (base_class)) {
+                                                       Report.SymbolRelatedToPreviousError (base_class.Location, "");
+                                                       Report.Error (263, part.Location,
+                                                               "Partial declarations of `{0}' must not specify different base classes",
+                                                               part.GetSignatureForError ());
+
+                                                       return null;
+                                               }
+                                       }
+                               }
+
+                               if (new_ifaces == null)
+                                       continue;
+
+                               foreach (TypeExpr iface in new_ifaces) {
+                                       if (ifaces.Contains (iface))
+                                               continue;
+
+                                       ifaces.Add (iface);
+                               }
+                       }
+
+                       if (ifaces.Count == 0)
+                               return null;
+
+                       return (TypeExpr[])ifaces.ToArray (typeof (TypeExpr));
                }
 
                /// <summary>
@@ -1070,64 +1065,16 @@ namespace Mono.CSharp {
                ///   The @base_class argument is set to the base object or null
                ///   if this is `System.Object'. 
                /// </summary>
-               TypeExpr [] GetClassBases (out TypeExpr base_class)
+               public virtual TypeExpr [] GetClassBases (out TypeExpr base_class)
                {
-                       int i;
-
-                       TypeExpr[] ifaces;
-
-                       if (parts != null)
-                               ifaces = GetPartialBases (out base_class);
-                       else if (Bases == null){
-                               base_class = null;
-                               return null;
-                       } else
-                               ifaces = GetNormalBases (out base_class);
-
-                       if (ifaces == null)
-                               return null;
-
-                       if ((base_class != null) && (Kind == Kind.Class)){
-
-                               if (base_class.Type.IsArray || base_class.Type.IsPointer) {
-                                       Report.Error (1521, base_class.Location, "Invalid base type");
-                                       return null;
-                               }
-
-                               if (base_class.IsSealed){
-                                       Report.SymbolRelatedToPreviousError (base_class.Type);
-                                       if (base_class.Type.IsAbstract) {
-                                               Report.Error (709, Location, "`{0}': Cannot derive from static class `{1}'",
-                                                       GetSignatureForError (), TypeManager.CSharpName (base_class.Type));
-                                       } else {
-                                               Report.Error (509, Location, "`{0}': cannot derive from sealed class `{1}'",
-                                                       GetSignatureForError (), TypeManager.CSharpName (base_class.Type));
-                                       }
-                                       return null;
-                               }
-
-                               if (!base_class.CanInheritFrom ()){
-                                       Report.Error (644, Location, "`{0}' cannot derive from special class `{1}'",
-                                                     GetSignatureForError (), base_class.GetSignatureForError ());
-                                       return null;
-                               }
-
-                               if (!base_class.AsAccessible (this, ModFlags)) {
-                                       Report.SymbolRelatedToPreviousError (base_class.Type);
-                                       Report.Error (60, Location, "Inconsistent accessibility: base class `{0}' is less accessible than class `{1}'", 
-                                               TypeManager.CSharpName (base_class.Type), GetSignatureForError ());
-                               }
-                       }
-
-                       if (base_class != null)
-                               base_class_name = base_class.Name;
+                       TypeExpr[] ifaces = GetNormalBases (out base_class);
 
                        if (ifaces == null)
                                return null;
 
-                       int count = ifaces != null ? ifaces.Length : 0;
+                       int count = ifaces.Length;
 
-                       for (i = 0; i < count; i++) {
+                       for (int i = 0; i < count; i++) {
                                TypeExpr iface = (TypeExpr) ifaces [i];
 
                                if (!iface.IsInterface) {
@@ -1149,7 +1096,7 @@ namespace Mono.CSharp {
                                        if (iface.Equals (ifaces [x])) {
                                                Report.Error (528, Location,
                                                              "`{0}' is already listed in " +
-                                                             "interface list", iface.Name);
+                                                             "interface list", iface.GetSignatureForError ());
                                                return null;
                                        }
                                }
@@ -1174,69 +1121,33 @@ namespace Mono.CSharp {
                        Report.Error (527, loc, "Type `{0}' in interface list is not an interface", type);
                }
 
-               //
-               // Defines the type in the appropriate ModuleBuilder or TypeBuilder.
-               //
-               public override TypeBuilder DefineType ()
+               bool DefineTypeBuilder ()
                {
-                       if (error)
-                               return null;
-
-                       if (TypeBuilder != null)
-                               return TypeBuilder;
-                       
-                       TypeAttributes type_attributes = TypeAttr;
-
                        try {
                                if (IsTopLevel){
                                        if (TypeManager.NamespaceClash (Name, Location)) {
-                                               error = true;
-                                               return null;
+                                               return false;
                                        }
 
                                        ModuleBuilder builder = CodeGen.Module.Builder;
                                        TypeBuilder = builder.DefineType (
-                                               Name, type_attributes, null, null);
+                                               Name, TypeAttr, null, null);
                                } else {
                                        TypeBuilder builder = Parent.TypeBuilder;
-                                       if (builder == null) {
-                                               error = true;
-                                               return null;
-                                       }
 
                                        TypeBuilder = builder.DefineNestedType (
-                                               Basename, type_attributes, ptype, null);
+                                               Basename, TypeAttr, null, null);
                                }
                        } catch (ArgumentException) {
                                Report.RuntimeMissingSupport (Location, "static classes");
-                               error = true;
-                               return null;
+                               return false;
                        }
 
                        TypeManager.AddUserType (this);
 
-                       if (Parts != null) {
-                               ec = null;
-                               foreach (ClassPart part in Parts) {
-                                       part.TypeBuilder = TypeBuilder;
-                                       part.ec = new EmitContext (part, Mono.CSharp.Location.Null, null, null, ModFlags);
-                                       part.ec.ContainerType = TypeBuilder;
-                               }
-                       } else {
-                               //
-                               // Normally, we create the EmitContext here.
-                               // The only exception is if we're an Iterator - in this case,
-                               // we already have the `ec', so we don't want to create a new one.
-                               //
-                               if (ec == null)
-                                       ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
-                               ec.ContainerType = TypeBuilder;
-                       }
-
                        iface_exprs = GetClassBases (out base_type);
-                       if (iface_exprs == null && base_type != null) {
-                               error = true;
-                               return null;
+                       if (partial_parts != null) {
+                               iface_exprs = GetNormalPartialBases (ref base_type);
                        }
 
                        //
@@ -1252,67 +1163,25 @@ namespace Mono.CSharp {
                        if (!(this is Iterator))
                                RootContext.RegisterOrder (this); 
 
-                       if (base_type == null) {
-                               if (Kind == Kind.Class){
-                                       if (RootContext.StdLib)
-                                               base_type = TypeManager.system_object_expr;
-                                       else if (Name != "System.Object")
-                                               base_type = TypeManager.system_object_expr;
-                               } else if (Kind == Kind.Struct) {
-                                       //
-                                       // If we are compiling our runtime,
-                                       // and we are defining ValueType, then our
-                                       // base is `System.Object'.
-                                       //
-                                       if (!RootContext.StdLib && Name == "System.ValueType")
-                                               base_type = TypeManager.system_object_expr;
-                                       else
-                                               base_type = TypeManager.system_valuetype_expr;
-                               }
-                       }
-
-                       if ((Kind == Kind.Struct) && TypeManager.value_type == null)
-                               throw new Exception ();
-
-                       // Avoid attributes check when parent is not set
-                       TypeResolveEmitContext.TestObsoleteMethodUsage = false;
 
                        if (base_type != null) {
-                               // FIXME: I think this should be ...ResolveType (Parent.EmitContext).
-                               //        However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
-                               ptype = base_type.ResolveType (TypeResolveEmitContext);
-                               if (ptype == null) {
-                                       error = true;
-                                       return null;
+                               TypeBuilder.SetParent (base_type.Type);
+
+                               ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
+                               if (obsolete_attr != null && !IsInObsoleteScope) {
+                                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
                                }
                        }
 
                        if (!CheckRecursiveDefinition (this)) {
-                               error = true;
-                               return null;
-                       }
-
-                       if (ptype != null) {
-                               TypeBuilder.SetParent (ptype);
-                       }
-
-                       // Attribute is undefined at the begining of corlib compilation
-                       if (TypeManager.obsolete_attribute_type != null) {
-                               TypeResolveEmitContext.TestObsoleteMethodUsage = GetObsoleteAttribute () == null;
-                               if (ptype != null && TypeResolveEmitContext.TestObsoleteMethodUsage) {
-                                       CheckObsoleteType (base_type);
-                               }
+                               return false;
                        }
 
                        // add interfaces that were not added at type creation
                        if (iface_exprs != null) {
-                               // FIXME: I think this should be ...ExpandInterfaces (Parent.EmitContext, ...).
-                               //        However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
-                               TypeResolveEmitContext.ContainerType = TypeBuilder;
-                               ifaces = TypeManager.ExpandInterfaces (TypeResolveEmitContext, iface_exprs);
+                               ifaces = TypeManager.ExpandInterfaces (iface_exprs);
                                if (ifaces == null) {
-                                       error = true;
-                                       return null;
+                                       return false;
                                }
 
                                foreach (Type itype in ifaces)
@@ -1321,14 +1190,35 @@ namespace Mono.CSharp {
                                TypeManager.RegisterBuilder (TypeBuilder, ifaces);
                        }
 
-                       if (!DefineNestedTypes ()) {
+                       return true;
+               }
+
+               //
+               // Defines the type in the appropriate ModuleBuilder or TypeBuilder.
+               //
+               public override TypeBuilder DefineType ()
+               {
+                       if (TypeBuilder != null)
+                               return TypeBuilder;
+
+                       if (error)
+                               return null;
+                       
+                       if (!DefineTypeBuilder ()) {
                                error = true;
                                return null;
                        }
 
-                       return TypeBuilder;
-               }
-
+                       if (partial_parts != null) {
+                               foreach (TypeContainer part in partial_parts)
+                                       part.TypeBuilder = TypeBuilder;
+                       }
+
+                       DefineNestedTypes ();
+
+                       return TypeBuilder;
+               }
+
                protected virtual bool DefineNestedTypes ()
                {
                        if (Interfaces != null) {
@@ -1379,9 +1269,8 @@ namespace Mono.CSharp {
 
                        InTransit = tc;
 
-                       Type parent = ptype;
-                       if (parent != null) {
-                               TypeContainer ptc = TypeManager.LookupTypeContainer (parent);
+                       if (BaseType != null) {
+                               TypeContainer ptc = TypeManager.LookupTypeContainer (BaseType);
                                if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
                                        return false;
                        }
@@ -1408,12 +1297,12 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Populates our TypeBuilder with fields and methods
                /// </summary>
-               public override bool DefineMembers (TypeContainer container)
+               public override bool DefineMembers ()
                {
                        if (members_defined)
                                return members_defined_ok;
 
-                       if (!base.DefineMembers (container))
+                       if (!base.DefineMembers ())
                                return false;
 
                        members_defined_ok = DoDefineMembers ();
@@ -1441,38 +1330,8 @@ namespace Mono.CSharp {
                        DefineContainerMembers (constants);
                        DefineContainerMembers (fields);
 
-                       if ((Kind == Kind.Class) && !(this is ClassPart)){
-                               if ((instance_constructors == null) &&
-                                   !(this is StaticClass)) {
-                                       if (default_constructor == null)
-                                               DefineDefaultConstructor (false);
-                               }
-
-                               if (initialized_static_fields != null &&
-                                   default_static_constructor == null)
-                                       DefineDefaultConstructor (true);
-                       }
-
-                       if (Kind == Kind.Struct){
-                               //
-                               // Structs can not have initialized instance
-                               // fields
-                               //
-                               if (initialized_static_fields != null &&
-                                   default_static_constructor == null)
-                                       DefineDefaultConstructor (true);
-
-                               if (initialized_fields != null)
-                                       ReportStructInitializedInstanceError ();
-                       }
-
-                       Pending = GetPendingImplementations ();
-
-                       if (parts != null) {
-                               foreach (ClassPart part in parts) {
-                                       if (!part.DefineMembers (this))
-                                               return false;
-                               }
+                       if (Kind == Kind.Struct || Kind == Kind.Class) {
+                               pending = PendingImplementation.GetPendingImplementations (this);
                        }
                
                        //
@@ -1480,9 +1339,6 @@ namespace Mono.CSharp {
                        //
                        DefineContainerMembers (instance_constructors);
                
-                       if (default_static_constructor != null)
-                               default_static_constructor.Define ();
-                       
                        DefineContainerMembers (properties);
                        DefineContainerMembers (events);
                        DefineContainerMembers (indexers);
@@ -1492,15 +1348,12 @@ namespace Mono.CSharp {
                        DefineContainerMembers (delegates);                     
 
 #if CACHE
-                       if (!(this is ClassPart))
-                               member_cache = new MemberCache (this);
-#endif
-
-                       if (parts != null) {
-                               foreach (ClassPart part in parts)
+                       member_cache = new MemberCache (this);
+                       if (partial_parts != null) {
+                               foreach (TypeContainer part in partial_parts)
                                        part.member_cache = member_cache;
                        }
-
+#endif
                        if (iterators != null) {
                                foreach (Iterator iterator in iterators) {
                                        if (iterator.DefineType () == null)
@@ -1508,7 +1361,7 @@ namespace Mono.CSharp {
                                }
 
                                foreach (Iterator iterator in iterators) {
-                                       if (!iterator.DefineMembers (this))
+                                       if (!iterator.DefineMembers ())
                                                return false;
                                }
                        }
@@ -1516,15 +1369,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               void ReportStructInitializedInstanceError ()
-               {
-                       foreach (Field f in initialized_fields){
-                               Report.Error (573, Location,
-                                       "`{0}': Structs cannot have instance field initializers",
-                                       f.GetSignatureForError ());
-                       }
-               }
-
                protected virtual void DefineContainerMembers (MemberCoreArrayList mcal)
                {
                        if (mcal != null)
@@ -1533,13 +1377,6 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
-                       if (parts != null) {
-                               foreach (ClassPart part in parts) {
-                                       if (!part.Define ())
-                                               return false;
-                               }
-                       }
-
                        if (iterators != null) {
                                foreach (Iterator iterator in iterators) {
                                        if (!iterator.Define ())
@@ -1579,7 +1416,7 @@ namespace Mono.CSharp {
                {
                        ArrayList members = new ArrayList ();
 
-                       DefineMembers (null);
+                       DefineMembers ();
 
                        if (methods != null) {
                                int len = methods.Count;
@@ -1595,7 +1432,7 @@ namespace Mono.CSharp {
                                for (int i = 0; i < len; i++) {
                                        Operator o = (Operator) operators [i];
 
-                                       members.Add (o.OperatorMethodBuilder);
+                                       members.Add (o.MethodBuilder);
                                }
                        }
 
@@ -1641,14 +1478,20 @@ namespace Mono.CSharp {
                }
                
                // Indicated whether container has StructLayout attribute set Explicit
-               public virtual bool HasExplicitLayout {
+               public bool HasExplicitLayout {
                        get {
-                               return false;
+                               return (caching_flags & Flags.HasExplicitLayout) != 0;
+                       }
+                       set {
+                               caching_flags |= Flags.HasExplicitLayout;
                        }
                }
 
                public override Type FindNestedType (string name)
                {
+                       if (PartialContainer != this)
+                               return PartialContainer.FindNestedType (name);
+
                        ArrayList [] lists = { types, enums, delegates, interfaces };
 
                        for (int j = 0; j < lists.Length; ++j) {
@@ -1660,8 +1503,7 @@ namespace Mono.CSharp {
                                for (int i = 0; i < len; ++i) {
                                        DeclSpace ds = (DeclSpace) list [i];
                                        if (ds.Basename == name) {
-                                               ds.DefineType ();
-                                               return ds.TypeBuilder;
+                                               return ds.DefineType ();
                                        }
                                }
                        }
@@ -1833,7 +1675,7 @@ namespace Mono.CSharp {
                                                if ((o.ModFlags & static_mask) != static_flags)
                                                        continue;
                                                
-                                               MethodBuilder ob = o.OperatorMethodBuilder;
+                                               MethodBuilder ob = o.MethodBuilder;
                                                if (ob != null && filter (ob, criteria) == true) {
                                                        if (members == null)
                                                                members = new ArrayList ();
@@ -1843,6 +1685,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++) {
@@ -2049,19 +1916,8 @@ namespace Mono.CSharp {
                                return ds.FindMembers (mt, bf, filter, criteria);
                        else
                                return new MemberList (t.FindMembers (mt, bf, filter, criteria));
-                        
                 }
 
-               //
-               // FindMethods will look for methods not only in the type `t', but in
-               // any interfaces implemented by the type.
-               //
-               public static MethodInfo [] FindMethods (Type t, BindingFlags bf,
-                                                        MemberFilter filter, object criteria)
-               {
-                       return null;
-               }
-
                /// <summary>
                ///   Emits the values for the constants
                /// </summary>
@@ -2073,7 +1929,7 @@ namespace Mono.CSharp {
                        return;
                }
 
-               void CheckMemberUsage (MemberCoreArrayList al, string member_type)
+               static void CheckMemberUsage (MemberCoreArrayList al, string member_type)
                {
                        if (al == null)
                                return;
@@ -2134,6 +1990,31 @@ namespace Mono.CSharp {
                        }
                }
 
+               // TODO: move to ClassOrStruct
+               void EmitConstructors ()
+               {
+                       if (instance_constructors == null)
+                               return;
+
+                       if (TypeBuilder.IsSubclassOf (TypeManager.attribute_type) && RootContext.VerifyClsCompliance && IsClsComplianceRequired ()) {
+                               bool has_compliant_args = false;
+
+                               foreach (Constructor c in instance_constructors) {
+                                       c.Emit ();
+
+                                       if (has_compliant_args)
+                                               continue;
+
+                                       has_compliant_args = c.HasCompliantArgs;
+                               }
+                               if (!has_compliant_args)
+                                       Report.Error (3015, Location, "`{0}' has no accessible constructors which use only CLS-compliant types", GetSignatureForError ());
+                       } else {
+                               foreach (Constructor c in instance_constructors)
+                                       c.Emit ();
+                       }
+               }
+
                /// <summary>
                ///   Emits the code, this step is performed after all
                ///   the types, enumerations, constructors
@@ -2141,7 +2022,7 @@ namespace Mono.CSharp {
                public virtual void EmitType ()
                {
                        if (OptAttributes != null)
-                               OptAttributes.Emit (ec, this);
+                               OptAttributes.Emit ();
                                
                        //
                        // Structs with no fields need to have at least one byte.
@@ -2166,25 +2047,7 @@ namespace Mono.CSharp {
 
                        Emit ();
 
-                       if (instance_constructors != null) {
-                               if (TypeBuilder.IsSubclassOf (TypeManager.attribute_type) && RootContext.VerifyClsCompliance && IsClsComplianceRequired (this)) {
-                                       bool has_compliant_args = false;
-
-                                       foreach (Constructor c in instance_constructors) {
-                                               c.Emit ();
-
-                                               if (has_compliant_args)
-                                                       continue;
-
-                                               has_compliant_args = c.HasCompliantArgs;
-                                       }
-                                       if (!has_compliant_args)
-                                               Report.Error (3015, Location, "`{0}' has no accessible constructors which use only CLS-compliant types", GetSignatureForError ());
-                               } else {
-                                       foreach (Constructor c in instance_constructors)
-                                               c.Emit ();
-                               }
-                       }
+                       EmitConstructors ();
 
                        // Can not continue if constants are broken
                        EmitConstants ();
@@ -2194,9 +2057,10 @@ namespace Mono.CSharp {
                        if (default_static_constructor != null)
                                default_static_constructor.Emit ();
                        
-                       if (methods != null)
+                       if (methods != null){
                                foreach (Method m in methods)
                                        m.Emit ();
+                       }
 
                        if (operators != null)
                                foreach (Operator o in operators)
@@ -2231,22 +2095,13 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (parts != null) {
-                               foreach (ClassPart part in parts)
-                                       part.EmitType ();
-                       }
-
-                       if ((Pending != null) && !(this is ClassPart))
-                               if (Pending.VerifyPendingMethods ())
+                       if (pending != null)
+                               if (pending.VerifyPendingMethods ())
                                        return;
 
                        if (iterators != null)
                                foreach (Iterator iterator in iterators)
                                        iterator.EmitType ();
-                       
-//                     if (types != null)
-//                             foreach (TypeContainer tc in types)
-//                                     tc.Emit ();
                }
 
                public override void CloseType ()
@@ -2304,7 +2159,6 @@ namespace Mono.CSharp {
                        indexers = null;
                        operators = null;
                        iterators = null;
-                       ec = null;
                        default_constructor = null;
                        default_static_constructor = null;
                        type_bases = null;
@@ -2394,19 +2248,13 @@ namespace Mono.CSharp {
                        return ok;
                }
 
-               public bool UserDefinedStaticConstructor {
-                       get {
-                               return default_static_constructor != null;
-                       }
-               }
-
                public Constructor DefaultStaticConstructor {
                        get { return default_static_constructor; }
                }
 
-               protected override bool VerifyClsCompliance (DeclSpace ds)
+               protected override bool VerifyClsCompliance ()
                {
-                       if (!base.VerifyClsCompliance (ds))
+                       if (!base.VerifyClsCompliance ())
                                return false;
 
                        VerifyClsName ();
@@ -2416,7 +2264,7 @@ namespace Mono.CSharp {
                                Report.Error (3009, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
                        }
 
-                       if (!Parent.IsClsComplianceRequired (ds)) {
+                       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 ());
                        }
@@ -2436,7 +2284,7 @@ namespace Mono.CSharp {
 
                        foreach (DictionaryEntry entry in defined_names) {
                                MemberCore mc = (MemberCore)entry.Value;
-                               if (!mc.IsClsComplianceRequired (mc.Parent))
+                               if (!mc.IsClsComplianceRequired ())
                                        continue;
 
                                string name = (string) entry.Key;
@@ -2481,11 +2329,21 @@ namespace Mono.CSharp {
                                }
                        }
                        
+                       Report.SymbolRelatedToPreviousError (mb.InterfaceType);
                        Report.Error (540, mb.Location, "`{0}': containing type does not implement interface `{1}'",
                                mb.GetSignatureForError (), TypeManager.CSharpName (mb.InterfaceType));
                        return false;
                }
 
+               public void Mark_HasEquals ()
+               {
+                       Methods.HasEquals = true;
+               }
+
+               public void Mark_HasGetHashCode ()
+               {
+                       Methods.HasGetHashCode = true;
+               }
 
                //
                // IMemberContainer
@@ -2546,324 +2404,225 @@ namespace Mono.CSharp {
                }
        }
 
-       public class PartialContainer : TypeContainer {
-
-               public readonly Namespace Namespace;
-               public readonly int OriginalModFlags;
-               public readonly int AllowedModifiers;
-               public readonly TypeAttributes DefaultTypeAttributes;
-               public ListDictionary DeclarativeSecurity;
+       public abstract class ClassOrStruct : TypeContainer {
+               ListDictionary declarative_security;
 
-               static PartialContainer Create (NamespaceEntry ns, TypeContainer parent,
-                                               MemberName member_name, int mod_flags, Kind kind)
+               public ClassOrStruct (NamespaceEntry ns, DeclSpace parent,
+                                     MemberName name, Attributes attrs, Kind kind)
+                       : base (ns, parent, name, attrs, kind)
                {
+               }
 
-                       if (!CheckModFlags (0, mod_flags, member_name))
-                               return null;
-
-                       PartialContainer pc = RootContext.Tree.GetDecl (member_name) as PartialContainer;
-                       if (pc != null) {
-                               if (pc.Kind != kind) {
-                                       Report.Error (
-                                               261, member_name.Location, "Partial declarations of `{0}' " +
-                                               "must be all classes, all structs or " +
-                                               "all interfaces", member_name.GetPartialName ());
-                                       return null;
-                               }
-
-                               if (!CheckModFlags (pc.OriginalModFlags, mod_flags, member_name))
-                                       return null;
-                               pc.ModFlags |= (mod_flags & pc.AllowedModifiers);
-
-                               return pc;
+               protected override bool AddToContainer (MemberCore symbol, string name)
+               {
+                       if (name == Basename) {
+                               Report.SymbolRelatedToPreviousError (this);
+                               Report.Error (542, symbol.Location, "`{0}': member names cannot be the same as their enclosing type",
+                                       symbol.GetSignatureForError ());
+                               return false;
                        }
 
-                       if (parent is ClassPart)
-                               parent = ((ClassPart) parent).PartialContainer;
+                       return base.AddToContainer (symbol, name);
+               }
 
-                       pc = new PartialContainer (ns.NS, parent, member_name, mod_flags, kind);
+               public override void VerifyMembers ()
+               {
+                       base.VerifyMembers ();
 
-                       if (kind == Kind.Interface) {
-                               if (!parent.AddInterface (pc))
-                                       return null;
-                       } else if (kind == Kind.Class || kind == Kind.Struct) {
-                               if (!parent.AddClassOrStruct (pc))
-                                       return null;
-                       } else {
-                               throw new InvalidOperationException ();
+                       if ((events != null) && (RootContext.WarningLevel >= 3)) {
+                               foreach (Event e in events){
+                                       if ((e.caching_flags & Flags.IsAssigned) == 0)
+                                               Report.Warning (67, 3, e.Location, "The event `{0}' is never used", e.GetSignatureForError ());
+                               }
                        }
-                       RootContext.Tree.RecordDecl (ns.NS, member_name, pc);
-                       return pc;
                }
 
-               static bool CheckModFlags (int flags_org, int flags, MemberName member_name)
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
-                       // Check (abstract|static|sealed) sanity.
-                       int tmp = (flags_org | flags) & (Modifiers.ABSTRACT | Modifiers.SEALED | Modifiers.STATIC);
-                       if ((tmp & Modifiers.ABSTRACT) != 0) {
-                               if ((tmp & (Modifiers.STATIC | Modifiers.SEALED)) != 0) {
-                                       Report.Error (
-                                               418, member_name.Location, 
-                                               "`{0}': an abstract class cannot be sealed or static", member_name.ToString ());
-                                       return false;
-                               }
-                       } else if (tmp == (Modifiers.SEALED | Modifiers.STATIC)) {
-                               Report.Error (441, member_name.Location, "`{0}': a class cannot be both static and sealed", member_name.ToString ());
-                               return false;
-                       }
+                       if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (false)) {
+                               if (declarative_security == null)
+                                       declarative_security = new ListDictionary ();
 
-                       if (flags_org == 0)
-                               return true;
+                               a.ExtractSecurityPermissionSet (declarative_security);
+                               return;
+                       }
 
-                       // Check conflicts.
-                       if (0 != ((flags_org ^ flags) & (0xFFFFFFFF ^ (Modifiers.SEALED | Modifiers.ABSTRACT)))) {
-                               Report.Error (
-                                       262, member_name.Location, "Partial declarations of `{0}' " +
-                                       "have conflicting accessibility modifiers",
-                                       member_name.GetPartialName ());
-                               return false;
+                       if (a.Type == TypeManager.struct_layout_attribute_type && a.GetLayoutKindValue () == LayoutKind.Explicit) {
+                               HasExplicitLayout = true;
                        }
-                       return true;
+
+                       base.ApplyAttributeBuilder (a, cb);
                }
 
-               public static ClassPart CreatePart (NamespaceEntry ns, TypeContainer parent,
-                                                   MemberName name, int mod, Attributes attrs,
-                                                   Kind kind, Location loc)
+               /// <summary>
+               /// Defines the default constructors 
+               /// </summary>
+               protected void DefineDefaultConstructor (bool is_static)
                {
-                       PartialContainer pc = Create (ns, parent, name, mod, kind);
-                       if (pc == null) {
-                               // An error occured; create a dummy container, but don't
-                               // register it.
-                               pc = new PartialContainer (ns.NS, parent, name, mod, kind);
+                       // The default instance constructor is public
+                       // If the class is abstract, the default constructor is protected
+                       // The default static constructor is private
+
+                       int mods;
+                       if (is_static) {
+                               mods = Modifiers.STATIC | Modifiers.PRIVATE;
+                       } else {
+                               mods = ((ModFlags & Modifiers.ABSTRACT) != 0) ? Modifiers.PROTECTED : Modifiers.PUBLIC;
                        }
 
-                       ClassPart part = new ClassPart (ns, pc, parent, mod, attrs, kind);
-                       pc.AddPart (part);
-                       return part;
+                       Constructor c = new Constructor (this, MemberName.Name, mods,
+                               Parameters.EmptyReadOnlyParameters,
+                               new GeneratedBaseInitializer (Location),
+                               Location);
+                       
+                       AddConstructor (c);
+                       c.Block = new ToplevelBlock (null, Location);
                }
 
-               protected PartialContainer (Namespace ns, TypeContainer parent,
-                                           MemberName name, int mod, Kind kind)
-                       : base (null, parent, name, null, kind)
+               void DefineFieldInitializers ()
                {
-                       this.Namespace = ns;
+                       if (initialized_fields != null) {
+                               for (int i = 0; i < initialized_fields.Count; ++i) {
+                                       FieldBase fb = (FieldBase)initialized_fields[i];
+                                       fb.ResolveInitializer ();
+                                       if (fb.HasDefaultInitializer && RootContext.Optimize) {
+                                               // Field is re-initialized to its default value => removed
+                                               initialized_fields.RemoveAt (i);
+                                               --i;
+                                       }
+                               }
+                       }
 
-                       switch (kind) {
-                       case Kind.Class:
-                               AllowedModifiers = Class.AllowedModifiers;
-                               DefaultTypeAttributes = Class.DefaultTypeAttributes;
-                               break;
+                       if (initialized_static_fields != null) {
+                               bool has_complex_initializer = false;
 
-                       case Kind.Struct:
-                               AllowedModifiers = Struct.AllowedModifiers;
-                               DefaultTypeAttributes = Struct.DefaultTypeAttributes;
-                               break;
+                               foreach (FieldBase fb in initialized_static_fields) {
+                                       if (fb.ResolveInitializer () is Constant)
+                                               continue;
 
-                       case Kind.Interface:
-                               AllowedModifiers = Interface.AllowedModifiers;
-                               DefaultTypeAttributes = Interface.DefaultTypeAttributes;
-                               break;
+                                       has_complex_initializer = true;
+                               }
 
-                       default:
-                               throw new InvalidOperationException ();
-                       }
+                               // Need special check to not optimize code like this
+                               // static int a = b = 5;
+                               // 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) {
+                                                       initialized_static_fields.RemoveAt (i);
+                                                       --i;
+                                               }
+                                       }
+                               }
 
-                       int accmods;
-                       if (parent.Parent == null)
-                               accmods = Modifiers.INTERNAL;
-                       else
-                               accmods = Modifiers.PRIVATE;
+                               if (default_static_constructor == null && initialized_static_fields.Count > 0) {
+                                       DefineDefaultConstructor (true);
+                               }
+                       }
 
-                       this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
-                       this.OriginalModFlags = mod;
                }
 
-               public override void EmitType ()
+               public override bool Define ()
                {
-                       base.EmitType ();
+                       DefineFieldInitializers ();
 
-                       if (DeclarativeSecurity != null) {
-                               foreach (DictionaryEntry de in DeclarativeSecurity) {
-                                       TypeBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
-                               }
-                       }
-               }
+                       if (default_static_constructor != null)
+                               default_static_constructor.Define ();
 
-               public override PendingImplementation GetPendingImplementations ()
-               {
-                       return PendingImplementation.GetPendingImplementations (this);
+                       return base.Define ();
                }
 
-               public override bool MarkForDuplicationCheck ()
+               public override void Emit ()
                {
-                       return true;
+                       base.Emit ();
+
+                       if (declarative_security != null) {
+                               foreach (DictionaryEntry de in declarative_security) {
+                                       TypeBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
+                               }
+                       }
                }
 
                protected override TypeAttributes TypeAttr {
                        get {
-                               return base.TypeAttr | DefaultTypeAttributes;
+                               if (default_static_constructor == null)
+                                       return base.TypeAttr | TypeAttributes.BeforeFieldInit;
+
+                               return base.TypeAttr;
                        }
                }
        }
 
-       public class ClassPart : TypeContainer, IMemberContainer {
-               public readonly PartialContainer PartialContainer;
-               public readonly bool IsPartial;
-
-               public ClassPart (NamespaceEntry ns, PartialContainer pc, TypeContainer parent,
-                                 int mod, Attributes attrs, Kind kind)
-                       : base (ns, parent, pc.MemberName, attrs, kind)
-               {
-                       this.PartialContainer = pc;
-                       this.IsPartial = true;
-
-                       int accmods;
-                       if (parent == null || parent == RootContext.Tree.Types)
-                               accmods = Modifiers.INTERNAL;
-                       else
-                               accmods = Modifiers.PRIVATE;
 
-                       this.ModFlags = Modifiers.Check (pc.AllowedModifiers, mod, accmods, pc.MemberName.Location);
-               }
+       // TODO: should be sealed
+       public class Class : ClassOrStruct {
+               const int AllowedModifiers =
+                       Modifiers.NEW |
+                       Modifiers.PUBLIC |
+                       Modifiers.PROTECTED |
+                       Modifiers.INTERNAL |
+                       Modifiers.PRIVATE |
+                       Modifiers.ABSTRACT |
+                       Modifiers.SEALED |
+                       Modifiers.STATIC |
+                       Modifiers.UNSAFE;
 
-               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               public Class (NamespaceEntry ns, DeclSpace parent, MemberName name, int mod,
+                             Attributes attrs)
+                       : base (ns, parent, name, attrs, Kind.Class)
                {
-                       if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (false)) {
-                               if (PartialContainer.DeclarativeSecurity == null)
-                                       PartialContainer.DeclarativeSecurity = new ListDictionary ();
+                       int accmods = Parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
+                       this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
 
-                               a.ExtractSecurityPermissionSet (PartialContainer.DeclarativeSecurity);
-                               return;
+                       if (IsStatic && RootContext.Version == LanguageVersion.ISO_1) {
+                               Report.FeatureIsNotStandardized (Location, "static classes");
                        }
-
-                       base.ApplyAttributeBuilder (a, cb);
-               }
-
-               public override PendingImplementation GetPendingImplementations ()
-               {
-                       return PartialContainer.Pending;
                }
 
-               public override bool VerifyImplements (MemberBase mb)
+               public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
-                       return PartialContainer.VerifyImplements (mb);
-               }
+                       if (a.Type == TypeManager.attribute_usage_type) {
+                               if (BaseType != TypeManager.attribute_type && !BaseType.IsSubclassOf (TypeManager.attribute_type) &&
+                                       TypeBuilder.FullName != "System.Attribute") {
+                                       Report.Error (641, a.Location, "Attribute `{0}' is only valid on classes derived from System.Attribute", a.GetSignatureForError ());
+                               }
+                       }
 
+                       if (a.Type == TypeManager.conditional_attribute_type &&
+                               !(BaseType == TypeManager.attribute_type || BaseType.IsSubclassOf (TypeManager.attribute_type))) {
+                               Report.Error (1689, a.Location, "Attribute `System.Diagnostics.ConditionalAttribute' is only valid on methods or attribute classes");
+                               return;
+                       }
 
-               public override void RegisterFieldForInitialization (FieldMember field)
-               {
-                       PartialContainer.RegisterFieldForInitialization (field);
-               }
+                       if (a.Type == TypeManager.comimport_attr_type &&
+                               !attributes.Contains (TypeManager.guid_attr_type)) {
+                                       a.Error_MissingGuidAttribute ();
+                                       return;
+                       }
 
-               public override bool EmitFieldInitializers (EmitContext ec)
-               {
-                       return PartialContainer.EmitFieldInitializers (ec);
-               }
+                       if (AttributeTester.IsAttributeExcluded (a.Type))
+                               return;
 
-               public override Type FindNestedType (string name)
-               {
-                       return PartialContainer.FindNestedType (name);
+                       base.ApplyAttributeBuilder (a, cb);
                }
 
-               public override MemberCache BaseCache {
+               public override AttributeTargets AttributeTargets {
                        get {
-                               return PartialContainer.BaseCache;
+                               return AttributeTargets.Class;
                        }
                }
 
-               public override TypeBuilder DefineType ()
+               protected override void DefineContainerMembers (MemberCoreArrayList list)
                {
-                       throw new InternalErrorException ("Should not get here");
-               }
+                       if (list == null)
+                               return;
 
-       }
-
-       public abstract class ClassOrStruct : TypeContainer {
-               bool has_explicit_layout = false;
-               ListDictionary declarative_security;
-
-               public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
-                                     MemberName name, Attributes attrs, Kind kind)
-                       : base (ns, parent, name, attrs, kind)
-               {
-               }
-
-               public override PendingImplementation GetPendingImplementations ()
-               {
-                       return PendingImplementation.GetPendingImplementations (this);
-               }
-
-               public override bool HasExplicitLayout {
-                       get {
-                               return has_explicit_layout;
-                       }
-               }
-
-               public override void VerifyMembers ()
-               {
-                       base.VerifyMembers ();
-
-                       if ((events != null) && (RootContext.WarningLevel >= 3)) {
-                               foreach (Event e in events){
-                                       if ((e.caching_flags & Flags.IsAssigned) == 0)
-                                               Report.Warning (67, 3, e.Location, "The event `{0}' is never used", e.GetSignatureForError ());
-                               }
-                       }
-               }
-
-               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
-               {
-                       if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (false)) {
-                               if (declarative_security == null)
-                                       declarative_security = new ListDictionary ();
-
-                               a.ExtractSecurityPermissionSet (declarative_security);
+                       if (!IsStatic) {
+                               base.DefineContainerMembers (list);
                                return;
                        }
 
-                       if (a.Type == TypeManager.struct_layout_attribute_type && a.GetLayoutKindValue () == LayoutKind.Explicit)
-                               has_explicit_layout = true;
-
-                       base.ApplyAttributeBuilder (a, cb);
-               }
-
-               public override void Emit()
-               {
-                       base.Emit ();
-
-                       if (declarative_security != null) {
-                               foreach (DictionaryEntry de in declarative_security) {
-                                       TypeBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
-                               }
-                       }
-               }
-       }
-
-       /// <summary>
-       /// Class handles static classes declaration
-       /// </summary>
-       public sealed class StaticClass: Class {
-               public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
-                       Attributes attrs)
-                       : base (ns, parent, name, mod, attrs)
-               {
-                       if (RootContext.Version == LanguageVersion.ISO_1) {
-                               Report.FeatureIsNotStandardized (Location, "static classes");
-                       }
-               }
-
-               protected override int AllowedModifiersProp {
-                       get {
-                               return Modifiers.NEW | Modifiers.PUBLIC | Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE |
-                                       Modifiers.STATIC | Modifiers.UNSAFE;
-                       }
-               }
-
-               protected override void DefineContainerMembers (MemberCoreArrayList list)
-               {
-                       if (list == null)
-                               return;
-
                        foreach (MemberCore m in list) {
                                if (m is Operator) {
                                        Report.Error (715, m.Location, "`{0}': Static classes cannot contain user-defined operators", m.GetSignatureForError ());
@@ -2899,97 +2658,84 @@ namespace Mono.CSharp {
                        base.DefineContainerMembers (list);
                }
 
-               public override TypeBuilder DefineType()
+               public override TypeBuilder DefineType ()
                {
-                       if ((ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) == (Modifiers.SEALED | Modifiers.STATIC)) {
-                               Report.Error (441, Location, "`{0}': a class cannot be both static and sealed", GetSignatureForError ());
+                       if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
+                               Report.Error (418, Location, "`{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
                                return null;
                        }
 
-                       TypeBuilder tb = base.DefineType ();
-                       if (tb == null)
-                               return null;
-
-                       if (ptype != TypeManager.object_type) {
-                               Report.Error (713, Location, "Static class `{0}' cannot derive from type `{1}'. Static classes must derive from object", GetSignatureForError (), TypeManager.CSharpName (ptype));
+                       if ((ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) == (Modifiers.SEALED | Modifiers.STATIC)) {
+                               Report.Error (441, Location, "`{0}': a class cannot be both static and sealed", GetSignatureForError ());
                                return null;
                        }
 
-                       if (ifaces != null) {
-                               foreach (Type t in ifaces)
-                                       Report.SymbolRelatedToPreviousError (t);
-                               Report.Error (714, Location, "`{0}': static classes cannot implement interfaces", GetSignatureForError ());
-                       }
-                       return tb;
-               }
-
-               protected override TypeAttributes TypeAttr {
-                       get {
-                               return base.TypeAttr | TypeAttributes.Abstract | TypeAttributes.Sealed;
-                       }
+                       return base.DefineType ();
                }
-       }
-
-       public class Class : ClassOrStruct {
-               // TODO: remove this and use only AllowedModifiersProp to fix partial classes bugs
-               public const int AllowedModifiers =
-                       Modifiers.NEW |
-                       Modifiers.PUBLIC |
-                       Modifiers.PROTECTED |
-                       Modifiers.INTERNAL |
-                       Modifiers.PRIVATE |
-                       Modifiers.ABSTRACT |
-                       Modifiers.SEALED |
-                       Modifiers.UNSAFE;
 
-               public Class (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
-                             Attributes attrs)
-                       : base (ns, parent, name, attrs, Kind.Class)
+               protected override bool DoDefineMembers ()
                {
-                       this.ModFlags = mod;
-               }
+                       if (InstanceConstructors == null && !IsStatic)
+                               DefineDefaultConstructor (false);
 
-               virtual protected int AllowedModifiersProp {
-                       get {
-                               return AllowedModifiers;
-                       }
+                       return base.DoDefineMembers ();
                }
 
-               public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+               public override TypeExpr[] GetClassBases (out TypeExpr base_class)
                {
-                       if (a.Type == TypeManager.attribute_usage_type) {
-                               if (ptype != TypeManager.attribute_type && !ptype.IsSubclassOf (TypeManager.attribute_type) &&
-                                       TypeBuilder.FullName != "System.Attribute") {
-                                       Report.Error (641, a.Location, "Attribute `{0}' is only valid on classes derived from System.Attribute", a.GetSignatureForError ());
+                       TypeExpr[] ifaces = base.GetClassBases (out base_class);
+
+                       if (base_class == null) {
+                               if (RootContext.StdLib)
+                                       base_class = TypeManager.system_object_expr;
+                               else if (Name != "System.Object")
+                                       base_class = TypeManager.system_object_expr;
+                       } else {
+                               if (base_class.Type.IsArray || base_class.Type.IsPointer) {
+                                       Report.Error (1521, base_class.Location, "Invalid base type");
+                                       return ifaces;
                                }
-                       }
 
-                       if (a.Type == TypeManager.conditional_attribute_type &&
-                               !(ptype == TypeManager.attribute_type || ptype.IsSubclassOf (TypeManager.attribute_type))) {
-                               Report.Error (1689, a.Location, "Attribute 'System.Diagnostics.ConditionalAttribute' is only valid on methods or attribute classes");
-                               return;
-                       }
+                               if (base_class.IsSealed){
+                                       Report.SymbolRelatedToPreviousError (base_class.Type);
+                                       if (base_class.Type.IsAbstract) {
+                                               Report.Error (709, Location, "`{0}': Cannot derive from static class `{1}'",
+                                                       GetSignatureForError (), TypeManager.CSharpName (base_class.Type));
+                                       } else {
+                                               Report.Error (509, Location, "`{0}': cannot derive from sealed class `{1}'",
+                                                       GetSignatureForError (), TypeManager.CSharpName (base_class.Type));
+                                       }
+                                       return ifaces;
+                               }
 
-                       if (AttributeTester.IsAttributeExcluded (a.Type))
-                               return;
+                               if (!base_class.CanInheritFrom ()){
+                                       Report.Error (644, Location, "`{0}' cannot derive from special class `{1}'",
+                                               GetSignatureForError (), base_class.GetSignatureForError ());
+                                       return ifaces;
+                               }
 
-                       base.ApplyAttributeBuilder (a, cb);
-               }
+                               if (!base_class.AsAccessible (this, ModFlags)) {
+                                       Report.SymbolRelatedToPreviousError (base_class.Type);
+                                       Report.Error (60, Location, "Inconsistent accessibility: base class `{0}' is less accessible than class `{1}'", 
+                                               TypeManager.CSharpName (base_class.Type), GetSignatureForError ());
+                               }
+                       }
 
-               public const TypeAttributes DefaultTypeAttributes =
-                       TypeAttributes.AutoLayout | TypeAttributes.Class;
+                       if (IsStatic) {
+                               if (base_class != TypeManager.system_object_expr) {
+                                       Report.Error (713, Location, "Static class `{0}' cannot derive from type `{1}'. Static classes must derive from object",
+                                               GetSignatureForError (), base_class.GetSignatureForError ());
+                                       return ifaces;
+                               }
 
-               public override TypeBuilder DefineType()
-               {
-                       if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
-                               Report.Error (418, Location, "`{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
-                               return null;
+                               if (ifaces != null) {
+                                       foreach (TypeExpr t in ifaces)
+                                               Report.SymbolRelatedToPreviousError (t.Type);
+                                       Report.Error (714, Location, "`{0}': static classes cannot implement interfaces", GetSignatureForError ());
+                               }
                        }
 
-                       int accmods = Parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
-                       ModFlags = Modifiers.Check (AllowedModifiersProp, ModFlags, accmods, Location);
-
-                       return base.DefineType ();
+                       return ifaces;
                }
 
                /// Search for at least one defined condition in ConditionalAttribute of attribute class
@@ -3004,13 +2750,13 @@ namespace Mono.CSharp {
                        if (OptAttributes == null)
                                return false;
 
-                       Attribute[] attrs = OptAttributes.SearchMulti (TypeManager.conditional_attribute_type, ec);
+                       Attribute[] attrs = OptAttributes.SearchMulti (TypeManager.conditional_attribute_type);
 
                        if (attrs == null)
                                return false;
 
                        foreach (Attribute a in attrs) {
-                               string condition = a.GetConditionalAttributeValue (Parent.EmitContext);
+                               string condition = a.GetConditionalAttributeValue ();
                                if (RootContext.AllDefines.Contains (condition))
                                        return false;
                        }
@@ -3019,22 +2765,31 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               bool IsStatic {
+                       get {
+                               return (ModFlags & Modifiers.STATIC) != 0;
+                       }
+               }
+
                //
                // FIXME: How do we deal with the user specifying a different
                // layout?
                //
                protected override TypeAttributes TypeAttr {
                        get {
-                               return base.TypeAttr | DefaultTypeAttributes;
+                               TypeAttributes ta = base.TypeAttr | TypeAttributes.AutoLayout | TypeAttributes.Class;
+                               if (IsStatic)
+                                       ta |= TypeAttributes.Abstract | TypeAttributes.Sealed;
+                               return ta;
                        }
                }
        }
 
-       public class Struct : ClassOrStruct {
+       public sealed class Struct : ClassOrStruct {
                // <summary>
                //   Modifiers allowed in a struct declaration
                // </summary>
-               public const int AllowedModifiers =
+               const int AllowedModifiers =
                        Modifiers.NEW       |
                        Modifiers.PUBLIC    |
                        Modifiers.PROTECTED |
@@ -3042,7 +2797,7 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE    |
                        Modifiers.PRIVATE;
 
-               public Struct (NamespaceEntry ns, TypeContainer parent, MemberName name,
+               public Struct (NamespaceEntry ns, DeclSpace parent, MemberName name,
                               int mod, Attributes attrs)
                        : base (ns, parent, name, attrs, Kind.Struct)
                {
@@ -3058,11 +2813,36 @@ namespace Mono.CSharp {
                        this.ModFlags |= Modifiers.SEALED;
                }
 
-               public const TypeAttributes DefaultTypeAttributes =
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Struct;
+                       }
+               }
+
+               const TypeAttributes DefaultTypeAttributes =
                        TypeAttributes.SequentialLayout |
                        TypeAttributes.Sealed |
                        TypeAttributes.BeforeFieldInit;
 
+
+               public override TypeExpr[] GetClassBases (out TypeExpr base_class)
+               {
+                       TypeExpr[] ifaces = base.GetClassBases (out base_class);
+                       //
+                       // If we are compiling our runtime,
+                       // and we are defining ValueType, then our
+                       // base is `System.Object'.
+                       //
+                       if (base_class == null) {
+                               if (!RootContext.StdLib && Name == "System.ValueType")
+                                       base_class = TypeManager.system_object_expr;
+                               else
+                                       base_class = TypeManager.system_valuetype_expr;
+                       }
+
+                       return ifaces;
+               }
+
                //
                // FIXME: Allow the user to specify a different set of attributes
                // in some cases (Sealed for example is mandatory for a class,
@@ -3073,12 +2853,23 @@ namespace Mono.CSharp {
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
+
+               public override void RegisterFieldForInitialization (FieldBase field)
+               {
+                       if ((field.ModFlags & Modifiers.STATIC) == 0) {
+                               Report.Error (573, field.Location, "`{0}': Structs cannot have instance field initializers",
+                                       field.GetSignatureForError ());
+                               return;
+                       }
+                       base.RegisterFieldForInitialization (field);
+               }
+
        }
 
        /// <summary>
        ///   Interfaces
        /// </summary>
-       public class Interface : TypeContainer, IMemberContainer {
+       public sealed class Interface : TypeContainer, IMemberContainer {
 
                /// <summary>
                ///   Modifiers allowed in a class declaration
@@ -3091,7 +2882,7 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE    |
                        Modifiers.PRIVATE;
 
-               public Interface (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
+               public Interface (NamespaceEntry ns, DeclSpace parent, MemberName name, int mod,
                                  Attributes attrs)
                        : base (ns, parent, name, attrs, Kind.Interface)
                {
@@ -3105,12 +2896,24 @@ namespace Mono.CSharp {
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, name.Location);
                }
 
-               public override PendingImplementation GetPendingImplementations ()
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
-                       return null;
+                       if (a.Type == TypeManager.comimport_attr_type &&
+                               !attributes.Contains (TypeManager.guid_attr_type)) {
+                                       a.Error_MissingGuidAttribute ();
+                                       return;
+                       }
+                       base.ApplyAttributeBuilder (a, cb);
+               }
+
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Interface;
+                       }
                }
 
-               public const TypeAttributes DefaultTypeAttributes =
+               const TypeAttributes DefaultTypeAttributes =
                        TypeAttributes.AutoLayout |
                        TypeAttributes.Abstract |
                        TypeAttributes.Interface;
@@ -3121,9 +2924,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override bool VerifyClsCompliance (DeclSpace ds)
+               protected override bool VerifyClsCompliance ()
                {
-                       if (!base.VerifyClsCompliance (ds))
+                       if (!base.VerifyClsCompliance ())
                                return false;
 
                        if (ifaces != null) {
@@ -3144,18 +2947,13 @@ namespace Mono.CSharp {
        public abstract class MethodCore : MemberBase {
                public readonly Parameters Parameters;
                protected ToplevelBlock block;
-               
-               // Whether this is an operator method.
-               public Operator IsOperator;
 
                //
                // The method we're overriding if this is an override method.
                //
                protected MethodInfo base_method = null;
 
-               static string[] attribute_targets = new string [] { "method", "return" };
-
-               public MethodCore (TypeContainer parent, Expression type, int mod,
+               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,
@@ -3212,7 +3010,7 @@ namespace Mono.CSharp {
                                return true;
 
                        // Is null for System.Object while compiling corlib and base interfaces
-                       if (Parent.BaseCache == null) {
+                       if (ParentContainer.BaseCache == 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 ());
                                }
@@ -3220,7 +3018,7 @@ namespace Mono.CSharp {
                        }
 
                        Type base_ret_type = null;
-                       base_method = FindOutBaseMethod (Parent, ref base_ret_type);
+                       base_method = FindOutBaseMethod (ref base_ret_type);
 
                        // method is override
                        if (base_method != null) {
@@ -3255,18 +3053,15 @@ namespace Mono.CSharp {
                                        return false;
                                }
 
-                               if (RootContext.WarningLevel > 2) {
-                                       if (Name == "Equals" && Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type)
-                                               Parent.Methods.HasEquals = true;
-                                       else if (Name == "GetHashCode" && Parameters.Empty)
-                                               Parent.Methods.HasGetHashCode = true;
-                               }
+                               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) {
-                                               EmitContext ec = new EmitContext (this.Parent, this.Parent, Location, null, null, ModFlags, false);
-                                               if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type, ec)) {
+                                               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) );
@@ -3276,7 +3071,7 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       MemberInfo conflict_symbol = Parent.FindBaseMemberWithSameName (Name, !(this is Property));
+                       MemberInfo conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, !(this is Property));
                        if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                if (conflict_symbol != null) {
                                        Report.SymbolRelatedToPreviousError (conflict_symbol);
@@ -3410,7 +3205,7 @@ namespace Mono.CSharp {
 
                public bool CheckAbstractAndExtern (bool has_block)
                {
-                       if (Parent.Kind == Kind.Interface)
+                       if (ParentContainer.Kind == Kind.Interface)
                                return true;
 
                        if (has_block) {
@@ -3464,22 +3259,14 @@ namespace Mono.CSharp {
                /// <summary>
                /// Gets base method and its return type
                /// </summary>
-               protected abstract MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type);
+               protected abstract MethodInfo FindOutBaseMethod (ref Type base_ret_type);
 
                protected bool DoDefineParameters ()
                {
-                       EmitContext ec = Parent.EmitContext;
-                       if (ec == null)
-                               throw new InternalErrorException ("DoDefineParameters invoked too early");
-
-                       bool old_unsafe = ec.InUnsafe;
-                       ec.InUnsafe = InUnsafe;
                        // Check if arguments were correct
-                       if (!Parameters.Resolve (ec))
+                       if (!Parameters.Resolve (this))
                                return false;
 
-                       ec.InUnsafe = old_unsafe;
-
                        return CheckParameters (ParameterTypes);
                }
 
@@ -3497,8 +3284,6 @@ namespace Mono.CSharp {
                                }
 
                                if (partype.IsPointer){
-                                       if (!UnsafeOK (ds))
-                                               error = true;
                                        if (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
                                                error = true;
                                }
@@ -3506,12 +3291,13 @@ namespace Mono.CSharp {
                                if (ds.AsAccessible (partype, ModFlags))
                                        continue;
 
+                               Report.SymbolRelatedToPreviousError (partype);
                                if (this is Indexer)
                                        Report.Error (55, Location,
                                                "Inconsistent accessibility: parameter type `" +
                                                TypeManager.CSharpName (partype) + "' is less " +
                                                "accessible than indexer `" + GetSignatureForError () + "'");
-                               else if ((this is Method) && ((Method) this).IsOperator != null)
+                               else if (this is Operator)
                                        Report.Error (57, Location,
                                                "Inconsistent accessibility: parameter type `" +
                                                TypeManager.CSharpName (partype) + "' is less " +
@@ -3527,16 +3313,10 @@ namespace Mono.CSharp {
                        return !error;
                }
 
-               public override string[] ValidAttributeTargets {
-                       get {
-                               return attribute_targets;
-                       }
-               }
-
-               protected override bool VerifyClsCompliance (DeclSpace ds)
+               protected override bool VerifyClsCompliance ()
                {
-                       if (!base.VerifyClsCompliance (ds)) {
-                               if ((ModFlags & Modifiers.ABSTRACT) != 0 && IsExposedFromAssembly (ds) && ds.IsClsComplianceRequired (ds)) {
+                       if (!base.VerifyClsCompliance ()) {
+                               if ((ModFlags & Modifiers.ABSTRACT) != 0 && IsExposedFromAssembly () && Parent.IsClsComplianceRequired ()) {
                                        Report.Error (3011, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
                                }
                                return false;
@@ -3575,6 +3355,9 @@ namespace Mono.CSharp {
                        if (param_types.Length != ParameterTypes.Length)
                                return false;
 
+                       if (method.Parameters.HasArglist != Parameters.HasArglist)
+                               return false;
+                       
                        for (int i = 0; i < param_types.Length; i++)
                                if (param_types [i] != ParameterTypes [i])
                                        return false;
@@ -3627,9 +3410,9 @@ namespace Mono.CSharp {
                // FIXME: with a few effort, it could be done with XmlReader,
                // that means removal of DOM use.
                //
-               internal override void OnGenerateDocComment (DeclSpace ds, XmlElement el)
+               internal override void OnGenerateDocComment (XmlElement el)
                {
-                       DocUtil.OnMethodGenerateDocComment (this, ds, el);
+                       DocUtil.OnMethodGenerateDocComment (this, el);
                }
 
                //
@@ -3641,37 +3424,264 @@ namespace Mono.CSharp {
 
        }
 
-       public class SourceMethod : ISourceMethod
+       public abstract class MethodOrOperator : MethodCore, IMethodData
        {
-               TypeContainer container;
-               MethodBase builder;
+               public MethodBuilder MethodBuilder;
+               ReturnParameter return_attributes;
+               ListDictionary declarative_security;
+               protected MethodData MethodData;
 
-               protected SourceMethod (TypeContainer container, MethodBase builder,
-                                       ISourceFile file, Location start, Location end)
+               static string[] attribute_targets = new string [] { "method", "return" };
+
+               protected MethodOrOperator (DeclSpace parent, 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,
+                                       attrs, parameters)
                {
-                       this.container = container;
-                       this.builder = builder;
-                       
-                       CodeGen.SymbolWriter.OpenMethod (
-                               file, this, start.Row, start.Column, end.Row, start.Column);
                }
 
-               public string Name {
-                       get { return builder.Name; }
-               }
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.Target == AttributeTargets.ReturnValue) {
+                               if (return_attributes == null)
+                                       return_attributes = new ReturnParameter (MethodBuilder, Location);
 
-               public int NamespaceID {
-                       get { return container.NamespaceEntry.SymbolFileID; }
+                               return_attributes.ApplyAttributeBuilder (a, cb);
+                               return;
+                       }
+
+                       if (a.Type == TypeManager.methodimpl_attr_type &&
+                               (a.GetMethodImplOptions () & MethodImplOptions.InternalCall) != 0) {
+                               MethodBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
+                       }
+
+                       if (a.Type == TypeManager.dllimport_type) {
+                               const int extern_static = Modifiers.EXTERN | Modifiers.STATIC;
+                               if ((ModFlags & extern_static) != extern_static) {
+                                       Report.Error (601, a.Location, "The DllImport attribute must be specified on a method marked `static' and `extern'");
+                               }
+
+                               return;
+                       }
+
+                       if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (false)) {
+                               if (declarative_security == null)
+                                       declarative_security = new ListDictionary ();
+                               a.ExtractSecurityPermissionSet (declarative_security);
+                               return;
+                       }
+
+                       MethodBuilder.SetCustomAttribute (cb);
                }
 
-               public int Token {
+               public override AttributeTargets AttributeTargets {
                        get {
-                               if (builder is MethodBuilder)
-                                       return ((MethodBuilder) builder).GetToken ().Token;
-                               else if (builder is ConstructorBuilder)
-                                       return ((ConstructorBuilder) builder).GetToken ().Token;
-                               else
-                                       throw new NotSupportedException ();
+                               return AttributeTargets.Method; 
+                       }
+               }
+
+               public EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
+               {
+                       EmitContext ec = new EmitContext (this, ds, Parent, Location, ig, MemberType, ModFlags, false);
+
+                       ec.CurrentIterator = ds as Iterator;
+                       if (ec.CurrentIterator != null)
+                               ec.CurrentAnonymousMethod = ec.CurrentIterator.Host;
+
+                       return ec;
+               }
+
+               public override bool Define ()
+               {
+                       if (!DoDefine ())
+                               return false;
+
+                       if (!CheckAbstractAndExtern (block != null))
+                               return false;
+
+                       if (!CheckBase ())
+                               return false;
+
+                       MethodData = new MethodData (this, ModFlags, flags, this);
+
+                       if (!MethodData.Define (ParentContainer))
+                               return false;
+
+                       MethodBuilder = MethodData.MethodBuilder;
+
+                       if (MemberType.IsAbstract && MemberType.IsSealed) {
+                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
+                               return false;
+                       }
+
+                       return true;
+               }
+
+               public override void Emit ()
+               {
+                       if (OptAttributes != null)
+                               OptAttributes.Emit ();
+
+                       if (declarative_security != null) {
+                               foreach (DictionaryEntry de in declarative_security) {
+                                       MethodBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
+                               }
+                       }
+
+                       base.Emit ();
+               }
+
+               protected void Error_ConditionalAttributeIsNotValid ()
+               {
+                       Report.Error (577, Location,
+                               "Conditional not valid on `{0}' because it is a constructor, destructor, operator or explicit interface implementation",
+                               GetSignatureForError ());
+               }
+
+               public override bool MarkForDuplicationCheck ()
+               {
+                       caching_flags |= Flags.TestMethodDuplication;
+                       return true;
+               }
+
+               public override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
+
+               #region IMethodData Members
+
+               public CallingConventions CallingConventions {
+                       get {
+                               CallingConventions cc = Parameters.CallingConvention;
+                               if (Parameters.HasArglist)
+                                       block.HasVarargs = true;
+
+                               if (!IsInterface)
+                                       if ((ModFlags & Modifiers.STATIC) == 0)
+                                               cc |= CallingConventions.HasThis;
+
+                               // FIXME: How is `ExplicitThis' used in C#?
+                       
+                               return cc;
+                       }
+               }
+
+               public Type ReturnType {
+                       get {
+                               return MemberType;
+                       }
+               }
+
+               public MemberName MethodName {
+                       get {
+                               return MemberName;
+                       }
+               }
+
+               public new Location Location {
+                       get {
+                               return base.Location;
+                       }
+               }
+
+               protected override bool CheckBase() {
+                       if (!base.CheckBase ())
+                               return false;
+
+                       // TODO: Destructor should derive from MethodCore
+                       if (base_method != null && (ModFlags & Modifiers.OVERRIDE) != 0 && Name == "Finalize" &&
+                               base_method.DeclaringType == TypeManager.object_type && !(this is Destructor)) {
+                               Report.Error (249, Location, "Do not override object.Finalize. Instead, provide a destructor");
+                               return false;
+                       }
+
+                       return true;
+               }
+
+               /// <summary>
+               /// Returns true if method has conditional attribute and the conditions is not defined (method is excluded).
+               /// </summary>
+               public bool IsExcluded () {
+                       if ((caching_flags & Flags.Excluded_Undetected) == 0)
+                               return (caching_flags & Flags.Excluded) != 0;
+
+                       caching_flags &= ~Flags.Excluded_Undetected;
+
+                       if (base_method == null) {
+                               if (OptAttributes == null)
+                                       return false;
+
+                               Attribute[] attrs = OptAttributes.SearchMulti (TypeManager.conditional_attribute_type);
+
+                               if (attrs == null)
+                                       return false;
+
+                               foreach (Attribute a in attrs) {
+                                       string condition = a.GetConditionalAttributeValue ();
+                                       if (condition == null)
+                                               return false;
+
+                                       if (RootContext.AllDefines.Contains (condition))
+                                               return false;
+                               }
+
+                               caching_flags |= Flags.Excluded;
+                               return true;
+                       }
+
+                       IMethodData md = TypeManager.GetMethod (base_method);
+                       if (md == null) {
+                               if (AttributeTester.IsConditionalMethodExcluded (base_method)) {
+                                       caching_flags |= Flags.Excluded;
+                                       return true;
+                               }
+                               return false;
+                       }
+
+                       if (md.IsExcluded ()) {
+                               caching_flags |= Flags.Excluded;
+                               return true;
+                       }
+                       return false;
+               }
+
+               #endregion
+
+       }
+
+       public class SourceMethod : ISourceMethod
+       {
+               DeclSpace parent;
+               MethodBase builder;
+
+               protected SourceMethod (DeclSpace parent, MethodBase builder,
+                                       ISourceFile file, Location start, Location end)
+               {
+                       this.parent = parent;
+                       this.builder = builder;
+                       
+                       CodeGen.SymbolWriter.OpenMethod (file, this, start.Row, start.Column, end.Row, start.Column);
+               }
+
+               public string Name {
+                       get { return builder.Name; }
+               }
+
+               public int NamespaceID {
+                       get { return parent.NamespaceEntry.SymbolFileID; }
+               }
+
+               public int Token {
+                       get {
+                               if (builder is MethodBuilder)
+                                       return ((MethodBuilder) builder).GetToken ().Token;
+                               else if (builder is ConstructorBuilder)
+                                       return ((ConstructorBuilder) builder).GetToken ().Token;
+                               else
+                                       throw new NotSupportedException ();
                        }
                }
 
@@ -3681,8 +3691,7 @@ namespace Mono.CSharp {
                                CodeGen.SymbolWriter.CloseMethod ();
                }
 
-               public static SourceMethod Create (TypeContainer parent,
-                                                  MethodBase builder, Block block)
+               public static SourceMethod Create (DeclSpace parent, MethodBase builder, Block block)
                {
                        if (CodeGen.SymbolWriter == null)
                                return null;
@@ -3706,11 +3715,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class Method : MethodCore, IIteratorContainer, IMethodData {
-               public MethodBuilder MethodBuilder;
-               public MethodData MethodData;
-               ReturnParameter return_attributes;
-               ListDictionary declarative_security;
+       public class Method : MethodOrOperator, IIteratorContainer {
 
                /// <summary>
                ///   Modifiers allowed in a class declaration
@@ -3736,36 +3741,25 @@ namespace Mono.CSharp {
                //
                // return_type can be "null" for VOID values.
                //
-               public Method (TypeContainer ds, Expression return_type, int mod, bool is_iface,
+               public Method (DeclSpace parent, Expression return_type, int mod, bool is_iface,
                               MemberName name, Parameters parameters, Attributes attrs)
-                       : base (ds, return_type, mod,
+                       : base (parent, return_type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, attrs, parameters)
                {
                }
-
-               public override AttributeTargets AttributeTargets {
-                       get {
-                               return AttributeTargets.Method;
-                       }
-               }
                
                public override string GetSignatureForError()
                {
-                       if (IsOperator != null)
-                               return IsOperator.GetSignatureForError ();
-
                        return base.GetSignatureForError () + Parameters.GetSignatureForError ();
                }
 
-                void DuplicateEntryPoint (MethodInfo b, Location location)
-                {
-                        Report.Error (
-                                17, location,
-                                "Program `" + CodeGen.FileName +
-                                "' has more than one entry point defined: `" +
-                                TypeManager.CSharpSignature(b) + "'");
-                }
+               void Error_DuplicateEntryPoint (MethodInfo b, Location location)
+               {
+                       Report.Error (17, location,
+                               "Program `{0}' has more than one entry point defined: `{1}'",
+                               CodeGen.FileName, TypeManager.CSharpSignature(b));
+               }
 
                 bool IsEntryPoint (MethodBuilder b, Parameters pinfo)
                 {
@@ -3791,39 +3785,9 @@ namespace Mono.CSharp {
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
-                       if (a.Target == AttributeTargets.ReturnValue) {
-                               if (return_attributes == null)
-                                       return_attributes = new ReturnParameter (MethodBuilder, Location);
-
-                               return_attributes.ApplyAttributeBuilder (a, cb);
-                               return;
-                       }
-
-                       if (a.Type == TypeManager.methodimpl_attr_type &&
-                               (a.GetMethodImplOptions () & MethodImplOptions.InternalCall) != 0) {
-                               MethodBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
-                       }
-
-                       if (a.Type == TypeManager.dllimport_type) {
-                               const int extern_static = Modifiers.EXTERN | Modifiers.STATIC;
-                               if ((ModFlags & extern_static) != extern_static) {
-                                       Report.Error (601, a.Location, "The DllImport attribute must be specified on a method marked `static' and `extern'");
-                               }
-
-                               return;
-                       }
-
-                       if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (false)) {
-                               if (declarative_security == null)
-                                       declarative_security = new ListDictionary ();
-                               a.ExtractSecurityPermissionSet (declarative_security);
-                               return;
-                       }
-
                        if (a.Type == TypeManager.conditional_attribute_type) {
-                               if (IsOperator != null || IsExplicitImpl) {
-                                       Report.Error (577, Location, "Conditional not valid on `{0}' because it is a constructor, destructor, operator or explicit interface implementation",
-                                               GetSignatureForError ());
+                               if (IsExplicitImpl) {
+                                       Error_ConditionalAttributeIsNotValid ();
                                        return;
                                }
 
@@ -3849,19 +3813,19 @@ namespace Mono.CSharp {
                                }
 
                                for (int i = 0; i < ParameterInfo.Count; ++i) {
-                                       if ((ParameterInfo.ParameterModifier (i) & Parameter.Modifier.OUT) != 0) {
+                                       if ((ParameterInfo.ParameterModifier (i) & Parameter.Modifier.OUTMASK) != 0) {
                                                Report.Error (685, Location, "Conditional method `{0}' cannot have an out parameter", GetSignatureForError ());
                                                return;
                                        }
                                }
                        }
 
-                       MethodBuilder.SetCustomAttribute (cb);
+                       base.ApplyAttributeBuilder (a, cb);
                }
 
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = Parent.Methods;
+                       ArrayList ar = ParentContainer.Methods;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -3872,7 +3836,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = Parent.Properties;
+                       ar = ParentContainer.Properties;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        PropertyBase pb = (PropertyBase) ar [i];
@@ -3881,7 +3845,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = Parent.Indexers;
+                       ar = ParentContainer.Indexers;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        PropertyBase pb = (PropertyBase) ar [i];
@@ -3890,7 +3854,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = Parent.Events;
+                       ar = ParentContainer.Events;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        Event ev = (Event) ar [i];
@@ -3907,10 +3871,7 @@ namespace Mono.CSharp {
                //
                public override bool Define ()
                {
-                       if (!DoDefine ())
-                               return false;
-
-                       if (!CheckAbstractAndExtern (block != null))
+                       if (!base.Define ())
                                return false;
 
                        if (RootContext.StdLib && (ReturnType == TypeManager.arg_iterator_type || ReturnType == TypeManager.typed_reference_type)) {
@@ -3918,17 +3879,6 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (!CheckBase ())
-                               return false;
-
-                       if (IsOperator != null)
-                               flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
-
-                       MethodData = new MethodData (this, ModFlags, flags, this);
-
-                       if (!MethodData.Define (Parent))
-                               return false;
-
                        if (ReturnType == TypeManager.void_type && ParameterTypes.Length == 0 && 
                                Name == "Finalize" && !(this is Destructor)) {
                                Report.Warning (465, 1, Location, "Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
@@ -3946,37 +3896,35 @@ namespace Mono.CSharp {
                                        return false;
                        }
 
-                       MethodBuilder = MethodData.MethodBuilder;
-                       
                        //
                        // This is used to track the Entry Point,
                        //
                        if (Name == "Main" &&
-                           ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint && 
-                           (RootContext.MainClass == null ||
-                            RootContext.MainClass == Parent.TypeBuilder.FullName)){
-                                if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
-                                        IMethodData md = TypeManager.GetMethod (MethodBuilder);
-                                        md.SetMemberIsUsed ();
-
-                                        if (RootContext.EntryPoint == null) {
-                                                RootContext.EntryPoint = MethodBuilder;
-                                                RootContext.EntryPointLocation = Location;
-                                        } else {
-                                                DuplicateEntryPoint (RootContext.EntryPoint, RootContext.EntryPointLocation);
-                                                DuplicateEntryPoint (MethodBuilder, Location);
-                                        }
-                                } else {
+                               ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint && 
+                               (RootContext.MainClass == null ||
+                               RootContext.MainClass == Parent.TypeBuilder.FullName)){
+                               if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
+                                       IMethodData md = TypeManager.GetMethod (MethodBuilder);
+                                       md.SetMemberIsUsed ();
+
+                                       if (RootContext.EntryPoint == null) {
+                                               if (Parent.IsGeneric){
+                                                       Report.Error (-201, Location,
+                                                                     "Entry point can not be defined in a generic class");
+                                               }
+
+                                               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));
                                }
                        }
 
-                       if (MemberType.IsAbstract && MemberType.IsSealed) {
-                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
-                               return false;
-                       }
-
                        return true;
                }
 
@@ -3985,164 +3933,46 @@ namespace Mono.CSharp {
                // 
                public override void Emit ()
                {
-                       MethodData.Emit (Parent, this);
+                       MethodData.Emit (Parent);
                        base.Emit ();
 
-                       if (declarative_security != null) {
-                               foreach (DictionaryEntry de in declarative_security) {
-                                       MethodBuilder.AddDeclarativeSecurity ((SecurityAction)de.Key, (PermissionSet)de.Value);
-                               }
-                       }
-
-                       Block = null;
-                       MethodData = null;
-               }
-
-               public static void Error1599 (Location loc, Type t)
-               {
-                       Report.Error (1599, loc, "Method or delegate cannot return type `{0}'", TypeManager.CSharpName (t));
-               }
-
-               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
-               {
-                       MethodInfo mi = (MethodInfo) container.BaseCache.FindMemberToOverride (
-                               container.TypeBuilder, Name, ParameterTypes, false);
-
-                       if (mi == null)
-                               return null;
-
-                       base_ret_type = mi.ReturnType;
-                       return mi;
-               }
-
-               public override bool MarkForDuplicationCheck ()
-               {
-                       caching_flags |= Flags.TestMethodDuplication;
-                       return true;
-               }
-
-               protected override bool VerifyClsCompliance(DeclSpace ds)
-               {
-                       if (!base.VerifyClsCompliance (ds))
-                               return false;
-
-                       if (ParameterInfo.Count > 0) {
-                               ArrayList al = (ArrayList)ds.MemberCache.Members [Name];
-                               if (al.Count > 1)
-                                       ds.MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
-                       }
-
-                       return true;
-               }
-
-               #region IMethodData Members
-
-               public CallingConventions CallingConventions {
-                       get {
-                               CallingConventions cc = Parameters.CallingConvention;
-                               if (Parameters.HasArglist)
-                                       block.HasVarargs = true;
-
-                               if (!IsInterface)
-                                       if ((ModFlags & Modifiers.STATIC) == 0)
-                                               cc |= CallingConventions.HasThis;
-
-                               // FIXME: How is `ExplicitThis' used in C#?
-                       
-                               return cc;
-                       }
-               }
-
-               public Type ReturnType {
-                       get {
-                               return MemberType;
-                       }
-               }
-
-               public MemberName MethodName {
-                       get {
-                               return MemberName;
-                       }
-               }
-
-               public new Location Location {
-                       get {
-                               return base.Location;
-                       }
-               }
-
-               protected override bool CheckBase() {
-                       if (!base.CheckBase ())
-                               return false;
-
-                       // TODO: Destructor should derive from MethodCore
-                       if (base_method != null && (ModFlags & Modifiers.OVERRIDE) != 0 && Name == "Finalize" &&
-                               base_method.DeclaringType == TypeManager.object_type && !(this is Destructor)) {
-                               Report.Error (249, Location, "Do not override object.Finalize. Instead, provide a destructor");
-                               return false;
-                       }
-
-                       return true;
-               }
-
-               public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
-               {
-                       EmitContext ec = new EmitContext (
-                               tc, Parent, Location, ig, ReturnType, ModFlags, false);
-
-                       ec.CurrentIterator = tc as Iterator;
-                       if (ec.CurrentIterator != null)
-                               ec.CurrentAnonymousMethod = ec.CurrentIterator.Host;
-
-                       return ec;
+                       Block = null;
+                       MethodData = null;
                }
 
-               /// <summary>
-               /// Returns true if method has conditional attribute and the conditions is not defined (method is excluded).
-               /// </summary>
-               public bool IsExcluded (EmitContext ec)
+               public static void Error1599 (Location loc, Type t)
                {
-                       if ((caching_flags & Flags.Excluded_Undetected) == 0)
-                               return (caching_flags & Flags.Excluded) != 0;
-
-                       caching_flags &= ~Flags.Excluded_Undetected;
-
-                       if (base_method == null) {
-                               if (OptAttributes == null)
-                                       return false;
+                       Report.Error (1599, loc, "Method or delegate cannot return type `{0}'", TypeManager.CSharpName (t));
+               }
 
-                               Attribute[] attrs = OptAttributes.SearchMulti (TypeManager.conditional_attribute_type, ec);
+               protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
+               {
+                       MethodInfo mi = (MethodInfo) ParentContainer.BaseCache.FindMemberToOverride (
+                               Parent.TypeBuilder, Name, ParameterTypes, false);
 
-                               if (attrs == null)
-                                       return false;
+                       if (mi == null)
+                               return null;
 
-                               foreach (Attribute a in attrs) {
-                                       string condition = a.GetConditionalAttributeValue (Parent.EmitContext);
-                                       if (RootContext.AllDefines.Contains (condition))
-                                               return false;
-                               }
+                       if (mi.IsSpecialName)
+                               return null;
 
-                               caching_flags |= Flags.Excluded;
-                               return true;
-                       }
+                       base_ret_type = mi.ReturnType;
+                       return mi;
+               }
 
-                       IMethodData md = TypeManager.GetMethod (base_method);
-                       if (md == null) {
-                               if (AttributeTester.IsConditionalMethodExcluded (base_method)) {
-                                       caching_flags |= Flags.Excluded;
-                                       return true;
-                               }
+               protected override bool VerifyClsCompliance ()
+               {
+                       if (!base.VerifyClsCompliance ())
                                return false;
-                       }
 
-                       if (md.IsExcluded (ec)) {
-                               caching_flags |= Flags.Excluded;
-                               return true;
+                       if (ParameterInfo.Count > 0) {
+                               ArrayList al = (ArrayList)ParentContainer.MemberCache.Members [Name];
+                               if (al.Count > 1)
+                                       MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
                        }
-                       return false;
-               }
 
-               #endregion
+                       return true;
+               }
        }
 
        public abstract class ConstructorInitializer {
@@ -4192,14 +4022,14 @@ namespace Mono.CSharp {
                                t = ec.ContainerType;
 
                        base_constructor_group = Expression.MemberLookup (
-                               ec, t, ".ctor", MemberTypes.Constructor,
+                               ec.ContainerType, t, ".ctor", MemberTypes.Constructor,
                                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                loc);
                        
                        if (base_constructor_group == null){
                                error = true;
                                base_constructor_group = Expression.MemberLookup (
-                                       ec, t, null, t, ".ctor", MemberTypes.Constructor,
+                                       t, null, t, ".ctor", MemberTypes.Constructor,
                                        BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                        loc);
                        }
@@ -4213,11 +4043,12 @@ namespace Mono.CSharp {
                        if (base_constructor == null) {
                                if (errors == Report.Errors)
                                        Invocation.Error_WrongNumArguments (loc, TypeManager.CSharpSignature (caller_builder),
-                                               argument_list.Count);
+                                               argument_list == null ? 0 : argument_list.Count);
                                return false;
                        }
 
                        if (error) {
+                               Report.SymbolRelatedToPreviousError (base_constructor);
                                Expression.ErrorIsInaccesible (loc, TypeManager.CSharpSignature (base_constructor));
                                base_constructor = null;
                                return false;
@@ -4255,14 +4086,6 @@ namespace Mono.CSharp {
                        base (null, loc)
                {
                }
-
-               public override void Emit(EmitContext ec)
-               {
-                       bool old = ec.TestObsoleteMethodUsage;
-                       ec.TestObsoleteMethodUsage = false;
-                       base.Emit (ec);
-                       ec.TestObsoleteMethodUsage = old;
-               }
        }
 
        public class ConstructorThisInitializer : ConstructorInitializer {
@@ -4289,29 +4112,27 @@ namespace Mono.CSharp {
                        Modifiers.EXTERN |              
                        Modifiers.PRIVATE;
 
+               static string[] attribute_targets = new string [] { "method" };
+
                bool has_compliant_args = false;
                //
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
-               public Constructor (TypeContainer ds, string name, int mod, Parameters args,
+               public Constructor (DeclSpace parent, string name, int mod, Parameters args,
                                    ConstructorInitializer init, Location loc)
-                       : base (ds, null, mod, AllowedModifiers, false, new MemberName (name, loc),
+                       : base (parent, null, mod, AllowedModifiers, false, new MemberName (name, loc),
                                null, args)
                {
                        Initializer = init;
                }
 
                public bool HasCompliantArgs {
-                       get {
-                               return has_compliant_args;
-                       }
+                       get { return has_compliant_args; }
                }
 
                public override AttributeTargets AttributeTargets {
-                       get {
-                               return AttributeTargets.Constructor;
-                       }
+                       get { return AttributeTargets.Constructor; }
                }
 
 
@@ -4338,12 +4159,17 @@ namespace Mono.CSharp {
                                return;
                        }
 
+                       if (a.Type == TypeManager.methodimpl_attr_type &&
+                               (a.GetMethodImplOptions () & MethodImplOptions.InternalCall) != 0) {
+                               ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
+                       }
+
                        ConstructorBuilder.SetCustomAttribute (cb);
                }
                
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = Parent.InstanceConstructors;
+                       ArrayList ar = ParentContainer.InstanceConstructors;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -4358,18 +4184,25 @@ namespace Mono.CSharp {
 
                protected override bool CheckBase ()
                {
+                       if ((ModFlags & Modifiers.STATIC) != 0) {
+                               if (!Parameters.Empty) {
+                                       Report.Error (132, Location, "`{0}': The static constructor must be parameterless",
+                                               GetSignatureForError ());
+                                       return false;
+                               }
+
+                               // the rest can be ignored
+                               return true;
+                       }
+
                        // Check whether arguments were correct.
                        if (!DoDefineParameters ())
                                return false;
 
-                       // TODO: skip the rest for generated ctor
-                       if ((ModFlags & Modifiers.STATIC) != 0)
-                               return true;
-
                        if (!CheckForDuplications ())
                                return false;
 
-                       if (Parent.Kind == Kind.Struct) {
+                       if (ParentContainer.Kind == Kind.Struct) {
                                if (ParameterTypes.Length == 0) {
                                        Report.Error (568, Location, 
                                                "Structs cannot contain explicit parameterless constructors");
@@ -4414,8 +4247,6 @@ namespace Mono.CSharp {
                                                ca |= MethodAttributes.Family;
                                } else if ((ModFlags & Modifiers.INTERNAL) != 0)
                                        ca |= MethodAttributes.Assembly;
-                               else if (IsDefault ())
-                                       ca |= MethodAttributes.Public;
                                else
                                        ca |= MethodAttributes.Private;
                        }
@@ -4434,7 +4265,7 @@ namespace Mono.CSharp {
                        if ((ModFlags & Modifiers.UNSAFE) != 0)
                                ConstructorBuilder.InitLocals = false;
 
-                       if (Parent.IsComImport) {
+                       if (ParentContainer.IsComImport) {
                                if (!IsDefault ()) {
                                        Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
                                                Parent.GetSignatureForError ());
@@ -4453,21 +4284,24 @@ namespace Mono.CSharp {
                //
                public override void Emit ()
                {
-                       EmitContext ec = CreateEmitContext (null, null);
+                       if (OptAttributes != null)
+                               OptAttributes.Emit ();
 
-                       // If this is a non-static `struct' constructor and doesn't have any
-                       // initializer, it must initialize all of the struct's fields.
-                       if ((Parent.Kind == Kind.Struct) &&
-                           ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
-                               Block.AddThisVariable (Parent, Location);
+                       EmitContext ec = CreateEmitContext (null, null);
 
                        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) &&
+                                       ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
+                                       block.AddThisVariable (Parent, Location);
+
                                if (!block.ResolveMeta (ec, ParameterInfo))
                                        block = null;
                        }
 
                        if ((ModFlags & Modifiers.STATIC) == 0){
-                               if (Parent.Kind == Kind.Class && Initializer == null)
+                               if (ParentContainer.Kind == Kind.Class && Initializer == null)
                                        Initializer = new GeneratedBaseInitializer (Location);
 
 
@@ -4482,7 +4316,7 @@ namespace Mono.CSharp {
                                ec.IsStatic = false;
                        }
 
-                       Parameters.ApplyAttributes (ec, ConstructorBuilder);
+                       Parameters.ApplyAttributes (ConstructorBuilder);
                        
                        SourceMethod source = SourceMethod.Create (
                                Parent, ConstructorBuilder, block);
@@ -4490,7 +4324,7 @@ namespace Mono.CSharp {
                        //
                        // Classes can have base initializers and instance field initializers.
                        //
-                       if (Parent.Kind == Kind.Class){
+                       if (ParentContainer.Kind == Kind.Class){
                                if ((ModFlags & Modifiers.STATIC) == 0){
 
                                        //
@@ -4498,21 +4332,15 @@ namespace Mono.CSharp {
                                        // do not emit field initializers, they are initialized in the other constructor
                                        //
                                        if (!(Initializer != null && Initializer is ConstructorThisInitializer))
-                                               Parent.EmitFieldInitializers (ec);
+                                               ParentContainer.EmitFieldInitializers (ec);
                                }
                        }
                        if (Initializer != null) {
-                               if (GetObsoleteAttribute () != null || Parent.GetObsoleteAttribute () != null)
-                                       ec.TestObsoleteMethodUsage = false;
-
                                Initializer.Emit (ec);
                        }
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
-                               Parent.EmitFieldInitializers (ec);
-
-                       if (OptAttributes != null) 
-                               OptAttributes.Emit (ec, this);
+                               ParentContainer.EmitFieldInitializers (ec);
 
                        ec.EmitTopBlock (this, block);
 
@@ -4531,7 +4359,7 @@ namespace Mono.CSharp {
                }
 
                // Is never override
-               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
+               protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
                        return null;
                }
@@ -4541,18 +4369,24 @@ namespace Mono.CSharp {
                        return base.GetSignatureForError () + Parameters.GetSignatureForError ();
                }
 
-               protected override bool VerifyClsCompliance (DeclSpace ds)
+               public override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
+
+               protected override bool VerifyClsCompliance ()
                {
-                       if (!base.VerifyClsCompliance (ds) || !IsExposedFromAssembly (ds)) {
+                       if (!base.VerifyClsCompliance () || !IsExposedFromAssembly ()) {
                                return false;
                        }
                        
                        if (ParameterInfo.Count > 0) {
-                               ArrayList al = (ArrayList)ds.MemberCache.Members [".ctor"];
+                               ArrayList al = (ArrayList)Parent.MemberCache.Members [".ctor"];
                                if (al.Count > 3)
-                                       ds.MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
+                                       MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
  
-                               if (ds.TypeBuilder.IsSubclassOf (TypeManager.attribute_type)) {
+                               if (Parent.TypeBuilder.IsSubclassOf (TypeManager.attribute_type)) {
                                        foreach (Type param in ParameterTypes) {
                                                if (param.IsArray) {
                                                        return true;
@@ -4570,7 +4404,7 @@ namespace Mono.CSharp {
                        get {
                                CallingConventions cc = Parameters.CallingConvention;
 
-                               if (Parent.Kind == Kind.Class)
+                               if (ParentContainer.Kind == Kind.Class)
                                        if ((ModFlags & Modifiers.STATIC) == 0)
                                                cc |= CallingConventions.HasThis;
 
@@ -4598,13 +4432,13 @@ namespace Mono.CSharp {
                        }
                }
 
-               public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+               public EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                {
                        ILGenerator ig_ = ConstructorBuilder.GetILGenerator ();
-                       return new EmitContext (Parent, Location, ig_, null, ModFlags, true);
+                       return new EmitContext (this, Parent, Location, ig_, null, ModFlags, true);
                }
 
-               public bool IsExcluded(EmitContext ec)
+               public bool IsExcluded()
                {
                        return false;
                }
@@ -4626,11 +4460,11 @@ namespace Mono.CSharp {
                Attributes OptAttributes { get; }
                ToplevelBlock Block { get; set; }
 
-               EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig);
+               EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig);
                ObsoleteAttribute GetObsoleteAttribute ();
                string GetSignatureForError ();
-               bool IsExcluded (EmitContext ec);
-               bool IsClsComplianceRequired (DeclSpace ds);
+               bool IsExcluded ();
+               bool IsClsComplianceRequired ();
                void SetMemberIsUsed ();
        }
 
@@ -4670,30 +4504,33 @@ namespace Mono.CSharp {
                        this.method = method;
                }
 
-               public bool Define (TypeContainer container)
+               public bool Define (DeclSpace parent)
                {
                        string name = method.MethodName.Name;
                        string method_name = name;
 
-                       if (container.Pending != null){
+                       TypeContainer container = ((TypeContainer) parent).PartialContainer;
+
+                       PendingImplementation pending = container.PendingImplementations;
+                       if (pending != null){
                                if (member is Indexer) // TODO: test it, but it should work without this IF
-                                       implementing = container.Pending.IsInterfaceIndexer (
+                                       implementing = pending.IsInterfaceIndexer (
                                                member.InterfaceType, method.ReturnType, method.ParameterInfo);
                                else
-                                       implementing = container.Pending.IsInterfaceMethod (
+                                       implementing = pending.IsInterfaceMethod (
                                                member.InterfaceType, name, method.ReturnType, method.ParameterInfo);
 
                                if (member.InterfaceType != null){
                                        if (implementing == null){
                                                if (member is PropertyBase) {
                                                        Report.Error (550, method.Location, "`{0}' is an accessor not found in interface member `{1}{2}'",
-                                                               method.GetSignatureForError (), TypeManager.CSharpName (member.InterfaceType),
-                                                               member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.')));
+                                                                     method.GetSignatureForError (), TypeManager.CSharpName (member.InterfaceType),
+                                                                     member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.')));
 
                                                } else {
                                                        Report.Error (539, method.Location,
-                                                               "`{0}.{1}' in explicit interface declaration is not a member of interface",
-                                                               TypeManager.CSharpName (member.InterfaceType), member.ShortName);
+                                                                     "`{0}.{1}' in explicit interface declaration is not a member of interface",
+                                                                     TypeManager.CSharpName (member.InterfaceType), member.ShortName);
                                                }
                                                return false;
                                        }
@@ -4707,7 +4544,15 @@ namespace Mono.CSharp {
                                } 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",
@@ -4743,6 +4588,12 @@ namespace Mono.CSharp {
                                                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)){
                                                //
@@ -4790,9 +4641,7 @@ namespace Mono.CSharp {
                                        flags |= MethodAttributes.Final;
                        }
 
-                       EmitContext ec = method.CreateEmitContext (container, null);
-
-                       DefineMethodBuilder (ec, container, method_name, method.ParameterInfo.Types);
+                       DefineMethodBuilder (container, method_name, method.ParameterInfo.Types);
 
                        if (builder == null)
                                return false;
@@ -4805,11 +4654,11 @@ namespace Mono.CSharp {
                                // clear the pending implemntation flag
                                //
                                if (member is Indexer) {
-                                       container.Pending.ImplementIndexer (
+                                       pending.ImplementIndexer (
                                                member.InterfaceType, builder, method.ReturnType,
                                                method.ParameterInfo, member.IsExplicitImpl);
                                } else
-                                       container.Pending.ImplementMethod (
+                                       pending.ImplementMethod (
                                                member.InterfaceType, name, method.ReturnType,
                                                method.ParameterInfo, member.IsExplicitImpl);
 
@@ -4828,18 +4677,18 @@ namespace Mono.CSharp {
                /// <summary>
                /// Create the MethodBuilder for the method 
                /// </summary>
-               void DefineMethodBuilder (EmitContext ec, TypeContainer container, string method_name, Type[] ParameterTypes)
+               void DefineMethodBuilder (TypeContainer container, string method_name, Type[] ParameterTypes)
                {
                        const int extern_static = Modifiers.EXTERN | Modifiers.STATIC;
 
                        if ((modifiers & extern_static) == extern_static) {
 
                                if (method.OptAttributes != null) {
-                                       Attribute dllimport_attribute = method.OptAttributes.Search (TypeManager.dllimport_type, ec);
+                                       Attribute dllimport_attribute = method.OptAttributes.Search (TypeManager.dllimport_type);
                                        if (dllimport_attribute != null) {
                                                flags |= MethodAttributes.PinvokeImpl;
                                                builder = dllimport_attribute.DefinePInvokeMethod (
-                                                       ec, container.TypeBuilder, method_name, flags,
+                                                       container.TypeBuilder, method_name, flags,
                                                        method.ReturnType, ParameterTypes);
 
                                                return;
@@ -4849,7 +4698,7 @@ namespace Mono.CSharp {
                                // for extern static method must be specified either DllImport attribute or MethodImplAttribute.
                                // We are more strict than Microsoft and report CS0626 like error
                                if (method.OptAttributes == null ||
-                                       !method.OptAttributes.Contains (TypeManager.methodimpl_attr_type, ec)) {
+                                       !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 ());
                                        return;
@@ -4864,28 +4713,19 @@ namespace Mono.CSharp {
                //
                // Emits the code
                // 
-               public void Emit (TypeContainer container, Attributable kind)
+               public void Emit (DeclSpace parent)
                {
                        EmitContext ec;
                        if ((flags & MethodAttributes.PinvokeImpl) == 0)
-                               ec = method.CreateEmitContext (container, builder.GetILGenerator ());
+                               ec = method.CreateEmitContext (parent, builder.GetILGenerator ());
                        else
-                               ec = method.CreateEmitContext (container, null);
-
-                       if (method.GetObsoleteAttribute () != null || container.GetObsoleteAttribute () != null)
-                               ec.TestObsoleteMethodUsage = false;
-
-                       method.ParameterInfo.ApplyAttributes (ec, MethodBuilder);
+                               ec = method.CreateEmitContext (parent, null);
 
-                       Attributes OptAttributes = method.OptAttributes;
-
-                       if (OptAttributes != null)
-                               OptAttributes.Emit (ec, kind);
+                       method.ParameterInfo.ApplyAttributes (MethodBuilder);
 
                        ToplevelBlock block = method.Block;
                        
-                       SourceMethod source = SourceMethod.Create (
-                               container, MethodBuilder, method.Block);
+                       SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
 
                        //
                        // Handle destructors specially
@@ -4919,7 +4759,7 @@ namespace Mono.CSharp {
                        
                        if (ec.ContainerType.BaseType != null) {
                                Expression member_lookup = Expression.MemberLookup (
-                                       ec, ec.ContainerType.BaseType, null, ec.ContainerType.BaseType,
+                                       ec.ContainerType.BaseType, null, ec.ContainerType.BaseType,
                                        "Finalize", MemberTypes.Method, Expression.AllBindingFlags, method.Location);
 
                                if (member_lookup != null){
@@ -4939,18 +4779,19 @@ namespace Mono.CSharp {
        // TODO: Should derive from MethodCore
        public class Destructor : Method {
 
-               public Destructor (TypeContainer ds, Expression return_type, int mod,
+               static string[] attribute_targets = new string [] { "method" };
+
+               public Destructor (DeclSpace parent, Expression return_type, int mod,
                                   string name, Parameters parameters, Attributes attrs,
                                   Location l)
-                       : base (ds, return_type, mod, false, new MemberName (name, l),
+                       : base (parent, return_type, mod, false, new MemberName (name, l),
                                parameters, attrs)
                { }
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
                        if (a.Type == TypeManager.conditional_attribute_type) {
-                               Report.Error (577, Location, "Conditional not valid on `{0}' because it is a constructor, destructor, operator or explicit interface implementation",
-                                       GetSignatureForError ());
+                               Error_ConditionalAttributeIsNotValid ();
                                return;
                        }
 
@@ -4962,6 +4803,11 @@ namespace Mono.CSharp {
                        return Parent.GetSignatureForError () + ".~" + Parent.MemberName.Name + "()";
                }
 
+               public override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
        }
        
        abstract public class MemberBase : MemberCore {
@@ -4977,9 +4823,11 @@ namespace Mono.CSharp {
                //
                public string ShortName {
                        get { return MemberName.Name; }
-                       set {
-                               SetMemberName (new MemberName (MemberName.Left, value, Location));
-                       }
+                       set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
+               }
+
+               public TypeContainer ParentContainer {
+                       get { return ((TypeContainer) Parent).PartialContainer; }
                }
 
                //
@@ -4989,11 +4837,7 @@ namespace Mono.CSharp {
                public Type MemberType {
                        get {
                                if (member_type == null && Type != null) {
-                                       EmitContext ec = Parent.EmitContext;
-                                       bool old_unsafe = ec.InUnsafe;
-                                       ec.InUnsafe = InUnsafe;
-                                       Type = Type.ResolveAsTypeTerminal (ec, false);
-                                       ec.InUnsafe = old_unsafe;
+                                       Type = Type.ResolveAsTypeTerminal (ResolveContext, false);
                                        if (Type != null) {
                                                member_type = Type.Type;
                                        }
@@ -5020,7 +4864,7 @@ namespace Mono.CSharp {
                //
                // The constructor is only exposed to our children
                //
-               protected MemberBase (TypeContainer parent, Expression type, int mod,
+               protected MemberBase (DeclSpace parent, Expression type, int mod,
                                      int allowed_mod, int def_mod, MemberName name,
                                      Attributes attrs)
                        : base (parent, name, attrs)
@@ -5033,7 +4877,7 @@ namespace Mono.CSharp {
 
                protected virtual bool CheckBase ()
                {
-                       if ((ModFlags & Modifiers.PROTECTED) != 0 && Parent.Kind == Kind.Struct) {
+                       if ((ModFlags & Modifiers.PROTECTED) != 0 && ParentContainer.Kind == Kind.Struct) {
                                Report.Error (666, Location, "`{0}': new protected member declared in struct", GetSignatureForError ());
                                return false;
                        }
@@ -5047,13 +4891,8 @@ namespace Mono.CSharp {
                        return true;
        }
 
-
                protected virtual bool DoDefine ()
                {
-                       EmitContext ec = Parent.EmitContext;
-                       if (ec == null)
-                               throw new InternalErrorException ("MemberBase.DoDefine called too early");
-
                        if (Name == null)
                                throw new InternalErrorException ();
 
@@ -5068,7 +4907,7 @@ namespace Mono.CSharp {
                                        MethodAttributes.NewSlot |
                                        MethodAttributes.Virtual;
                        } else {
-                               if (!Parent.MethodModifiersValid (this))
+                               if (!ParentContainer.MethodModifiersValid (this))
                                        return false;
 
                                flags = Modifiers.MethodAttr (ModFlags);
@@ -5077,8 +4916,6 @@ namespace Mono.CSharp {
                        if (MemberType == null)
                                return false;
 
-                       CheckObsoleteType (Type);
-
                        if ((Parent.ModFlags & Modifiers.SEALED) != 0 && 
                                (ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0) {
                                        Report.Error (549, Location, "New virtual member `{0}' is declared in a sealed class `{1}'",
@@ -5119,23 +4956,20 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (MemberType.IsPointer && !UnsafeOK (Parent))
-                               return false;
-
                        if (IsExplicitImpl) {
                                Expression expr = MemberName.Left.GetTypeExpression ();
-                               TypeExpr texpr = expr.ResolveAsTypeTerminal (ec, false);
+                               TypeExpr texpr = expr.ResolveAsTypeTerminal (ResolveContext, false);
                                if (texpr == null)
                                        return false;
 
-                               InterfaceType = texpr.ResolveType (ec);
+                               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.VerifyImplements (this))
+                               if (!ParentContainer.VerifyImplements (this))
                                        return false;
                                
                                Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
@@ -5153,13 +4987,13 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected override bool VerifyClsCompliance(DeclSpace ds)
+               protected override bool VerifyClsCompliance()
                {
-                       if (base.VerifyClsCompliance (ds)) {
+                       if (base.VerifyClsCompliance ()) {
                                return true;
                        }
 
-                       if (IsInterface && HasClsCompliantAttribute && ds.IsClsComplianceRequired (ds)) {
+                       if (IsInterface && HasClsCompliantAttribute && Parent.IsClsComplianceRequired ()) {
                                Report.Error (3010, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
                        }
                        return false;
@@ -5174,6 +5008,8 @@ namespace Mono.CSharp {
        abstract public class FieldBase : MemberBase {
                public FieldBuilder  FieldBuilder;
                public Status status;
+               protected Expression initializer;
+               ExpressionStatement initializerStatement;
 
                [Flags]
                public enum Status : byte {
@@ -5187,16 +5023,11 @@ namespace Mono.CSharp {
                /// </summary>
                public MemberInfo conflict_symbol;
 
-               //
-               // The constructor is only exposed to our children
-               //
-               protected FieldBase (TypeContainer parent, Expression type, int mod,
-                                    int allowed_mod, MemberName name, object init,
-                                    Attributes attrs)
+               protected FieldBase (DeclSpace parent, Expression type, int mod,
+                                    int allowed_mod, MemberName name, Attributes attrs)
                        : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE,
                                name, attrs)
                {
-                       this.init = init;
                }
 
                public override AttributeTargets AttributeTargets {
@@ -5223,52 +5054,9 @@ namespace Mono.CSharp {
                        FieldBuilder.SetCustomAttribute (cb);
                }
 
-               //
-               // Whether this field has an initializer.
-               //
-               public bool HasInitializer {
-                       get {
-                               return init != null;
-                       }
-               }
-
-               protected readonly Object init;
-
-               // Private.
-               Expression init_expr;
-               bool init_expr_initialized = false;
-
-               //
-               // Resolves and returns the field initializer.
-               //
-               public Expression GetInitializerExpression (EmitContext ec)
+               public void EmitInitializer (EmitContext ec)
                {
-                       if (init_expr_initialized)
-                               return init_expr;
-
-                       Expression e;
-                       if (init is Expression)
-                               e = (Expression) init;
-                       else
-                               e = new ArrayCreation (Type, "", (ArrayList)init, Location);
-
-                       // TODO: Any reason why we are using parent EC ?
-                       EmitContext parent_ec = Parent.EmitContext;
-
-                       bool old_is_static = parent_ec.IsStatic;
-                       bool old_is_ctor = parent_ec.IsConstructor;
-                       parent_ec.IsStatic = ec.IsStatic;
-                       parent_ec.IsConstructor = ec.IsConstructor;
-                       parent_ec.IsFieldInitializer = true;
-                       e = e.DoResolve (parent_ec);
-                       parent_ec.IsFieldInitializer = false;
-                       parent_ec.IsStatic = old_is_static;
-                       parent_ec.IsConstructor = old_is_ctor;
-
-                       init_expr = e;
-                       init_expr_initialized = true;
-
-                       return init_expr;
+                       initializerStatement.EmitStatement (ec);
                }
 
                protected override bool CheckBase ()
@@ -5280,7 +5068,7 @@ namespace Mono.CSharp {
                        if (IsInterface)
                                return true;
  
-                       conflict_symbol = Parent.FindBaseMemberWithSameName (Name, false);
+                       conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, 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 ());
@@ -5297,6 +5085,15 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               public Expression Initializer {
+                       set {
+                               if (value != null) {
+                                       this.initializer = value;
+                                       ParentContainer.RegisterFieldForInitialization (this);
+                               }
+                       }
+               }
+
                protected virtual bool IsFieldClsCompliant {
                        get {
                                if (FieldBuilder == null)
@@ -5306,15 +5103,49 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override string[] ValidAttributeTargets {
+               public Expression ResolveInitializer ()
+               {
+                       // 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 (FieldBuilder == null)
+                               return null;
+
+                       FieldExpr fe = new FieldExpr (FieldBuilder, Location, true);
+                       if ((ModFlags & Modifiers.STATIC) == 0) 
+                       {
+                               fe.InstanceExpression = CompilerGeneratedThis.Instance;
+                       }
+
+                       initializerStatement = new Assign (fe, initializer, Location).ResolveStatement (ec);
+                       return initializer;
+               }
+
+               public bool HasDefaultInitializer
+               {
+                       get
+                       {
+                               Constant c = initializer as Constant;
+                               if (c == null)
+                                       return false;
+
+                               return c.IsDefaultInitializer (MemberType);
+                       }
+               }
+
+               public override string[] ValidAttributeTargets 
+               {
                        get {
                                return attribute_targets;
                        }
                }
 
-               protected override bool VerifyClsCompliance (DeclSpace ds)
+               protected override bool VerifyClsCompliance ()
                {
-                       if (!base.VerifyClsCompliance (ds))
+                       if (!base.VerifyClsCompliance ())
                                return false;
 
                        if (!IsFieldClsCompliant) {
@@ -5330,11 +5161,11 @@ namespace Mono.CSharp {
                }
        }
 
-       public abstract class FieldMember: FieldBase
+       public abstract class FieldMember : FieldBase
        {
-               protected FieldMember (TypeContainer parent, Expression type, int mod,
-                       int allowed_mod, MemberName name, object init, Attributes attrs)
-                       : base (parent, type, mod, allowed_mod | Modifiers.ABSTRACT, name, init, attrs)
+               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");
@@ -5346,7 +5177,7 @@ namespace Mono.CSharp {
                        {
                                status |= Status.HAS_OFFSET;
 
-                               if (!Parent.HasExplicitLayout) {
+                               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;
                                }
@@ -5367,18 +5198,11 @@ namespace Mono.CSharp {
                        base.ApplyAttributeBuilder (a, cb);
                }
 
-
                public override bool Define()
                {
-                       EmitContext ec = Parent.EmitContext;
-                       if (ec == null)
-                               throw new InternalErrorException ("FieldMember.Define called too early");
-
                        if (MemberType == null || Type == null)
                                return false;
 
-                       CheckObsoleteType (Type);
-
                        if (MemberType == TypeManager.void_type) {
                                Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
                                return false;
@@ -5398,20 +5222,16 @@ namespace Mono.CSharp {
                        if (!IsTypePermitted ())
                                return false;
 
-                       if (MemberType.IsPointer && !UnsafeOK (Parent))
-                               return false;
-
                        return true;
                }
 
                public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (Parent, Location, null, FieldBuilder.FieldType, ModFlags);
-                               OptAttributes.Emit (ec, this);
+                               OptAttributes.Emit ();
                        }
 
-                       if (Parent.HasExplicitLayout && ((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0) {
+                       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 ());
                        }
 
@@ -5461,7 +5281,7 @@ namespace Mono.CSharp {
        /// <summary>
        /// Fixed buffer implementation
        /// </summary>
-       public class FixedField: FieldMember, IFixedBuffer
+       public class FixedField : FieldMember, IFixedBuffer
        {
                public const string FixedElementName = "FixedElementField";
                static int GlobalCounter = 0;
@@ -5480,9 +5300,9 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public FixedField (TypeContainer parent, Expression type, int mod, string name,
+               public FixedField (DeclSpace parent, Expression type, int mod, string name,
                        Expression size_expr, Attributes attrs, Location loc):
-                       base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), null, attrs)
+                       base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
                {
                        if (RootContext.Version == LanguageVersion.ISO_1)
                                Report.FeatureIsNotStandardized (loc, "fixed size buffers");
@@ -5497,7 +5317,7 @@ namespace Mono.CSharp {
                                Report.Warning (-23, 1, Location, "Only private or internal fixed sized buffers are supported by .NET 1.x");
 #endif
 
-                       if (Parent.Kind != Kind.Struct) {
+                       if (ParentContainer.Kind != Kind.Struct) {
                                Report.Error (1642, Location, "`{0}': Fixed size buffer fields may only be members of structs",
                                        GetSignatureForError ());
                                return false;
@@ -5512,7 +5332,8 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       Constant c = size_expr.ResolveAsConstant (Parent.EmitContext, this);
+                       EmitContext ec = new EmitContext (this, Parent, Location, null, null, ModFlags);
+                       Constant c = size_expr.ResolveAsConstant (ec, this);
                        if (c == null)
                                return false;
 
@@ -5611,10 +5432,10 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.READONLY;
 
-               public Field (TypeContainer parent, Expression type, int mod, string name,
-                             Object expr_or_array_init, Attributes attrs, Location loc)
+               public Field (DeclSpace parent, Expression type, int mod, string name,
+                             Attributes attrs, Location loc)
                        : base (parent, type, mod, AllowedModifiers, new MemberName (name, loc),
-                               expr_or_array_init, attrs)
+                               attrs)
                {
                }
 
@@ -5668,7 +5489,7 @@ namespace Mono.CSharp {
 
                        FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
 
-                       if (Parent.Kind == Kind.Struct && 
+                       if (ParentContainer.Kind == Kind.Struct && 
                            ((fa & FieldAttributes.Static) == 0) &&
                            MemberType == Parent.TypeBuilder &&
                            !TypeManager.IsBuiltinType (MemberType)){
@@ -5691,9 +5512,9 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected override bool VerifyClsCompliance (DeclSpace ds)
+               protected override bool VerifyClsCompliance ()
                {
-                       if (!base.VerifyClsCompliance (ds))
+                       if (!base.VerifyClsCompliance ())
                                return false;
 
                        if ((ModFlags & Modifiers.VOLATILE) != 0) {
@@ -5797,7 +5618,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public bool IsExcluded (EmitContext ec)
+               public bool IsExcluded ()
                {
                        return false;
                }
@@ -5816,7 +5637,7 @@ namespace Mono.CSharp {
 
                public abstract Parameters ParameterInfo { get ; }
                public abstract Type ReturnType { get; }
-               public abstract EmitContext CreateEmitContext(TypeContainer tc, ILGenerator ig);
+               public abstract EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig);
 
                #endregion
 
@@ -5863,9 +5684,12 @@ namespace Mono.CSharp {
                        throw new NotSupportedException ();
                }
 
-               public virtual void Emit (TypeContainer container)
+               public void Emit (DeclSpace parent)
                {
-                       EmitMethod (container);
+                       EmitMethod (parent);
+
+                       if (OptAttributes != null)
+                               OptAttributes.Emit ();
 
                        if (declarative_security != null) {
                                foreach (DictionaryEntry de in declarative_security) {
@@ -5876,12 +5700,12 @@ namespace Mono.CSharp {
                        block = null;
                }
 
-               protected virtual void EmitMethod (TypeContainer container)
+               protected virtual void EmitMethod (DeclSpace parent)
                {
-                       method_data.Emit (container, this);
+                       method_data.Emit (parent);
                }
 
-               public override bool IsClsComplianceRequired(DeclSpace ds)
+               public override bool IsClsComplianceRequired()
                {
                        return false;
                }
@@ -5950,13 +5774,13 @@ namespace Mono.CSharp {
                        {
                        }
 
-                       public override MethodBuilder Define(TypeContainer container)
+                       public override MethodBuilder Define (DeclSpace parent)
                        {
-                               base.Define (container);
+                               base.Define (parent);
                                
                                method_data = new MethodData (method, ModFlags, flags, this);
 
-                               if (!method_data.Define (container))
+                               if (!method_data.Define (parent))
                                        return null;
 
                                return method_data.MethodBuilder;
@@ -6001,7 +5825,7 @@ namespace Mono.CSharp {
                        {
                                if (a.Target == AttributeTargets.Parameter) {
                                        if (param_attr == null)
-                                               param_attr = new ImplicitParameter (method_data.MethodBuilder, method.Location);
+                                               param_attr = new ImplicitParameter (method_data.MethodBuilder);
 
                                        param_attr.ApplyAttributeBuilder (a, cb);
                                        return;
@@ -6018,26 +5842,22 @@ namespace Mono.CSharp {
 
                        protected virtual void DefineParameters ()
                        {
-                               Parameter [] parms = new Parameter [1];
-                               parms [0] = new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, Location);
-                               parameters = new Parameters (parms);
-                               parameters.Resolve (null);
+                               parameters = new Parameters (
+                                       new Parameter[] { new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, Location) },
+                                       new Type[] { method.MemberType });
                        }
 
-                       public override MethodBuilder Define (TypeContainer container)
+                       public override MethodBuilder Define (DeclSpace parent)
                        {
-                               if (container.EmitContext == null)
-                                       throw new InternalErrorException ("SetMethod.Define called too early");
-
                                DefineParameters ();
                                if (IsDummy)
                                        return null;
 
-                               base.Define (container);
+                               base.Define (parent);
 
                                method_data = new MethodData (method, ModFlags, flags, this);
 
-                               if (!method_data.Define (container))
+                               if (!method_data.Define (parent))
                                        return null;
 
                                return method_data.MethodBuilder;
@@ -6089,16 +5909,18 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override bool IsClsComplianceRequired(DeclSpace ds)
+                       public override bool IsClsComplianceRequired()
                        {
-                               return method.IsClsComplianceRequired (ds);
+                               return method.IsClsComplianceRequired ();
                        }
 
-                       public virtual MethodBuilder Define (TypeContainer container)
+                       public virtual MethodBuilder Define (DeclSpace parent)
                        {
                                if (!method.CheckAbstractAndExtern (block != null))
                                        return null;
 
+                               TypeContainer container = ((TypeContainer) parent).PartialContainer;
+
                                //
                                // Check for custom access modifier
                                //
@@ -6114,7 +5936,7 @@ namespace Mono.CSharp {
                                                Report.Error (442, Location, "`{0}': abstract properties cannot have private accessors", GetSignatureForError ());
                                        }
 
-                                       CheckModifiers (container, ModFlags);
+                                       CheckModifiers (ModFlags);
                                        ModFlags |= (method.ModFlags & (~Modifiers.Accessibility));
                                        ModFlags |= Modifiers.PROPERTY_CUSTOM;
                                        flags = Modifiers.MethodAttr (ModFlags);
@@ -6125,8 +5947,7 @@ namespace Mono.CSharp {
                                // Setup iterator if we are one
                                //
                                if (yields) {
-                                       Iterator iterator = new Iterator (this,
-                                               Parent, ModFlags);
+                                       Iterator iterator = new Iterator (this, Parent as TypeContainer, ModFlags);
                                        
                                        if (!iterator.DefineIterator ())
                                                return null;
@@ -6142,11 +5963,10 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override EmitContext CreateEmitContext (TypeContainer tc,
-                                                                      ILGenerator ig)
+                       public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                        {
-                               return new EmitContext (
-                                       tc, method.Parent, method.Location, ig, ReturnType,
+                               return new EmitContext (method,
+                                       ds, method.Parent, method.Location, ig, ReturnType,
                                        method.ModFlags, false);
                        }
 
@@ -6160,7 +5980,7 @@ namespace Mono.CSharp {
                                return method.GetSignatureForError () + '.' + prefix.Substring (0, 3);
                        }
                        
-                       void CheckModifiers (TypeContainer container, int modflags)
+                       void CheckModifiers (int modflags)
                        {
                                int flags = 0;
                                int mflags = method.ModFlags & Modifiers.Accessibility;
@@ -6191,17 +6011,16 @@ namespace Mono.CSharp {
                        }
                }
 
-
                public PropertyMethod Get, Set;
                public PropertyBuilder PropertyBuilder;
                public MethodBuilder GetBuilder, SetBuilder;
 
                protected EmitContext ec;
 
-               public PropertyBase (TypeContainer ds, Expression type, int mod_flags,
+               public PropertyBase (DeclSpace parent, Expression type, int mod_flags,
                                     int allowed_mod, bool is_iface, MemberName name,
                                     Parameters parameters, Attributes attrs)
-                       : base (ds, type, mod_flags, allowed_mod, is_iface, name,
+                       : base (parent, type, mod_flags, allowed_mod, is_iface, name,
                                attrs, parameters)
                {
                }
@@ -6260,13 +6079,12 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
                        return true;
                }
 
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = Parent.Indexers;
+                       ArrayList ar = ParentContainer.Indexers;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -6277,7 +6095,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = Parent.Properties;
+                       ar = ParentContainer.Properties;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -6292,10 +6110,10 @@ namespace Mono.CSharp {
                }
 
                // TODO: rename to Resolve......
-               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
+               protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
-                       PropertyInfo base_property = container.BaseCache.FindMemberToOverride (
-                               container.TypeBuilder, Name, ParameterTypes, true) as PropertyInfo;
+                       PropertyInfo base_property = ParentContainer.BaseCache.FindMemberToOverride (
+                               Parent.TypeBuilder, Name, ParameterTypes, true) as PropertyInfo;
   
                        if (base_property == null)
                                return null;
@@ -6345,7 +6163,7 @@ namespace Mono.CSharp {
                        // Get the less restrictive access
                        //
                        return get_accessor_access > set_accessor_access ? get_accessor : set_accessor;
-               }
+               }
 
                public override void Emit ()
                {
@@ -6355,7 +6173,7 @@ namespace Mono.CSharp {
                        // put the attribute
                        //
                        if (PropertyBuilder != null && OptAttributes != null)
-                               OptAttributes.Emit (ec, this);
+                               OptAttributes.Emit ();
 
                        if (!Get.IsDummy)
                                Get.Emit (Parent);
@@ -6425,10 +6243,10 @@ namespace Mono.CSharp {
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
-               public Property (TypeContainer ds, Expression type, int mod, bool is_iface,
+               public Property (DeclSpace parent, Expression type, int mod, bool is_iface,
                                 MemberName name, Attributes attrs, Accessor get_block,
                                 Accessor set_block)
-                       : base (ds, type, mod,
+                       : base (parent, type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, Parameters.EmptyReadOnlyParameters, attrs)
                {
@@ -6466,14 +6284,9 @@ namespace Mono.CSharp {
                        }
 
                        // FIXME - PropertyAttributes.HasDefault ?
-                       
-                       PropertyAttributes prop_attr = PropertyAttributes.None;
-                       if (!IsInterface)
-                               prop_attr |= PropertyAttributes.RTSpecialName |
-                                       PropertyAttributes.SpecialName;
 
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
-                            Name, prop_attr, MemberType, null);
+                            Name, PropertyAttributes.None, MemberType, null);
                        
                        if (!Get.IsDummy)
                                PropertyBuilder.SetGetMethod (GetBuilder);
@@ -6481,6 +6294,7 @@ namespace Mono.CSharp {
                        if (!Set.IsDummy)
                                PropertyBuilder.SetSetMethod (SetBuilder);
                        
+                       TypeManager.RegisterProperty (PropertyBuilder, this);
                        return true;
                }
        }
@@ -6638,10 +6452,10 @@ namespace Mono.CSharp {
 
                static string[] attribute_targets = new string [] { "event" }; // "property" target was disabled for 2.0 version
 
-               public EventProperty (TypeContainer parent, Expression type, int mod_flags,
-                                     bool is_iface, MemberName name, Object init,
+               public EventProperty (DeclSpace parent, Expression type, int mod_flags,
+                                     bool is_iface, MemberName name,
                                      Attributes attrs, Accessor add, Accessor remove)
-                       : base (parent, type, mod_flags, is_iface, name, init, attrs)
+                       : base (parent, type, mod_flags, is_iface, name, attrs)
                {
                        Add = new AddDelegateMethod (this, add);
                        Remove = new RemoveDelegateMethod (this, remove);
@@ -6661,15 +6475,15 @@ namespace Mono.CSharp {
        /// <summary>
        /// Event is declared like field.
        /// </summary>
-       public class EventField: Event {
+       public class EventField : Event {
 
                static string[] attribute_targets = new string [] { "event", "field", "method" };
                static string[] attribute_targets_interface = new string[] { "event", "method" };
 
-               public EventField (TypeContainer parent, Expression type, int mod_flags,
-                                  bool is_iface, MemberName name, Object init,
+               public EventField (DeclSpace parent, Expression type, int mod_flags,
+                                  bool is_iface, MemberName name,
                                   Attributes attrs)
-                       : base (parent, type, mod_flags, is_iface, name, init, attrs)
+                       : base (parent, type, mod_flags, is_iface, name, attrs)
                {
                        Add = new AddDelegateMethod (this);
                        Remove = new RemoveDelegateMethod (this);
@@ -6691,6 +6505,22 @@ namespace Mono.CSharp {
                        base.ApplyAttributeBuilder (a, cb);
                }
 
+               public override bool Define()
+               {
+                       if (!base.Define ())
+                               return false;
+
+                       if (initializer != null) {
+                               if (((ModFlags & Modifiers.ABSTRACT) != 0)) {
+                                       Report.Error (74, Location, "`{0}': abstract event cannot have an initializer",
+                                               GetSignatureForError ());
+                                       return false;
+                               }
+                       }
+
+                       return true;
+               }
+
                public override string[] ValidAttributeTargets {
                        get {
                                return IsInterface ? attribute_targets_interface : attribute_targets;
@@ -6741,7 +6571,7 @@ namespace Mono.CSharp {
 
                }
 
-               public abstract class DelegateMethod: AbstractPropertyEventMethod
+               public abstract class DelegateMethod : AbstractPropertyEventMethod
                {
                        protected readonly Event method;
                        ImplicitParameter param_attr;
@@ -6764,7 +6594,7 @@ namespace Mono.CSharp {
                        {
                                if (a.Target == AttributeTargets.Parameter) {
                                        if (param_attr == null)
-                                               param_attr = new ImplicitParameter (method_data.MethodBuilder, method.Location);
+                                               param_attr = new ImplicitParameter (method_data.MethodBuilder);
 
                                        param_attr.ApplyAttributeBuilder (a, cb);
                                        return;
@@ -6779,29 +6609,29 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override bool IsClsComplianceRequired(DeclSpace ds)
+                       public override bool IsClsComplianceRequired ()
                        {
-                               return method.IsClsComplianceRequired (ds);
+                               return method.IsClsComplianceRequired ();
                        }
 
-                       public MethodBuilder Define (TypeContainer container)
+                       public MethodBuilder Define (DeclSpace parent)
                        {
                                method_data = new MethodData (method, method.ModFlags,
                                        method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
 
-                               if (!method_data.Define (container))
+                               if (!method_data.Define (parent))
                                        return null;
 
                                MethodBuilder mb = method_data.MethodBuilder;
-                               ParameterInfo.ApplyAttributes (Parent.EmitContext, mb);
+                               ParameterInfo.ApplyAttributes (mb);
                                return mb;
                        }
 
 
-                       protected override void EmitMethod (TypeContainer tc)
+                       protected override void EmitMethod (DeclSpace parent)
                        {
                                if (block != null) {
-                                       base.EmitMethod (tc);
+                                       base.EmitMethod (parent);
                                        return;
                                }
 
@@ -6838,11 +6668,10 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override EmitContext CreateEmitContext (TypeContainer tc,
-                                                                      ILGenerator ig)
+                       public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                        {
-                               return new EmitContext (
-                                       tc, method.Parent, Location, ig, ReturnType,
+                               return new EmitContext (method,
+                                       ds, method.Parent, Location, ig, ReturnType,
                                        method.ModFlags, false);
                        }
 
@@ -6887,11 +6716,11 @@ namespace Mono.CSharp {
                public MethodBuilder AddBuilder, RemoveBuilder;
                Parameters parameters;
 
-               public Event (TypeContainer parent, Expression type, int mod_flags,
-                             bool is_iface, MemberName name, Object init, Attributes attrs)
+               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,
-                               name, init, attrs)
+                               name, attrs)
                {
                        IsInterface = is_iface;
                }
@@ -6925,29 +6754,14 @@ namespace Mono.CSharp {
                        if (!DoDefine ())
                                return false;
 
-                       if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
-                               Report.Error (74, Location, "`" + GetSignatureForError () +
-                                             "': abstract event cannot have an initializer");
-                               return false;
-                       }
-                       
-                       if (!MemberType.IsSubclassOf (TypeManager.delegate_type)) {
+                       if (!TypeManager.IsDelegateType (MemberType)) {
                                Report.Error (66, Location, "`{0}': event must be of a delegate type", GetSignatureForError ());
                                return false;
                        }
 
-                       EmitContext ec = Parent.EmitContext;
-                       if (ec == null)
-                               throw new InternalErrorException ("Event.Define called too early?");
-                       bool old_unsafe = ec.InUnsafe;
-                       ec.InUnsafe = InUnsafe;
-
-                       Parameter [] parms = new Parameter [1];
-                       parms [0] = new Parameter (MemberType, "value", Parameter.Modifier.NONE, null, Location);
-                       parameters = new Parameters (parms);
-                       parameters.Resolve (null);
-
-                       ec.InUnsafe = old_unsafe;
+                       parameters = new Parameters (
+                               new Parameter[] { new Parameter (MemberType, "value", Parameter.Modifier.NONE, null, Location) },
+                               new Type[] { MemberType } );
 
                        if (!CheckBase ())
                                return false;
@@ -7001,9 +6815,7 @@ namespace Mono.CSharp {
                public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (
-                                       Parent, Location, null, MemberType, ModFlags);
-                               OptAttributes.Emit (ec, this);
+                               OptAttributes.Emit ();
                        }
 
                        Add.Emit (Parent);
@@ -7061,15 +6873,8 @@ namespace Mono.CSharp {
 
                        protected override void DefineParameters ()
                        {
-                               Parameter [] fixed_parms = method.Parameters.FixedParameters;
-                               Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
-
-                               fixed_parms.CopyTo (tmp, 0);
-                               tmp [fixed_parms.Length] = new Parameter (
-                                       method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location);
-
-                               parameters = new Parameters (tmp);
-                               parameters.Resolve (null);
+                               parameters = Parameters.MergeGenerated (method.Parameters,
+                                       new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location));
                        }
                }
 
@@ -7090,10 +6895,10 @@ namespace Mono.CSharp {
                        Modifiers.NEW;
 
 
-               public Indexer (TypeContainer ds, Expression type, MemberName name, int mod,
+               public Indexer (DeclSpace parent, Expression type, MemberName name, int mod,
                                bool is_iface, Parameters parameters, Attributes attrs,
                                Accessor get_block, Accessor set_block)
-                       : base (ds, type, mod,
+                       : base (parent, type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, parameters, attrs)
                {
@@ -7110,10 +6915,6 @@ namespace Mono.CSharp {
                       
                public override bool Define ()
                {
-                       PropertyAttributes prop_attr =
-                               PropertyAttributes.RTSpecialName |
-                               PropertyAttributes.SpecialName;
-                       
                        if (!base.Define ())
                                return false;
 
@@ -7123,12 +6924,16 @@ namespace Mono.CSharp {
                        }
 
                        if (OptAttributes != null) {
-                               Attribute indexer_attr = OptAttributes.Search (TypeManager.indexer_name_type, ec);
+                               Attribute indexer_attr = OptAttributes.Search (TypeManager.indexer_name_type);
                                if (indexer_attr != null) {
                                        // Remove the attribute from the list because it is not emitted
                                        OptAttributes.Attrs.Remove (indexer_attr);
 
-                                       ShortName = indexer_attr.GetIndexerAttributeValue (ec);
+                                       string name = indexer_attr.GetIndexerAttributeValue ();
+                                       if (name == null)
+                                               return false;
+
+                                       ShortName = name;
 
                                        if (IsExplicitImpl) {
                                                Report.Error (415, indexer_attr.Location,
@@ -7142,12 +6947,6 @@ namespace Mono.CSharp {
                                                              "Cannot set the `IndexerName' attribute on an indexer marked override");
                                                return false;
                                        }
-
-                                       if (!Tokenizer.IsValidIdentifier (ShortName)) {
-                                               Report.Error (633, indexer_attr.Location,
-                                                             "The argument to the `IndexerName' attribute must be a valid identifier");
-                                               return false;
-                                       }
                                }
                        }
 
@@ -7157,8 +6956,8 @@ namespace Mono.CSharp {
                                        ShortName = base_IndexerName;
                        }
 
-                       if (!Parent.AddToMemberContainer (this) ||
-                               !Parent.AddToMemberContainer (Get) || !Parent.AddToMemberContainer (Set))
+                       if (!ParentContainer.AddToMemberContainer (this) ||
+                               !ParentContainer.AddToMemberContainer (Get) || !ParentContainer.AddToMemberContainer (Set))
                                return false;
 
                        if (!CheckBase ())
@@ -7190,7 +6989,7 @@ namespace Mono.CSharp {
                        }
 
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
-                               Name, prop_attr, MemberType, ParameterTypes);
+                               Name, PropertyAttributes.None, MemberType, ParameterTypes);
                        
                        if (!Get.IsDummy)
                                PropertyBuilder.SetGetMethod (GetBuilder);
@@ -7223,7 +7022,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class Operator : MethodCore, IIteratorContainer {
+       public class Operator : MethodOrOperator, IIteratorContainer {
 
                const int AllowedModifiers =
                        Modifiers.PUBLIC |
@@ -7273,13 +7072,8 @@ namespace Mono.CSharp {
                };
 
                public readonly OpType OperatorType;
-               public MethodBuilder   OperatorMethodBuilder;
                
-               public Method OperatorMethod;
-
-               static string[] attribute_targets = new string [] { "method", "return" };
-
-               public Operator (TypeContainer parent, OpType type, Expression ret_type,
+               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,
@@ -7291,18 +7085,17 @@ namespace Mono.CSharp {
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb) 
                {
-                       OperatorMethod.ApplyAttributeBuilder (a, cb);
-               }
-
-               public override AttributeTargets AttributeTargets {
-                       get {
-                               return AttributeTargets.Method; 
+                       if (a.Type == TypeManager.conditional_attribute_type) {
+                               Error_ConditionalAttributeIsNotValid ();
+                               return;
                        }
+
+                       base.ApplyAttributeBuilder (a, cb);
                }
                
-               protected override bool CheckForDuplications()
+               protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = Parent.Operators;
+                       ArrayList ar = ParentContainer.Operators;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -7313,7 +7106,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = Parent.Methods;
+                       ar = ParentContainer.Methods;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -7335,7 +7128,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (!DoDefine ())
+                       if (!base.Define ())
                                return false;
 
                        if (MemberType == TypeManager.void_type) {
@@ -7343,27 +7136,9 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       OperatorMethod = new Method (
-                               Parent, Type, ModFlags, false, MemberName,
-                               Parameters, OptAttributes);
-
-                       OperatorMethod.Block = Block;
-                       OperatorMethod.IsOperator = this;                       
-                       OperatorMethod.flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
-                       OperatorMethod.Define ();
-
-                       if (OperatorMethod.MethodBuilder == null)
-                               return false;
-
-                       OperatorMethodBuilder = OperatorMethod.MethodBuilder;
-
-                       Type[] parameter_types = OperatorMethod.ParameterTypes;
-                       Type declaring_type = OperatorMethodBuilder.DeclaringType;
-                       Type return_type = OperatorMethod.ReturnType;
-                       Type first_arg_type = parameter_types [0];
-
-                       if (!CheckBase ())
-                               return false;
+                       Type declaring_type = MethodBuilder.DeclaringType;
+                       Type return_type = MemberType;
+                       Type first_arg_type = ParameterTypes [0];
 
                        // Rules for conversion operators
                        
@@ -7381,15 +7156,6 @@ namespace Mono.CSharp {
                                                "enclosing type");
                                        return false;
                                }
-                               
-                               if (first_arg_type == TypeManager.object_type ||
-                                       return_type == TypeManager.object_type){
-                                       Report.Error (
-                                               -8, Location,
-                                               "User-defined conversion cannot convert to or from " +
-                                               "object type");
-                                       return false;
-                               }
 
                                if (first_arg_type.IsInterface || return_type.IsInterface){
                                        Report.Error (552, Location, "User-defined conversion `{0}' cannot convert to or from an interface type",
@@ -7397,9 +7163,8 @@ namespace Mono.CSharp {
                                        return false;
                                }
                                
-                               if (first_arg_type.IsSubclassOf (return_type)
-                                       || return_type.IsSubclassOf (first_arg_type)){
-                                       if (declaring_type.IsSubclassOf (return_type)) {
+                               if (first_arg_type.IsSubclassOf (return_type) || return_type.IsSubclassOf (first_arg_type)) {
+                                       if (declaring_type.IsSubclassOf (return_type) || declaring_type.IsSubclassOf (first_arg_type)) {
                                                Report.Error (553, Location, "User-defined conversion `{0}' cannot convert to or from base class",
                                                        GetSignatureForError ());
                                                return false;
@@ -7409,7 +7174,7 @@ namespace Mono.CSharp {
                                        return false;
                                }
                        } else if (OperatorType == OpType.LeftShift || OperatorType == OpType.RightShift) {
-                               if (first_arg_type != declaring_type || parameter_types [1] != TypeManager.int32_type) {
+                               if (first_arg_type != declaring_type || ParameterTypes [1] != TypeManager.int32_type) {
                                        Report.Error (564, Location, "Overloaded shift operator must have the type of the first operand be the containing type, and the type of the second operand must be int");
                                        return false;
                                }
@@ -7451,7 +7216,7 @@ namespace Mono.CSharp {
                                // Checks for Binary operators
                                
                                if (first_arg_type != declaring_type &&
-                                   parameter_types [1] != declaring_type){
+                                   ParameterTypes [1] != declaring_type){
                                        Report.Error (
                                                563, Location,
                                                "One of the parameters of a binary operator must " +
@@ -7462,21 +7227,45 @@ namespace Mono.CSharp {
 
                        return true;
                }
+
+               protected override bool DoDefine ()
+               {
+                       if (!base.DoDefine ())
+                               return false;
+
+                       flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
+                       return true;
+               }
                
                public override void Emit ()
                {
+                       base.Emit ();
+
+                       Parameters.ApplyAttributes (MethodBuilder);
+
                        //
                        // abstract or extern methods have no bodies
                        //
                        if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
                                return;
                        
-                       OperatorMethod.Emit ();
+                       EmitContext ec;
+                       if ((flags & MethodAttributes.PinvokeImpl) == 0)
+                               ec = CreateEmitContext (Parent, MethodBuilder.GetILGenerator ());
+                       else
+                               ec = CreateEmitContext (Parent, null);
+                       
+                       SourceMethod source = SourceMethod.Create (Parent, MethodBuilder, Block);
+                       ec.EmitTopBlock (this, Block);
+
+                       if (source != null)
+                               source.CloseMethod ();
+
                        Block = null;
                }
 
                // Operator cannot be override
-               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
+               protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
                        return null;
                }
@@ -7569,18 +7358,6 @@ namespace Mono.CSharp {
                        sb.Append (Parameters.GetSignatureForError ());
                        return sb.ToString ();
                }
-
-               public override bool MarkForDuplicationCheck ()
-               {
-                       caching_flags |= Flags.TestMethodDuplication;
-                       return true;
-               }
-
-               public override string[] ValidAttributeTargets {
-                       get {
-                               return attribute_targets;
-                       }
-               }
        }
 
        //
@@ -7603,7 +7380,7 @@ namespace Mono.CSharp {
                        RetType = ret_type;
 
                        if (parameters == null)
-                               Parameters = TypeManager.NoTypes;
+                               Parameters = Type.EmptyTypes;
                        else
                                Parameters = parameters;
                }