Ver código fonte

2008-02-21 Marek Habersack <[email protected]>

	* ControlBuilder.cs: introduced a new internal property -
	MyNamingContainer used by the public properties
	NamingContainerType and BindingContainerType. This simplifies the
	code in the latter property, as the binding container type must
	almost always be the same as the naming container type. The only
	exception is when we're inside a content builder, in which case we
	return the parent's BindingContainerType. Fixes bug #363665

svn path=/trunk/mcs/; revision=96395
Marek Habersack 18 anos atrás
pai
commit
66916dc696

+ 10 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,13 @@
+2008-02-21  Marek Habersack  <[email protected]>
+
+	* ControlBuilder.cs: introduced a new internal property -
+	MyNamingContainer used by the public properties
+	NamingContainerType and BindingContainerType. This simplifies the
+	code in the latter property, as the binding container type must
+	almost always be the same as the naming container type. The only
+	exception is when we're inside a content builder, in which case we
+	return the parent's BindingContainerType. Fixes bug #363665
+
 2008-02-12  Vladimir Krasnov  <[email protected]>
 
 	* Page.jvm.cs: StateSerializer.readExternal and writeExternal fixed

+ 29 - 30
mcs/class/System.Web/System.Web.UI/ControlBuilder.cs

@@ -36,6 +36,7 @@ using System.Security.Permissions;
 using System.Web.Compilation;
 using System.Web.Configuration;
 using System.IO;
+using System.Web.UI.WebControls;
 
 namespace System.Web.UI {
 
@@ -49,6 +50,7 @@ namespace System.Web.UI {
 			BindingFlags.Static |
 			BindingFlags.IgnoreCase;
 
+		ControlBuilder myNamingContainer;
 		TemplateParser parser;
 		internal ControlBuilder parentBuilder;
 		Type type;	       
@@ -146,52 +148,49 @@ namespace System.Web.UI {
 
 		public Type NamingContainerType {
 			get {
-				if (parentBuilder == null)
+				ControlBuilder cb = myNamingContainer;
+				
+				if (cb == null)
 					return typeof (Control);
 
-				Type ptype = parentBuilder.ControlType;
-				if (ptype == null)
-					return parentBuilder.NamingContainerType;
+				return cb.ControlType;
+			}
+		}
 
-				if (!typeof (INamingContainer).IsAssignableFrom (ptype))
-					return parentBuilder.NamingContainerType;
+		ControlBuilder MyNamingContainer {
+			get {
+				if (myNamingContainer == null) {
+					Type controlType = parentBuilder != null ? parentBuilder.ControlType : null;
+					
+					if (controlType == null)
+						myNamingContainer = null;
+					else if (typeof (INamingContainer).IsAssignableFrom (controlType))
+						myNamingContainer = parentBuilder;
+					else
+						myNamingContainer = parentBuilder.MyNamingContainer;
+				}
 
-				return ptype;
+				return myNamingContainer;
 			}
 		}
-		
+			
 #if NET_2_0
 		public virtual
 #else
 		internal
 #endif
 		Type BindingContainerType {
-			get {				
-				if (parentBuilder == null) {
-#if NET_2_0
-					Type bt = Parser.BaseType;
-					if (bt != null)
-						return bt;
-#endif
-
+			get {
+				ControlBuilder cb = MyNamingContainer;
+				if (cb == null)
 					return typeof (Control);
-				}
-
-				if (parentBuilder is TemplateBuilder && ((TemplateBuilder)parentBuilder).ContainerType != null)
-					return ((TemplateBuilder)parentBuilder).ContainerType;
-				
-				Type ptype = parentBuilder.ControlType;
-				if (ptype == null)
-					return parentBuilder.BindingContainerType;
-				
-				if (!typeof (INamingContainer).IsAssignableFrom (ptype))
-					return parentBuilder.BindingContainerType;
 
 #if NET_2_0
-				return typeof (Control);
-#else
-				return ptype;
+				if (cb is ContentBuilderInternal)
+					return cb.BindingContainerType;
 #endif
+				
+				return cb.ControlType;
 			}
 		}