Explorar o código

2007-05-24 Marek Habersack <[email protected]>

	* PageParser.cs: added support for the PreviousPageType
	directive.

2007-05-24  Marek Habersack  <[email protected]>

	* PageCompiler.cs: added support for the PreviousPageType directive.

	* Directive.cs: as above.


svn path=/trunk/mcs/; revision=77907
Marek Habersack %!s(int64=18) %!d(string=hai) anos
pai
achega
324a2ea444

+ 6 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,9 @@
+2007-05-24  Marek Habersack  <[email protected]>
+
+	* PageCompiler.cs: added support for the PreviousPageType directive.
+
+	* Directive.cs: as above.
+
 2007-05-22  Marek Habersack  <[email protected]>
 
 	* UserControlCompiler.cs: the Profile property should be present

+ 5 - 0
mcs/class/System.Web/System.Web.Compilation/Directive.cs

@@ -72,6 +72,7 @@ namespace System.Web.Compilation
 
 #if NET_2_0
 		static string [] mastertype_atts = { "virtualpath", "typename" };
+		static string [] previouspagetype_atts = { "virtualpath", "typename" };
 #endif
 		
 		static Directive ()
@@ -189,6 +190,10 @@ namespace System.Web.Compilation
 			valid_attributes = new Hashtable (comparer);
 			foreach (string att in control_atts) valid_attributes.Add (att, null);
 			directivesHash.Add ("MASTER", valid_attributes);
+
+			valid_attributes = new Hashtable (comparer);
+			foreach (string att in previouspagetype_atts) valid_attributes.Add (att, null);
+			directivesHash.Add ("PREVIOUSPAGETYPE", valid_attributes);
 #endif
 		}
 		

+ 23 - 15
mcs/class/System.Web/System.Web.Compilation/PageCompiler.cs

@@ -254,27 +254,35 @@ namespace System.Web.Compilation
 				new CodePrimitiveExpression (pageParser.OutputCacheVaryByParam)
 				};
 		}
-                
+
+#if NET_2_0
+		void CreateStronglyTypedProperty (Type type, string name)
+		{
+			if (type == null)
+				return;
+			
+			CodeMemberProperty mprop = new CodeMemberProperty ();
+			mprop.Name = name;
+			mprop.Type = new CodeTypeReference (type);
+			mprop.Attributes = MemberAttributes.Public | MemberAttributes.New;
+			CodeExpression prop = new CodePropertyReferenceExpression (new CodeBaseReferenceExpression (), name);
+			prop = new CodeCastExpression (type, prop);
+			mprop.GetStatements.Add (new CodeMethodReturnStatement (prop));
+			if (partialClass != null)
+				partialClass.Members.Add (mprop);
+			else
+				mainClass.Members.Add (mprop);
+		}
+#endif
+		
 		protected internal override void CreateMethods ()
 		{
 			base.CreateMethods ();
 
 #if NET_2_0
 			CreateProfileProperty ();
-			if (pageParser.MasterType != null) {
-				CodeMemberProperty mprop = new CodeMemberProperty ();
-				mprop.Name = "Master";
-				mprop.Type = new CodeTypeReference (pageParser.MasterType);
-				mprop.Attributes = MemberAttributes.Public | MemberAttributes.New;
-				CodeExpression prop = new CodePropertyReferenceExpression (new CodeBaseReferenceExpression (), "Master");
-				prop = new CodeCastExpression (pageParser.MasterType, prop);
-				mprop.GetStatements.Add (new CodeMethodReturnStatement (prop));
-
-				if (partialClass != null)
-					partialClass.Members.Add (mprop);
-				else
-					mainClass.Members.Add (mprop);
-			}
+			CreateStronglyTypedProperty (pageParser.MasterType, "Master");
+			CreateStronglyTypedProperty (pageParser.PreviousPageType, "PreviousPage");
 #endif
 			
 			CreateGetTypeHashCode ();

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

@@ -1,3 +1,8 @@
+2007-05-24  Marek Habersack  <[email protected]>
+
+	* PageParser.cs: added support for the PreviousPageType
+	directive.
+
 2007-05-23  Marek Habersack  <[email protected]>
 
 	* TemplateParser.cs: use VirtualPathUtility.Combine to properly

+ 45 - 16
mcs/class/System.Web/System.Web.UI/PageParser.cs

@@ -72,6 +72,7 @@ namespace System.Web.UI
 		bool maintainScrollPositionOnPostBack;
 		int maxPageStateFieldLength = -1;
 		string pageParserFilter = String.Empty;
+		Type previousPageType;
 #endif
 
 		public PageParser ()
@@ -373,23 +374,41 @@ namespace System.Web.UI
 		
 #if NET_2_0
 		internal override void AddDirective (string directive, Hashtable atts)
-		{
-			if (String.Compare ("MasterType", directive, true) == 0) {
-				string type = GetString (atts, "TypeName", null);
-				if (type != null) {
-					masterType = LoadType (type);
-					if (masterType == null)
-						ThrowParseException ("Could not load type '" + type + "'.");
-				} else {
-					string path = GetString (atts, "VirtualPath", null);
-					if (path != null)
-						masterType = MasterPageParser.GetCompiledMasterType (path, MapPath (path), HttpContext.Current);
+		{			
+			bool isMasterType = String.Compare ("MasterType", directive, StringComparison.OrdinalIgnoreCase) == 0;
+			bool isPreviousPageType = isMasterType ? false : String.Compare ("PreviousPageType", directive,
+											 StringComparison.OrdinalIgnoreCase) == 0;
+			
+			string typeName = null;
+			string virtualPath = null;
+			Type type = null;
+			
+			if (isMasterType || isPreviousPageType) {
+				typeName = GetString (atts, "TypeName", null);
+				virtualPath = GetString (atts, "VirtualPath", null);
+
+				if (typeName != null && virtualPath != null)
+					ThrowParseException (
+						String.Format ("The '{0}' directive must have exactly one attribute: TypeName or VirtualPath", directive));
+				if (typeName != null) {
+					type = LoadType (typeName);
+					if (type == null)
+						ThrowParseException (String.Format ("Could not load type '{0}'.", typeName));
+				} else if (virtualPath != null) {
+					string mappedPath = MapPath (virtualPath);
+					if (isMasterType)
+						type = masterType = MasterPageParser.GetCompiledMasterType (virtualPath,
+												     mappedPath,
+												     HttpContext.Current);
 					else
-						ThrowParseException ("The MasterType directive must have either a TypeName or a VirtualPath attribute.");
-				}
-				AddAssembly (masterType.Assembly, true);
-			}
-			else
+						type = previousPageType = GetCompiledPageType (virtualPath, mappedPath,
+											       HttpContext.Current);
+				} else
+					ThrowParseException (
+						String.Format ("The {0} directive must have either a TypeName or a VirtualPath attribute.", directive));
+
+				AddAssembly (type.Assembly, true);
+			} else
 				base.AddDirective (directive, atts);
 		}
 #endif
@@ -404,6 +423,12 @@ namespace System.Web.UI
 			return retval;
 		}
 
+		public static Type GetCompiledPageType (string virtualPath, string inputFile, HttpContext context)
+		{
+			PageParser pp = new PageParser (virtualPath, inputFile, context);
+			return pp.CompileIntoType ();
+		}
+		
 		protected override Type CompileIntoType ()
 		{
 			AspGenerator generator = new AspGenerator (this);
@@ -526,6 +551,10 @@ namespace System.Web.UI
 		internal string PageParserFilterType {
 			get { return pageParserFilter; }
 		}
+
+		internal Type PreviousPageType {
+			get { return previousPageType; }
+		}
 #endif
 	}
 }