using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework.Library;

namespace Howest.Guidance.Extensions.Common.Helpers
{
	public static class DteHelperAdv
	{
		public static bool IsWebProject(Project project)
		{
			Guard.ArgumentNotNull(project, "project");
			return DteHelper.IsWebProject(project) || ProjectHasExtender(project, "WebApplication");
		}

		public static bool ProjectHasExtender(Project project, string extenderName)
		{
			Guard.ArgumentNotNull(project, "project");
			bool bResult = false;
			object[] colExtenderNames;
			try
			{
				// We could use proj.Extender(extenderName) but it causes an exception if not present and 
				// therefore it can cause performance problems if called multiple times. We use instead:

				colExtenderNames = (object[])project.ExtenderNames;
				if (colExtenderNames.Length > 0)
				{
					foreach (object objExtenderName in colExtenderNames)
					{
						if (objExtenderName.ToString() == extenderName)
						{
							bResult = true;
							break;
						}

					}
				}
			}
			catch (Exception) { }
			return bResult;

		}
	}
}
