System.Web.UI.ControlBuilder.MapTagType C# (CSharp) Method

MapTagType() static private method

static private MapTagType ( Type tagType ) : Type
tagType Type
return Type
		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 ();
			Type mappedType, originalType;
			string originalTypeName = String.Empty, mappedTypeName = String.Empty;
			bool missingType;
			Exception error;
			
			foreach (TagMapInfo tmi in tags) {
				error = null;
				originalType = null;
				
				try {
					originalTypeName = tmi.TagType;
					originalType = HttpApplication.LoadType (originalTypeName);
					if (originalType == null)
						missingType = true;
					else
						missingType = false;
				} catch (Exception ex) {
					missingType = true;
					error = ex;
				}
				if (missingType)
					throw new HttpException (String.Format ("Could not load type {0}", originalTypeName), error);
				
				if (originalTypeName == tagTypeName) {
					mappedTypeName = tmi.MappedTagType;
					error = null;
					mappedType = null;
					
					try {
						mappedType = HttpApplication.LoadType (mappedTypeName);
						if (mappedType == null)
							missingType = true;
						else
							missingType = false;
					} catch (Exception ex) {
						missingType = true;
						error = ex;
					}

					if (missingType)
						throw new HttpException (String.Format ("Could not load type {0}", mappedTypeName),
									 error);
					
					if (!mappedType.IsSubclassOf (originalType))
						throw new ConfigurationErrorsException (
							String.Format ("The specified type '{0}' used for mapping must inherit from the original type '{1}'.", mappedTypeName, originalTypeName));

					return mappedType;
				}
			}
			
			return tagType;
		}
#endif