/// <summary>
        /// Builds a set of javascript methods which are mapped to corresponding ModuleBase-derived
        /// class methods which are marked with the AjaxMethod attribute.
        /// </summary>
        /// <param name="restrictToTypes"></param>
        /// <returns>A block of javascript defining objects and methods that encapsulate ajax calls to
        /// matching server-side methods</returns>
        public string GetAjaxMethodsScript(params Type[] restrictToTypes)
        {
            if (ajaxScripts == null)
            {
                ajaxScripts = new Dictionary <Type, AjaxModuleRef>();
                foreach (RegisteredModule module in Core.Modules.ModuleRegistry)
                {
                    Type t = module.Module.GetType();
                    // don't include modules that don't have the correct attribute
                    AjaxMethodHandlerAttribute[] amh = (AjaxMethodHandlerAttribute[])t.GetCustomAttributes(typeof(AjaxMethodHandlerAttribute), false);
                    if (amh.Length != 1)
                    {
                        continue;
                    }

                    AjaxModuleRef modref = new AjaxModuleRef(t, amh[0].AjaxTypeName);

                    // get all the methods for the module
                    MethodInfo[] infos     = module.Module.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
                    bool         nameAdded = false;
                    foreach (MethodInfo info in infos)
                    {
                        // make sure the method has the appropriate attribute
                        object[] attrs = info.GetCustomAttributes(typeof(AjaxMethodAttribute), false);
                        if (attrs.Length == 1)
                        {
                            modref.AddMethod(info.Name);
                        }
                    }
                    ajaxScripts.Add(t, modref);
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("Ajax = {};");
            sb.Append(Environment.NewLine);
            foreach (AjaxModuleRef m in ajaxScripts.Values)
            {
                // if restrictions have been specified, make sure this module is included in the accepted module types
                if (restrictToTypes.Length > 0)
                {
                    if (Array.IndexOf <Type>(restrictToTypes, m.Type) == -1)
                    {
                        continue;
                    }
                }

                sb.Append(m.ToString());
            }

            return(sb.ToString());
        }
		/// <summary>
		/// Builds a set of javascript methods which are mapped to corresponding ModuleBase-derived
		/// class methods which are marked with the AjaxMethod attribute.
		/// </summary>
		/// <param name="restrictToAjaxModules">An optional list of ajax module names that should be used instead of the full list</param>
		/// <returns>A block of javascript defining objects and methods that encapsulate ajax calls to
		/// matching server-side methods</returns>
		public string GetAjaxMethodsScript(params string[] restrictToAjaxModules)
		{
			if (ajaxScripts == null)
			{
				ajaxScripts = new Dictionary<Type, AjaxModuleRef>();
				foreach (RegisteredModule module in Core.Modules.ModuleRegistry)
				{
					Type t = module.Module.GetType();
					// don't include modules that don't have the correct attribute
					AjaxMethodHandlerAttribute[] amh = (AjaxMethodHandlerAttribute[])t.GetCustomAttributes(typeof(AjaxMethodHandlerAttribute), false);
					if (amh.Length != 1)
						continue;

					AjaxModuleRef modref = new AjaxModuleRef(t, amh[0].AjaxTypeName);

					// get all the methods for the module
					MethodInfo[] infos = module.Module.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
					foreach (MethodInfo info in infos)
					{
						// make sure the method has the appropriate attribute
						object[] attrs = info.GetCustomAttributes(typeof(AjaxMethodAttribute), false);
						if (attrs.Length == 1)
							modref.AddMethod(info.Name);
					}
					ajaxScripts.Add(t, modref);
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.Append("Ajax = {};");
			sb.Append(Environment.NewLine);
			foreach (AjaxModuleRef m in ajaxScripts.Values)
			{
				// if restrictions have been specified, make sure this module is included in the accepted module types
				if (restrictToAjaxModules.Length > 0)
					if (Array.IndexOf<string>(restrictToAjaxModules, m.AjaxTypeName) == -1)
						continue;

				sb.Append(m.ToString());
			}

			return sb.ToString();
		}