Browse Source

Implement tag mapping for asp.net 2.0

svn path=/trunk/mcs/; revision=69906
Marek Habersack 19 years ago
parent
commit
5dd4bebf9e

+ 9 - 0
mcs/class/System.Web/System.Web.Configuration_2.0/ChangeLog

@@ -1,3 +1,12 @@
+2006-12-21  Marek Habersack  <[email protected]>
+
+	* TagMapInfo.cs: Add an internal default constructor for use from
+	TagMapCollection.
+
+	* TagMapCollection.cs: Don't call the string,string constructor of
+	TagMapInfo - the class disallows empty strings as values of its
+	properties.
+
 2006-12-21  Vladimir Krasnov  <[email protected]>
 
 	* RoleManagerSection.cs: refactored using attributes

+ 1 - 1
mcs/class/System.Web/System.Web.Configuration_2.0/TagMapCollection.cs

@@ -62,7 +62,7 @@ namespace System.Web.Configuration
 
 		protected override ConfigurationElement CreateNewElement ()
 		{
-			return new TagMapInfo ("", "");
+			return new TagMapInfo ();
 		}
 
 		protected override object GetElementKey (ConfigurationElement element)

+ 4 - 0
mcs/class/System.Web/System.Web.Configuration_2.0/TagMapInfo.cs

@@ -60,6 +60,10 @@ namespace System.Web.Configuration
 			properties.Add (tagTypeProp);
 		}
 
+		internal TagMapInfo ()
+		{
+		}
+		
 		public TagMapInfo (string tagTypeName, string mappedTagTypeName)
 		{
 			this.TagType = tagTypeName;

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

@@ -1,3 +1,7 @@
+2006-12-21  Marek Habersack  <[email protected]>
+
+	* ControlBuilder.cs: Add support for tag mapping in 2.0
+
 2006-12-20  Marek Habersack  <[email protected]>
 
 	* TemplateParser.cs: make sure Context.ApplicationInstance is not

+ 37 - 2
mcs/class/System.Web/System.Web.UI/ControlBuilder.cs

@@ -33,6 +33,7 @@ using System.CodeDom;
 using System.Reflection;
 using System.Security.Permissions;
 using System.Web.Compilation;
+using System.Web.Configuration;
 
 namespace System.Web.UI {
 
@@ -298,6 +299,33 @@ namespace System.Web.UI {
 		{
 		}
 
+#if NET_2_0
+		static Type MapTagType (Type tagType)
+		{
+			if (tagType == null)
+				return null;
+			
+			PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
+			if (ps == null)
+				return tagType;
+
+			TagMapCollection tags = ps.TagMapping;
+			if (tags == null || tags.Count == 0)
+				return tagType;
+			string tagTypeName = tagType.ToString ();
+			foreach (TagMapInfo tmi in tags)
+				if (tmi.TagType == tagTypeName) {
+					try {
+						return Type.GetType (tmi.MappedTagType, true);
+					} catch (Exception ex) {
+						throw new HttpException (String.Format ("Unable to map tag type {0}", tagTypeName),
+									 ex);
+					}
+				}
+			return tagType;
+		}
+#endif
+
 		public static ControlBuilder CreateBuilderFromType (TemplateParser parser,
 								    ControlBuilder parentBuilder,
 								    Type type,
@@ -307,8 +335,15 @@ namespace System.Web.UI {
 								    int line,
 								    string sourceFileName)
 		{
+
+			Type tagType;
+#if NET_2_0
+			tagType = MapTagType (type);
+#else
+			tagType = type;
+#endif
 			ControlBuilder  builder;
-			object [] atts = type.GetCustomAttributes (typeof (ControlBuilderAttribute), true);
+			object [] atts = tagType.GetCustomAttributes (typeof (ControlBuilderAttribute), true);
 			if (atts != null && atts.Length > 0) {
 				ControlBuilderAttribute att = (ControlBuilderAttribute) atts [0];
 				builder = (ControlBuilder) Activator.CreateInstance (att.BuilderType);
@@ -316,7 +351,7 @@ namespace System.Web.UI {
 				builder = new ControlBuilder ();
 			}
 
-			builder.Init (parser, parentBuilder, type, tagName, id, attribs);
+			builder.Init (parser, parentBuilder, tagType, tagName, id, attribs);
 			builder.line = line;
 			builder.fileName = sourceFileName;
 			return builder;