/Microsoft.Build/Microsoft.Build/Microsoft/Build/Execution/TaskRegistry.cs
C# | 588 lines | 558 code | 30 blank | 0 comment | 93 complexity | c4156c75c8d1120cc6a66103285d2efc MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
- namespace Microsoft.Build.Execution
- {
- using Microsoft.Build.BackEnd;
- using Microsoft.Build.BackEnd.Logging;
- using Microsoft.Build.Construction;
- using Microsoft.Build.Evaluation;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Internal;
- using Microsoft.Build.Shared;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Reflection;
- using System.Runtime;
- using System.Runtime.InteropServices;
-
- internal sealed class TaskRegistry
- {
- private Dictionary<string, RegisteredTaskRecord> cachedTaskRecordsWithExactMatch;
- private Dictionary<string, RegisteredTaskRecord> cachedTaskRecordsWithFuzzyMatch;
- private ProjectRootElementCache projectRootElementCache;
- private Dictionary<string, List<RegisteredTaskRecord>> taskRegistrations;
- private readonly Microsoft.Build.Evaluation.Toolset toolset;
-
- internal TaskRegistry(ProjectRootElementCache projectRootElementCache)
- {
- ErrorUtilities.VerifyThrowInternalNull(projectRootElementCache, "projectRootElementCache");
- this.projectRootElementCache = projectRootElementCache;
- }
-
- internal TaskRegistry(Microsoft.Build.Evaluation.Toolset toolset, ProjectRootElementCache projectRootElementCache)
- {
- ErrorUtilities.VerifyThrowInternalNull(projectRootElementCache, "projectRootElementCache");
- ErrorUtilities.VerifyThrowInternalNull(toolset, "toolset");
- this.projectRootElementCache = projectRootElementCache;
- this.toolset = toolset;
- }
-
- private RegisteredTaskRecord GetMatchingRegistration(string taskName, List<RegisteredTaskRecord> taskRecords, string taskProjectFile, TargetLoggingContext targetLoggingContext, IElementLocation elementLocation)
- {
- foreach (RegisteredTaskRecord record in taskRecords)
- {
- if (record.CanTaskBeCreatedByFactory(taskName, taskProjectFile, targetLoggingContext, elementLocation))
- {
- return record;
- }
- }
- return null;
- }
-
- internal TaskFactoryWrapper GetRegisteredTask(string taskName, string taskProjectFile, bool exactMatchRequired, TargetLoggingContext targetLoggingContext, IElementLocation elementLocation)
- {
- TaskFactoryWrapper wrapper = null;
- bool retrievedFromCache = false;
- RegisteredTaskRecord record = this.GetTaskRegistrationRecord(taskName, taskProjectFile, exactMatchRequired, targetLoggingContext, elementLocation, out retrievedFromCache);
- if (record != null)
- {
- string str = (taskName.Length > record.RegisteredName.Length) ? taskName : record.RegisteredName;
- wrapper = record.GetTaskFactoryFromRegistrationRecord(str, taskProjectFile, targetLoggingContext, elementLocation);
- if ((wrapper == null) || retrievedFromCache)
- {
- return wrapper;
- }
- if (record.TaskFactoryAttributeName.Equals("AssemblyTaskFactory"))
- {
- targetLoggingContext.LogComment(MessageImportance.Low, "TaskFound", new object[] { taskName, wrapper.Name });
- }
- else
- {
- targetLoggingContext.LogComment(MessageImportance.Low, "TaskFoundFromFactory", new object[] { taskName, wrapper.Name });
- }
- if (wrapper.TaskFactoryLoadedType.HasSTAThreadAttribute())
- {
- targetLoggingContext.LogComment(MessageImportance.Low, "TaskNeedsSTA", new object[] { taskName });
- }
- }
- return wrapper;
- }
-
- private Dictionary<string, List<RegisteredTaskRecord>> GetRelevantRegistrations(string taskName, bool exactMatchRequired)
- {
- List<RegisteredTaskRecord> list;
- Dictionary<string, List<RegisteredTaskRecord>> dictionary = new Dictionary<string, List<RegisteredTaskRecord>>(StringComparer.OrdinalIgnoreCase);
- if (this.taskRegistrations.TryGetValue(taskName, out list))
- {
- dictionary[taskName] = list;
- return dictionary;
- }
- if (!exactMatchRequired)
- {
- foreach (KeyValuePair<string, List<RegisteredTaskRecord>> pair in this.taskRegistrations)
- {
- if (TypeLoader.IsPartialTypeNameMatch(taskName, pair.Key))
- {
- dictionary[pair.Key] = pair.Value;
- }
- }
- }
- return dictionary;
- }
-
- internal RegisteredTaskRecord GetTaskRegistrationRecord(string taskName, string taskProjectFile, bool exactMatchRequired, TargetLoggingContext targetLoggingContext, IElementLocation elementLocation, out bool retrievedFromCache)
- {
- RegisteredTaskRecord record = null;
- retrievedFromCache = false;
- if (this.toolset != null)
- {
- record = this.toolset.GetOverrideTaskRegistry(targetLoggingContext.LoggingService, targetLoggingContext.BuildEventContext, this.projectRootElementCache).GetTaskRegistrationRecord(taskName, taskProjectFile, exactMatchRequired, targetLoggingContext, elementLocation, out retrievedFromCache);
- }
- if (((record == null) && (this.taskRegistrations != null)) && (this.taskRegistrations.Count > 0))
- {
- Dictionary<string, RegisteredTaskRecord> dictionary = exactMatchRequired ? this.cachedTaskRecordsWithExactMatch : this.cachedTaskRecordsWithFuzzyMatch;
- if ((dictionary != null) && dictionary.TryGetValue(taskName, out record))
- {
- retrievedFromCache = true;
- return record;
- }
- foreach (KeyValuePair<string, List<RegisteredTaskRecord>> pair in this.GetRelevantRegistrations(taskName, exactMatchRequired))
- {
- string str = (taskName.Length > pair.Key.Length) ? taskName : pair.Key;
- record = this.GetMatchingRegistration(str, pair.Value, taskProjectFile, targetLoggingContext, elementLocation);
- if (record != null)
- {
- break;
- }
- }
- }
- if ((record == null) && (this.toolset != null))
- {
- record = this.toolset.GetTaskRegistry(targetLoggingContext.LoggingService, targetLoggingContext.BuildEventContext, this.projectRootElementCache).GetTaskRegistrationRecord(taskName, taskProjectFile, exactMatchRequired, targetLoggingContext, elementLocation, out retrievedFromCache);
- }
- if (exactMatchRequired)
- {
- this.cachedTaskRecordsWithExactMatch = this.cachedTaskRecordsWithExactMatch ?? new Dictionary<string, RegisteredTaskRecord>(StringComparer.OrdinalIgnoreCase);
- this.cachedTaskRecordsWithExactMatch[taskName] = record;
- return record;
- }
- this.cachedTaskRecordsWithFuzzyMatch = this.cachedTaskRecordsWithFuzzyMatch ?? new Dictionary<string, RegisteredTaskRecord>(StringComparer.OrdinalIgnoreCase);
- this.cachedTaskRecordsWithFuzzyMatch[taskName] = record;
- return record;
- }
-
- private static bool IsTaskFactoryClass(Type type, object unused)
- {
- return ((type.IsClass && !type.IsAbstract) && typeof(ITaskFactory).IsAssignableFrom(type));
- }
-
- private void RegisterTask(string taskName, AssemblyLoadInfo assemblyLoadInfo, string taskFactory, RegisteredTaskRecord.ParameterGroupAndTaskElementRecord inlineTaskRecord)
- {
- List<RegisteredTaskRecord> list;
- ErrorUtilities.VerifyThrowInternalLength(taskName, "taskName");
- ErrorUtilities.VerifyThrowInternalNull(assemblyLoadInfo, "assemblyLoadInfo");
- if (this.taskRegistrations == null)
- {
- this.taskRegistrations = new Dictionary<string, List<RegisteredTaskRecord>>(StringComparer.OrdinalIgnoreCase);
- }
- if (!this.taskRegistrations.TryGetValue(taskName, out list))
- {
- list = new List<RegisteredTaskRecord>();
- this.taskRegistrations[taskName] = list;
- }
- list.Add(new RegisteredTaskRecord(taskName, assemblyLoadInfo, taskFactory, inlineTaskRecord));
- }
-
- internal static void RegisterTasksFromUsingTaskElement<P, I>(ILoggingService loggingService, BuildEventContext buildEventContext, string directoryOfImportingFile, ProjectUsingTaskElement projectUsingTaskXml, TaskRegistry taskRegistry, Expander<P, I> expander, ExpanderOptions expanderOptions) where P: class, IProperty where I: class, IItem
- {
- ErrorUtilities.VerifyThrowInternalNull(directoryOfImportingFile, "directoryOfImportingFile");
- if (ConditionEvaluator.EvaluateCondition<P, I>(projectUsingTaskXml.Condition, ParserOptions.AllowPropertiesAndItemLists, expander, expanderOptions, projectUsingTaskXml.ContainingProject.DirectoryPath, projectUsingTaskXml.ConditionLocation, loggingService, buildEventContext))
- {
- string str = null;
- string str2 = null;
- string str3 = expander.ExpandIntoStringLeaveEscaped(projectUsingTaskXml.TaskName, expanderOptions, projectUsingTaskXml.TaskNameLocation);
- ProjectErrorUtilities.VerifyThrowInvalidProject(str3.Length > 0, projectUsingTaskXml.TaskNameLocation, "InvalidEvaluatedAttributeValue", str3, projectUsingTaskXml.TaskName, "Name", "UsingTask");
- string str4 = expander.ExpandIntoStringLeaveEscaped(projectUsingTaskXml.TaskFactory, expanderOptions, projectUsingTaskXml.TaskFactoryLocation);
- if (string.IsNullOrEmpty(str4) || str4.Equals("AssemblyTaskFactory", StringComparison.OrdinalIgnoreCase))
- {
- ProjectXmlUtilities.VerifyThrowProjectNoChildElements(projectUsingTaskXml.XmlElement);
- }
- if (projectUsingTaskXml.AssemblyFile.Length > 0)
- {
- str = expander.ExpandIntoStringLeaveEscaped(projectUsingTaskXml.AssemblyFile, expanderOptions, projectUsingTaskXml.AssemblyFileLocation);
- }
- else
- {
- str2 = expander.ExpandIntoStringLeaveEscaped(projectUsingTaskXml.AssemblyName, expanderOptions, projectUsingTaskXml.AssemblyNameLocation);
- }
- ProjectErrorUtilities.VerifyThrowInvalidProject((str == null) || (str.Length > 0), projectUsingTaskXml.AssemblyFileLocation, "InvalidEvaluatedAttributeValue", str, projectUsingTaskXml.AssemblyFile, "AssemblyFile", "UsingTask");
- ProjectErrorUtilities.VerifyThrowInvalidProject((str2 == null) || (str2.Length > 0), projectUsingTaskXml.AssemblyNameLocation, "InvalidEvaluatedAttributeValue", str2, projectUsingTaskXml.AssemblyName, "AssemblyName", "UsingTask");
- try
- {
- if ((str != null) && !Path.IsPathRooted(str))
- {
- str = Path.Combine(directoryOfImportingFile, str);
- }
- }
- catch (ArgumentException exception)
- {
- ProjectErrorUtilities.ThrowInvalidProject(projectUsingTaskXml.Location, "InvalidAttributeValueWithException", str, "AssemblyFile", "UsingTask", exception.Message);
- }
- RegisteredTaskRecord.ParameterGroupAndTaskElementRecord inlineTaskRecord = null;
- if (projectUsingTaskXml.Count > 0)
- {
- inlineTaskRecord = new RegisteredTaskRecord.ParameterGroupAndTaskElementRecord();
- inlineTaskRecord.ExpandUsingTask<P, I>(projectUsingTaskXml, expander, expanderOptions);
- }
- taskRegistry.RegisterTask(str3, new AssemblyLoadInfo(str2, str), str4, inlineTaskRecord);
- }
- }
-
- internal IDictionary<string, List<RegisteredTaskRecord>> TaskRegistrations
- {
- get
- {
- if (this.taskRegistrations == null)
- {
- this.taskRegistrations = new Dictionary<string, List<RegisteredTaskRecord>>(StringComparer.OrdinalIgnoreCase);
- }
- return this.taskRegistrations;
- }
- }
-
- internal Microsoft.Build.Evaluation.Toolset Toolset
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.toolset;
- }
- }
-
- internal class RegisteredTaskRecord
- {
- internal const string AssemblyTaskFactory = "AssemblyTaskFactory";
- private ParameterGroupAndTaskElementRecord parameterGroupAndTaskBody;
- private string registeredName;
- private string taskFactory;
- private AssemblyLoadInfo taskFactoryAssemblyLoadInfo;
- private static readonly TypeFilter taskFactoryTypeFilter = new TypeFilter(TaskRegistry.IsTaskFactoryClass);
- private static TypeLoader taskFactoryTypeLoader;
- private static readonly object taskFactoryTypeLoaderLock = new object();
- private TaskFactoryWrapper taskFactoryWrapperInstance;
- private Dictionary<string, object> taskNamesCreatableByFactory;
-
- internal RegisteredTaskRecord(string registeredName, AssemblyLoadInfo assemblyLoadInfo, string taskFactory, ParameterGroupAndTaskElementRecord inlineTask)
- {
- ErrorUtilities.VerifyThrowArgumentNull(assemblyLoadInfo, "AssemblyLoadInfo");
- this.registeredName = registeredName;
- this.taskFactoryAssemblyLoadInfo = assemblyLoadInfo;
- this.parameterGroupAndTaskBody = inlineTask;
- if (string.IsNullOrEmpty(taskFactory))
- {
- this.taskFactory = "AssemblyTaskFactory";
- }
- else
- {
- this.taskFactory = taskFactory;
- }
- if (inlineTask == null)
- {
- this.parameterGroupAndTaskBody = new ParameterGroupAndTaskElementRecord();
- }
- }
-
- internal bool CanTaskBeCreatedByFactory(string taskName, string taskProjectFile, TargetLoggingContext targetLoggingContext, IElementLocation elementLocation)
- {
- if (this.taskNamesCreatableByFactory == null)
- {
- this.taskNamesCreatableByFactory = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
- }
- object obj2 = null;
- if (!this.taskNamesCreatableByFactory.TryGetValue(taskName, out obj2))
- {
- try
- {
- if (this.GetTaskFactory(targetLoggingContext, elementLocation, taskProjectFile))
- {
- if (this.TaskFactoryAttributeName == "AssemblyTaskFactory")
- {
- if (taskName.Equals(this.RegisteredName, StringComparison.OrdinalIgnoreCase))
- {
- obj2 = this;
- }
- else if (((Microsoft.Build.BackEnd.AssemblyTaskFactory) this.taskFactoryWrapperInstance.TaskFactory).TaskNameCreatableByFactory(taskName, taskProjectFile, targetLoggingContext, elementLocation))
- {
- obj2 = this;
- }
- else
- {
- obj2 = null;
- }
- }
- else
- {
- try
- {
- if (this.taskFactoryWrapperInstance.IsCreatableByFactory(taskName))
- {
- obj2 = this;
- }
- else
- {
- obj2 = null;
- }
- }
- catch (Exception exception)
- {
- if (ExceptionHandling.IsCriticalException(exception))
- {
- throw;
- }
- string str = string.Empty + exception.ToString();
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "TaskLoadFailure", taskName, this.taskFactoryWrapperInstance.Name, str);
- }
- }
- }
- }
- finally
- {
- this.taskNamesCreatableByFactory[taskName] = obj2;
- }
- }
- return (obj2 != null);
- }
-
- private bool GetTaskFactory(TargetLoggingContext targetLoggingContext, IElementLocation elementLocation, string taskProjectFile)
- {
- if (this.taskFactoryWrapperInstance == null)
- {
- AssemblyLoadInfo taskFactoryAssemblyLoadInfo = this.TaskFactoryAssemblyLoadInfo;
- ErrorUtilities.VerifyThrow(taskFactoryAssemblyLoadInfo != null, "TaskFactoryLoadInfo should never be null");
- ITaskFactory taskFactory = null;
- LoadedType taskFactoryLoadInfo = null;
- if (!string.Equals(this.TaskFactoryAttributeName, "AssemblyTaskFactory", StringComparison.OrdinalIgnoreCase))
- {
- TaskEngineAssemblyResolver resolver = null;
- try
- {
- resolver = new TaskEngineAssemblyResolver();
- resolver.Initialize(taskFactoryAssemblyLoadInfo.AssemblyFile);
- resolver.InstallHandler();
- try
- {
- lock (taskFactoryTypeLoaderLock)
- {
- if (taskFactoryTypeLoader == null)
- {
- taskFactoryTypeLoader = new TypeLoader(taskFactoryTypeFilter);
- }
- }
- taskFactoryLoadInfo = taskFactoryTypeLoader.Load(this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo);
- if (taskFactoryLoadInfo == null)
- {
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "CouldNotFindFactory", this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation);
- }
- targetLoggingContext.LogComment(MessageImportance.Low, "InitializingTaskFactory", new object[] { this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation });
- }
- catch (TargetInvocationException exception)
- {
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "TaskFactoryLoadFailure", this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation, Environment.NewLine + exception.InnerException.ToString());
- }
- catch (ReflectionTypeLoadException exception2)
- {
- foreach (Exception exception3 in exception2.LoaderExceptions)
- {
- if (exception3 != null)
- {
- targetLoggingContext.LogError(new BuildEventFileInfo(taskProjectFile), "TaskFactoryLoadFailure", new object[] { this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation, exception3.Message });
- }
- }
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "TaskFactoryLoadFailure", this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation, exception2.Message);
- }
- catch (Exception exception4)
- {
- if (ExceptionHandling.NotExpectedReflectionException(exception4))
- {
- throw;
- }
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "TaskFactoryLoadFailure", this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation, exception4.Message);
- }
- try
- {
- taskFactory = (ITaskFactory) AppDomain.CurrentDomain.CreateInstanceAndUnwrap(taskFactoryLoadInfo.Type.Assembly.FullName, taskFactoryLoadInfo.Type.FullName);
- TaskFactoryLoggingHost taskFactoryLoggingHost = new TaskFactoryLoggingHost(true, elementLocation, targetLoggingContext);
- bool flag2 = false;
- try
- {
- flag2 = taskFactory.Initialize(this.RegisteredName, this.ParameterGroupAndTaskBody.UsingTaskParameters, this.ParameterGroupAndTaskBody.InlineTaskXmlBody, taskFactoryLoggingHost);
- }
- finally
- {
- taskFactoryLoggingHost.MarkAsInactive();
- }
- if (!flag2)
- {
- this.taskFactoryWrapperInstance = null;
- return false;
- }
- }
- catch (InvalidCastException exception5)
- {
- string str = string.Empty + exception5.Message;
- targetLoggingContext.LogError(new BuildEventFileInfo(elementLocation.File, elementLocation.Line, elementLocation.Column), "TaskFactoryInstantiationFailureErrorInvalidCast", new object[] { this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation, str });
- return false;
- }
- catch (Exception exception6)
- {
- if (ExceptionHandling.IsCriticalException(exception6))
- {
- throw;
- }
- string str2 = string.Empty + exception6.Message;
- ProjectErrorUtilities.ThrowInvalidProject(elementLocation, "TaskFactoryLoadFailure", this.TaskFactoryAttributeName, taskFactoryAssemblyLoadInfo.AssemblyLocation, str2);
- }
- }
- finally
- {
- if (resolver != null)
- {
- resolver.RemoveHandler();
- resolver = null;
- }
- }
- }
- else
- {
- Microsoft.Build.BackEnd.AssemblyTaskFactory factory2 = new Microsoft.Build.BackEnd.AssemblyTaskFactory();
- taskFactoryLoadInfo = factory2.InitializeFactory(taskFactoryAssemblyLoadInfo, this.RegisteredName, this.ParameterGroupAndTaskBody.UsingTaskParameters, this.ParameterGroupAndTaskBody.InlineTaskXmlBody, targetLoggingContext, elementLocation, taskProjectFile);
- taskFactory = factory2;
- }
- this.taskFactoryWrapperInstance = new TaskFactoryWrapper(taskFactory, taskFactoryLoadInfo, this.RegisteredName);
- }
- return true;
- }
-
- internal TaskFactoryWrapper GetTaskFactoryFromRegistrationRecord(string taskName, string taskProjectFile, TargetLoggingContext targetLoggingContext, IElementLocation elementLocation)
- {
- if (this.CanTaskBeCreatedByFactory(taskName, taskProjectFile, targetLoggingContext, elementLocation))
- {
- return this.taskFactoryWrapperInstance;
- }
- return null;
- }
-
- internal ParameterGroupAndTaskElementRecord ParameterGroupAndTaskBody
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.parameterGroupAndTaskBody;
- }
- }
-
- internal string RegisteredName
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.registeredName;
- }
- }
-
- internal AssemblyLoadInfo TaskFactoryAssemblyLoadInfo
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.taskFactoryAssemblyLoadInfo;
- }
- }
-
- internal string TaskFactoryAttributeName
- {
- [DebuggerStepThrough, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.taskFactory;
- }
- }
-
- internal class ParameterGroupAndTaskElementRecord
- {
- private string inlineTaskXmlBody;
- private bool taskBodyEvaluated;
- private Dictionary<string, TaskPropertyInfo> usingTaskParameters = new Dictionary<string, TaskPropertyInfo>(StringComparer.OrdinalIgnoreCase);
-
- internal ParameterGroupAndTaskElementRecord()
- {
- }
-
- private void EvaluateTaskBody<P, I>(Expander<P, I> expander, ProjectUsingTaskBodyElement taskElement, ExpanderOptions expanderOptions) where P: class, IProperty where I: class, IItem
- {
- bool flag;
- string str = expander.ExpandIntoStringLeaveEscaped(taskElement.Evaluate, expanderOptions, taskElement.EvaluateLocation);
- if (!bool.TryParse(str, out flag))
- {
- ProjectErrorUtilities.ThrowInvalidProject(taskElement.EvaluateLocation, "InvalidEvaluatedAttributeValue", str, taskElement.Evaluate, "Evaluate", "Task");
- }
- this.taskBodyEvaluated = flag;
- if (flag)
- {
- this.inlineTaskXmlBody = expander.ExpandIntoStringLeaveEscaped(taskElement.TaskBody, expanderOptions, taskElement.Location);
- }
- else
- {
- this.inlineTaskXmlBody = taskElement.TaskBody;
- }
- }
-
- internal void ExpandUsingTask<P, I>(ProjectUsingTaskElement projectUsingTaskXml, Expander<P, I> expander, ExpanderOptions expanderOptions) where P: class, IProperty where I: class, IItem
- {
- ErrorUtilities.VerifyThrowArgumentNull(projectUsingTaskXml, "projectUsingTaskXml");
- ErrorUtilities.VerifyThrowArgumentNull(expander, "expander");
- ProjectUsingTaskBodyElement taskBody = projectUsingTaskXml.TaskBody;
- if (taskBody != null)
- {
- this.EvaluateTaskBody<P, I>(expander, taskBody, expanderOptions);
- }
- UsingTaskParameterGroupElement parameterGroup = projectUsingTaskXml.ParameterGroup;
- if (parameterGroup != null)
- {
- this.ParseUsingTaskParameterGroupElement<P, I>(parameterGroup, expander, expanderOptions);
- }
- }
-
- private void ParseUsingTaskParameterGroupElement<P, I>(UsingTaskParameterGroupElement usingTaskParameterGroup, Expander<P, I> expander, ExpanderOptions expanderOptions) where P: class, IProperty where I: class, IItem
- {
- foreach (ProjectUsingTaskParameterElement element in usingTaskParameterGroup.Parameters)
- {
- bool flag;
- bool flag2;
- string str = expander.ExpandIntoStringLeaveEscaped(element.ParameterType, expanderOptions, element.ParameterTypeLocation);
- ProjectErrorUtilities.VerifyThrowInvalidProject(!string.IsNullOrEmpty(str), element.ParameterTypeLocation, "InvalidEvaluatedAttributeValue", str, element.ParameterType, "ParameterType", "Parameter");
- Type parameterType = Type.GetType(str);
- if (parameterType == null)
- {
- parameterType = Type.GetType(str + "," + typeof(ITaskItem).Assembly.FullName, false, true);
- ProjectErrorUtilities.VerifyThrowInvalidProject(parameterType != null, element.ParameterTypeLocation, "InvalidEvaluatedAttributeValue", str, element.ParameterType, "ParameterType", "Parameter");
- }
- str = expander.ExpandIntoStringLeaveEscaped(element.Output, expanderOptions, element.OutputLocation);
- if (!bool.TryParse(str, out flag))
- {
- ProjectErrorUtilities.ThrowInvalidProject(element.OutputLocation, "InvalidEvaluatedAttributeValue", str, element.Output, "Output", "Parameter");
- }
- if ((!flag && !TaskParameterTypeVerifier.IsValidInputParameter(parameterType)) || (flag && !TaskParameterTypeVerifier.IsValidOutputParameter(parameterType)))
- {
- ProjectErrorUtilities.ThrowInvalidProject(element.Location, "UnsupportedTaskParameterTypeError", parameterType.FullName, element.ParameterType, element.Name);
- }
- str = expander.ExpandIntoStringLeaveEscaped(element.Required, expanderOptions, element.RequiredLocation);
- if (!bool.TryParse(str, out flag2))
- {
- ProjectErrorUtilities.ThrowInvalidProject(element.RequiredLocation, "InvalidEvaluatedAttributeValue", str, element.Required, "Required", "Parameter");
- }
- this.UsingTaskParameters.Add(element.Name, new TaskPropertyInfo(element.Name, parameterType, flag, flag2));
- }
- }
-
- internal string InlineTaskXmlBody
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.inlineTaskXmlBody;
- }
- }
-
- internal bool TaskBodyEvaluated
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.taskBodyEvaluated;
- }
- }
-
- internal Dictionary<string, TaskPropertyInfo> UsingTaskParameters
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.usingTaskParameters;
- }
- }
- }
- }
- }
- }
-