Przeglądaj źródła

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

	* TemplateParser.cs: refactoring - use HttpApplication.LoadType to
	actually look up types.
	
	* ControlBuilder.cs: as above

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

	* BuildProviderCollection.cs: refactoring - use
	HttpApplication.LoadType to actually look up the type.

	* HttpHandlerAction.cs: as above

	* WebConfigurationHost.cs: refactoring - moved the LoadType to
	HttpApplication to share the code between 1.1 and 2.0 profiles.

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

	* ObjectDataSourceView.cs: refactoring - use
	HttpApplication.LoadType to look up types.

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

	* HttpApplication.cs: refactoring - moved LoadType from
	WebConfigurationHost here and made it internal static, in order to
	make the code avaliable from all the places where extended type
	loading is required.


svn path=/trunk/mcs/; revision=77396
Marek Habersack 18 lat temu
rodzic
commit
c7d897bbf4

+ 1 - 1
mcs/class/System.Web/System.Web.Configuration/HandlerFactoryConfiguration.cs

@@ -107,7 +107,7 @@ namespace System.Web.Configuration {
 			Type t;
 			
 			try {
-				t = Type.GetType (type_name, true);
+				t = HttpApplication.LoadType (type_name, true);
 			} catch {
 				throw new HttpException (String.Format ("Failed to load httpHandler type `{0}'", type_name));
 			}

+ 5 - 2
mcs/class/System.Web/System.Web.Configuration_2.0/BuildProviderCollection.cs

@@ -98,8 +98,11 @@ namespace System.Web.Configuration
 			foreach (BuildProvider provider in this) {
 				if (extension != provider.Extension)
 					continue;
-
-				Type type = Type.GetType (provider.Type);
+				
+				Type type = HttpApplication.LoadType (provider.Type);
+				if (type == null)
+					return null;
+				
 				return (System.Web.Compilation.BuildProvider) Activator.CreateInstance (type, null);
 			}
 

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

@@ -1,3 +1,13 @@
+2007-05-15  Marek Habersack  <[email protected]>
+
+	* BuildProviderCollection.cs: refactoring - use
+	HttpApplication.LoadType to actually look up the type.
+
+	* HttpHandlerAction.cs: as above
+
+	* WebConfigurationHost.cs: refactoring - moved the LoadType to
+	HttpApplication to share the code between 1.1 and 2.0 profiles.
+
 2007-05-14  Marek Habersack  <[email protected]>
 
 	* UrlMappingCollection.cs: implemented the Item (string) indexer.

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

@@ -179,19 +179,7 @@ namespace System.Web.Configuration
 		{
 			Type t = null;
 			
-			t = System.Type.GetType (type_name, false);
-			if (t == null) {
-				IList tla = System.Web.Compilation.BuildManager.TopLevelAssemblies;
-				if (tla != null && tla.Count > 0) {
-					foreach (Assembly asm in tla) {
-						if (asm == null)
-							continue;
-						t = asm.GetType (type_name, false);
-						if (t != null)
-							break;
-					}
-				}
-			}
+			t = HttpApplication.LoadType (type_name, false);
 
 			if (t == null)
 				throw new HttpException (String.Format ("Failed to load httpHandler type `{0}'", type_name));

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

@@ -90,58 +90,10 @@ namespace System.Web.Configuration
 		{
 			return configPath + "/" + locatinSubPath;
 		}
-
-		private static string privateBinPath;
-
-		private static string PrivateBinPath {
-			get {
-				if (privateBinPath != null)
-					return privateBinPath;
-				
-				AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
-				privateBinPath = Path.Combine(setup.ApplicationBase, setup.PrivateBinPath);
-				return privateBinPath;
-			}
-		}
-		
-		private Type LoadType(string typeName)
-		{
-			Type type = Type.GetType (typeName);
-			if (type != null)
-				return type;
-
-			IList tla = System.Web.Compilation.BuildManager.TopLevelAssemblies;
-			if (tla != null && tla.Count > 0) {
-				foreach (Assembly asm in tla) {
-					if (asm == null)
-						continue;
-					type = asm.GetType (typeName, false);
-					if (type != null)
-						break;
-				}
-			}
-			if (type != null)
-				return type;
-			
-			if (!Directory.Exists (PrivateBinPath))
-				return null;
-			
-			string[] binDlls = Directory.GetFiles(PrivateBinPath, "*.dll");
-			foreach (string s in binDlls) {
-				Assembly binA = Assembly.LoadFrom (s);
-				type = binA.GetType (typeName);
-				if (type == null)
-					continue;
-				
-				return type;
-			}
-			
-			return null;
-		}
 		
 		public virtual Type GetConfigType (string typeName, bool throwOnError)
 		{
-		        Type type = LoadType(typeName);
+		        Type type = HttpApplication.LoadType (typeName);
 			if (type == null && throwOnError)
 				throw new ConfigurationErrorsException ("Type not found: '" + typeName + "'");
 			return type;

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

@@ -1,3 +1,8 @@
+2007-05-15  Marek Habersack  <[email protected]>
+
+	* ObjectDataSourceView.cs: refactoring - use
+	HttpApplication.LoadType to look up types.
+
 2007-05-10  Marek Habersack  <[email protected]>
 
 	* Table.cs: render rows, not controls

+ 2 - 35
mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs

@@ -483,44 +483,11 @@ namespace System.Web.UI.WebControls
 				return privateBinPath;
 			}
 		}
-
-		private Type LoadType (string typeName)
-		{
-			Type type = Type.GetType (typeName);
-			if (type != null)
-				return type;
-
-			IList tla;
-			if ((tla = BuildManager.TopLevelAssemblies) != null) {
-				foreach (Assembly asm in tla) {
-					if (asm == null)
-						continue;
-					type = asm.GetType (typeName);
-					if (type != null)
-						return type;
-				}
-			}
-
-			if (!Directory.Exists (PrivateBinPath))
-				return null;
-
-			string [] binDlls = Directory.GetFiles (PrivateBinPath, "*.dll");
-			foreach (string s in binDlls) {
-				Assembly binA = Assembly.LoadFrom (s);
-				type = binA.GetType (typeName);
-				if (type == null)
-					continue;
-
-				return type;
-			}
-
-			return null;
-		}
     
 		Type ObjectType {
 			get {
 				if (objectType == null) {
-					objectType = LoadType (TypeName);
+					objectType = HttpApplication.LoadType (TypeName);
 					if (objectType == null)
 						throw new InvalidOperationException ("Type not found: " + TypeName);
 				}
@@ -531,7 +498,7 @@ namespace System.Web.UI.WebControls
 		Type DataObjectType {
 			get {
 				if (dataObjectType == null) {
-					dataObjectType = LoadType (DataObjectTypeName);
+					dataObjectType = HttpApplication.LoadType (DataObjectTypeName);
 					if (dataObjectType == null)
 						throw new InvalidOperationException ("Type not found: " + DataObjectTypeName);
 				}

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

@@ -1,3 +1,10 @@
+2007-05-15  Marek Habersack  <[email protected]>
+
+	* TemplateParser.cs: refactoring - use HttpApplication.LoadType to
+	actually look up types.
+	
+	* ControlBuilder.cs: as above	
+
 2007-05-14  Marek Habersack  <[email protected]>
 
 	* ClientScriptManager.cs: put the hidden field within a <div>, the

+ 3 - 36
mcs/class/System.Web/System.Web.UI/ControlBuilder.cs

@@ -318,40 +318,7 @@ namespace System.Web.UI {
 		{
 		}
 
-#if NET_2_0
-		static Type LoadType (string typeName)
-                {
-                        Type type = Type.GetType (typeName);
-                        if (type != null)
-                                return type;
-
-                        IList tla;
-                        if ((tla = BuildManager.TopLevelAssemblies) != null) {
-                                foreach (Assembly asm in tla) {
-                                        if (asm == null)
-                                                continue;
-                                        type = asm.GetType (typeName);
-                                        if (type != null)
-                                                return type;
-                                }
-                        }
-
-                        if (!Directory.Exists (PrivateBinPath))
-                                return null;
-
-                        string [] binDlls = Directory.GetFiles (PrivateBinPath, "*.dll");
-                        foreach (string s in binDlls) {
-                                Assembly binA = Assembly.LoadFrom (s);
-                                type = binA.GetType (typeName);
-                                if (type == null)
-                                        continue;
-
-                                return type;
-                        }
-
-                        return null;
-                }
-		
+#if NET_2_0		
 		static Type MapTagType (Type tagType)
 		{
 			if (tagType == null)
@@ -377,7 +344,7 @@ namespace System.Web.UI {
 				
 				try {
 					originalTypeName = tmi.TagType;
-					originalType = LoadType (originalTypeName);
+					originalType = HttpApplication.LoadType (originalTypeName);
 					if (originalType == null)
 						missingType = true;
 					else
@@ -395,7 +362,7 @@ namespace System.Web.UI {
 					mappedType = null;
 					
 					try {
-						mappedType = LoadType (mappedTypeName);
+						mappedType = HttpApplication.LoadType (mappedTypeName);
 						if (mappedType == null)
 							missingType = true;
 						else

+ 9 - 36
mcs/class/System.Web/System.Web.UI/TemplateParser.cs

@@ -363,44 +363,17 @@ namespace System.Web.UI {
 
 		internal Type LoadType (string typeName)
 		{
-			// First try loaded assemblies, then try assemblies in Bin directory.
-			Type type = null;
-			bool seenBin = false;
-			Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies ();
-			foreach (Assembly ass in assemblies) {
-				type = ass.GetType (typeName);
-				if (type == null)
-					continue;
-
-				if (Path.GetDirectoryName (ass.Location) != PrivateBinPath) {
-					AddAssembly (ass, true);
-				} else {
-					seenBin = true;
-				}
-
-				AddDependency (ass.Location);
-				return type;
-			}
-
-			if (seenBin)
-				return null;
-
-			// Load from bin
-			if (!Directory.Exists (PrivateBinPath))
+			Type type = HttpApplication.LoadType (typeName);
+			if (type == null)
 				return null;
+			Assembly asm = type.Assembly;
+			string location = asm.Location;
+			
+			AddDependency (location);
+			if (Path.GetDirectoryName (location) != PrivateBinPath)
+				AddAssembly (asm, true);
 
-			string [] binDlls = Directory.GetFiles (PrivateBinPath, "*.dll");
-			foreach (string s in binDlls) {
-				Assembly binA = Assembly.LoadFrom (s);
-				type = binA.GetType (typeName);
-				if (type == null)
-					continue;
-
-				AddDependency (binA.Location);
-				return type;
-			}
-
-			return null;
+			return type;
 		}
 
 		void AddAssembliesInBin ()

+ 7 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,10 @@
+2007-05-15  Marek Habersack  <[email protected]>
+
+	* HttpApplication.cs: refactoring - moved LoadType from
+	WebConfigurationHost here and made it internal static, in order to
+	make the code avaliable from all the places where extended type
+	loading is required.
+
 2007-05-14  Marek Habersack  <[email protected]>
  
 	* HttpUtility.cs: when parsing query strings, skip the leading ?

+ 58 - 0
mcs/class/System.Web/System.Web/HttpApplication.cs

@@ -67,6 +67,7 @@ using System.Collections;
 using System.ComponentModel;
 using System.Configuration;
 using System.Globalization;
+using System.Reflection;
 using System.Security.Permissions;
 using System.Security.Principal;
 using System.Threading;
@@ -1304,6 +1305,63 @@ namespace System.Web {
 			}
 		}
 #endregion
+
+		private static string privateBinPath;
+		private static string PrivateBinPath {
+			get {
+				if (privateBinPath != null)
+					return privateBinPath;
+				
+				AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
+				privateBinPath = Path.Combine(setup.ApplicationBase, setup.PrivateBinPath);
+				return privateBinPath;
+			}
+		}		
+
+		internal static Type LoadType (string typeName)
+		{
+			return LoadType (typeName, false);
+		}
+		
+		internal static Type LoadType (string typeName, bool throwOnMissing)
+		{
+			Type type = Type.GetType (typeName, throwOnMissing);
+			if (type != null)
+				return type;
+
+#if NET_2_0
+			IList tla = System.Web.Compilation.BuildManager.TopLevelAssemblies;
+			if (tla != null && tla.Count > 0) {
+				foreach (Assembly asm in tla) {
+					if (asm == null)
+						continue;
+					type = asm.GetType (typeName, throwOnMissing);
+					if (type != null)
+						break;
+				}
+			}
+			if (type != null)
+				return type;
+#endif
+			
+			if (!Directory.Exists (PrivateBinPath))
+				return null;
+			
+			string[] binDlls = Directory.GetFiles(PrivateBinPath, "*.dll");
+			foreach (string s in binDlls) {
+				Assembly binA = Assembly.LoadFrom (s);
+				type = binA.GetType (typeName, throwOnMissing);
+				if (type == null)
+					continue;
+				
+				return type;
+			}
+
+			if (throwOnMissing)
+				throw new TypeLoadException (String.Format ("Type '{0}' cannot be found", typeName));
+			
+			return null;
+		}
 	}
 
 	//