MonoDevelop.Projects.Project.GetBuildActions C# (CSharp) Метод

GetBuildActions() публичный Метод

Gets a list of build actions supported by this project
Common actions are grouped at the top, separated by a "--" entry *IF* there are more "uncommon" actions than "common" actions
public GetBuildActions ( ) : string[]
Результат string[]
		public string[] GetBuildActions ()
		{
			if (buildActions != null)
				return buildActions;

			// find all the actions in use and add them to the list of standard actions
			Hashtable actions = new Hashtable ();
			object marker = new object (); //avoid using bools as they need to be boxed. re-use single object instead
			//ad the standard actions
			foreach (string action in GetStandardBuildActions ())
				actions[action] = marker;

			//add any more actions that are in the project file
			foreach (ProjectFile pf in files)
				if (!actions.ContainsKey (pf.BuildAction))
					actions[pf.BuildAction] = marker;

			//remove the "common" actions, since they're handled separately
			IList<string> commonActions = GetCommonBuildActions ();
			foreach (string action in commonActions)
				if (actions.Contains (action))
					actions.Remove (action);

			//calculate dimensions for our new array and create it
			int dashPos = commonActions.Count;
			bool hasDash = commonActions.Count > 0 && actions.Count > 0;
			int arrayLen = commonActions.Count + actions.Count;
			int uncommonStart = hasDash ? dashPos + 1 : dashPos;
			if (hasDash)
				arrayLen++;
			buildActions = new string[arrayLen];

			//populate it
			if (commonActions.Count > 0)
				commonActions.CopyTo (buildActions, 0);
			if (hasDash)
				buildActions[dashPos] = "--";
			if (actions.Count > 0)
				actions.Keys.CopyTo (buildActions, uncommonStart);

			//sort the actions
			if (hasDash) {
				//it may be better to leave common actions in the order that the project specified
				//Array.Sort (buildActions, 0, commonActions.Count, StringComparer.Ordinal);
				Array.Sort (buildActions, uncommonStart, arrayLen - uncommonStart, StringComparer.Ordinal);
			} else {
				Array.Sort (buildActions, StringComparer.Ordinal);
			}
			return buildActions;
		}
		

Usage Example

Пример #1
0
 /// <summary>
 /// Cache the build actions here since adding new files on loading the project will clear the cache
 /// so we avoid re-building the Project's build action cache potentially multiple times. This local
 /// cache is cleared in OnReadProject.
 /// </summary>
 bool IsBuildActionSupported(string buildAction)
 {
     if (cachedBuildActions == null)
     {
         cachedBuildActions = Project.GetBuildActions().Where(a => a != "Folder" && a != "--").ToArray();
     }
     return(cachedBuildActions.Contains(buildAction));
 }