Fix for running against RabbitMQ 2.2
[mono.git] / mcs / class / System.Web / System.Web.UI.Adapters / ControlAdapter.cs
index 7eddb8a33be7c350fc99e625388ae7a35daa8e33..ea0aa13b97df70875b3c7d3ffc115140804e2548 100644 (file)
@@ -4,7 +4,7 @@
 // Author:
 //     Dick Porter  <dick@ximian.com>
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -26,7 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System.Web;
 using System.Web.UI;
 using System.ComponentModel;
@@ -47,7 +46,12 @@ namespace System.Web.UI.Adapters
                protected HttpBrowserCapabilities Browser 
                {
                        get {
-                               return Page.Request.Browser;
+                               Page page = Page;
+
+                               if (page != null)
+                                       return page.Request.Browser;
+
+                               return null;
                        }
                }
 
@@ -55,14 +59,9 @@ namespace System.Web.UI.Adapters
                
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-               protected internal Control Control 
+               protected Control Control 
                {
-                       protected get {
-                               return control;
-                       }
-                       set {
-                               control = value;
-                       }
+                       get { return control; }
                }
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
@@ -70,7 +69,12 @@ namespace System.Web.UI.Adapters
                protected Page Page 
                {
                        get {
-                               return Control.Page;
+                               Control control = Control;
+
+                               if (control != null)
+                                       return control.Page;
+
+                               return null;
                        }
                }
                
@@ -79,7 +83,12 @@ namespace System.Web.UI.Adapters
                protected PageAdapter PageAdapter 
                {
                        get {
-                               return Control.Page.PageAdapter;
+                               Page page = Page;
+
+                               if (page != null)
+                                       return page.PageAdapter;
+
+                               return null;
                        }
                }
 
@@ -90,6 +99,9 @@ namespace System.Web.UI.Adapters
 
                protected internal virtual void CreateChildControls ()
                {
+                       Control control = Control;
+                       if (control != null)
+                               control.CreateChildControls ();
                }
 
                protected internal virtual void EndRender (HtmlTextWriter w)
@@ -107,32 +119,50 @@ namespace System.Web.UI.Adapters
 
                protected internal virtual void OnInit (EventArgs e)
                {
-                       Control.OnInit(e);
+                       Control control = Control;
+
+                       if (control != null)
+                               control.OnInit(e);
                }
 
                protected internal virtual void OnLoad (EventArgs e)
                {
-                       Control.OnLoad(e);
+                       Control control = Control;
+
+                       if (control != null)
+                               control.OnLoad(e);
                }
 
                protected internal virtual void OnPreRender (EventArgs e)
                {
-                       Control.OnPreRender(e);
+                       Control control = Control;
+
+                       if (control != null)
+                               control.OnPreRender(e);
                }
 
                protected internal virtual void OnUnload (EventArgs e)
                {
-                       Control.OnUnload(e);
+                       Control control = Control;
+
+                       if (control != null)
+                               control.OnUnload(e);
                }
 
                protected internal virtual void Render (HtmlTextWriter w)
                {
-                       Control.Render (w);
+                       Control control = Control;
+
+                       if (control != null)
+                               control.Render (w);
                }
 
                protected internal virtual void RenderChildren (HtmlTextWriter w)
                {
-                       Control.RenderChildren (w);
+                       Control control = Control;
+
+                       if (control != null)
+                               control.RenderChildren (w);
                }
 
                protected internal virtual object SaveAdapterControlState ()
@@ -146,4 +176,4 @@ namespace System.Web.UI.Adapters
                }
        }
 }
-#endif
+