System.Web.UI.SimpleWebHandlerParser.GetTypeFromBin C# (CSharp) Method

GetTypeFromBin() private method

private GetTypeFromBin ( string tname ) : Type
tname string
return System.Type
		internal Type GetTypeFromBin (string tname)
		{
			if (tname == null || tname.Length == 0)
				throw new ArgumentNullException ("tname");
			
			Type result = null;
			string typeName;
			string assemblyName;
			int comma = tname.IndexOf (',');
			
			if (comma != -1) {
				typeName = tname.Substring (0, comma).Trim ();
				assemblyName = tname.Substring (comma + 1).Trim ();
			} else {
				typeName = tname;
				assemblyName = null;
			}

			Type type = null;
			Assembly assembly = null;
			if (assemblyName != null) {
				assembly = Assembly.Load (assemblyName);
				if (assembly != null)
					type = assembly.GetType (typeName, false);
				if (type != null)
					return type;
			}
			
#if NET_2_0
			IList toplevelAssemblies = BuildManager.TopLevelAssemblies;
			if (toplevelAssemblies != null && toplevelAssemblies.Count > 0) {
				foreach (Assembly asm in toplevelAssemblies) {
					type = asm.GetType (typeName, false);
					if (type != null) {
						if (result != null)
							throw new HttpException (String.Format ("Type {0} is not unique.", typeName));
						result = type;
					}
				}
			}
#endif

			foreach (string dll in HttpApplication.BinDirectoryAssemblies) {
				try {
					assembly = Assembly.LoadFrom (dll);
				} catch (FileLoadException) {
					// ignore
					continue;
				} catch (BadImageFormatException) {
					// ignore
					continue;
				}
				
				type = assembly.GetType (typeName, false);
				if (type != null) {
					if (result != null) 
						throw new HttpException (String.Format ("Type {0} is not unique.", typeName));
						
					result = type;
				}
			}

			
			if (result == null)
				throw new HttpException (String.Format ("Type {0} not found.", typeName));

			return result;
		}