/// <summary> /// Gets the value of a given property on the given task. /// </summary> internal object GetPropertyValue(ITask task, TaskPropertyInfo property) { ErrorUtilities.VerifyThrowArgumentNull(task, "task"); ErrorUtilities.VerifyThrowArgumentNull(property, "property"); IGeneratedTask generatedTask = task as IGeneratedTask; if (generatedTask != null) { return(generatedTask.GetPropertyValue(property)); } else { ReflectableTaskPropertyInfo propertyInfo = property as ReflectableTaskPropertyInfo; if (propertyInfo != null) { return(propertyInfo.Reflection.GetValue(task, null)); } else { ErrorUtilities.ThrowInternalError("Task does not implement IGeneratedTask and we don't have {0} either.", typeof(ReflectableTaskPropertyInfo).Name); throw new InternalErrorException(); // unreachable } } }
/// <inheritdoc cref="ITaskFactory.Initialize"/> public bool Initialize(string taskName, IDictionary <string, TaskPropertyInfo> parameterGroup, string taskBody, IBuildEngine taskFactoryLoggingHost) { WaitForDebuggerIfConfigured(); _log = new TaskLoggingHelper(taskFactoryLoggingHost, taskName) { TaskResources = Strings.ResourceManager, }; _taskName = taskName; _parameters = parameterGroup.Values.ToArray(); // Attempt to parse and extract everything from the <UsingTask /> // if (!TryLoadTaskBody(_log, _taskName, taskBody, _parameters, out TaskInfo taskInfo)) { return(false); } // Attempt to compile an assembly (or get one from the cache) // if (!TryCompileInMemoryAssembly(taskFactoryLoggingHost, taskInfo, out Assembly assembly)) { return(false); } if (assembly != null) { TaskType = assembly.GetExportedTypes().FirstOrDefault(type => type.Name.Equals(taskName)); } if (TaskType != null) { // Perform automatic parameter detection if the user supplied a class. // This reduces the burden of the developer by not requiring them to // manually specify <ParameterGroup/>. // if (taskInfo.CodeType == CodeTaskFactoryCodeType.Class) { PropertyInfo[] properties = TaskType.GetProperties(BindingFlags.Instance | BindingFlags.Public); _parameters = new TaskPropertyInfo[properties.Length]; for (int i = 0; i < properties.Length; i++) { PropertyInfo property = properties[i]; _parameters[i] = new TaskPropertyInfo( property.Name, property.PropertyType, property.GetCustomAttribute <OutputAttribute>() != null, property.GetCustomAttribute <RequiredAttribute>() != null); } } } AppDomain.CurrentDomain.AssemblyResolve += AppDomain_AssemblyResolve; // Initialization succeeded if we found a type matching the task name from the compiled assembly // return(TaskType != null); }
/// <summary> /// Get the type information for all task parameters /// </summary> public TaskPropertyInfo[] GetTaskParameters() { var properties = new TaskPropertyInfo[_taskParameterTypeInfo.Count]; _taskParameterTypeInfo.Values.CopyTo(properties, 0); return(properties); }
/// <summary> /// Populate the cache of PropertyInfos for this type /// </summary> private void PopulatePropertyInfoCacheIfNecessary() { if (_propertyInfoCache == null) { _propertyInfoCache = new Dictionary <string, TaskPropertyInfo>(StringComparer.OrdinalIgnoreCase); // Use a HybridDictionary because these are usually very small _namesOfPropertiesWithRequiredAttribute = new HybridDictionary <string, string>(StringComparer.OrdinalIgnoreCase); _namesOfPropertiesWithOutputAttribute = new HybridDictionary <string, string>(StringComparer.OrdinalIgnoreCase); _namesOfPropertiesWithAmbiguousMatches = new HybridDictionary <string, string>(StringComparer.OrdinalIgnoreCase); bool taskTypeImplementsIGeneratedTask = typeof(IGeneratedTask).IsAssignableFrom(_taskFactory.TaskType); TaskPropertyInfo[] propertyInfos = _taskFactory.GetTaskParameters(); for (int i = 0; i < propertyInfos.Length; i++) { // If the task implements IGeneratedTask, we must use the TaskPropertyInfo the factory gives us. // Otherwise, we never have to hand the TaskPropertyInfo back to the task or factory, so we replace // theirs with one of our own that will allow us to cache reflection data per-property. TaskPropertyInfo propertyInfo = propertyInfos[i]; if (!taskTypeImplementsIGeneratedTask) { propertyInfo = new ReflectableTaskPropertyInfo(propertyInfo, _taskFactory.TaskType); } try { _propertyInfoCache.Add(propertyInfo.Name, propertyInfo); } catch (ArgumentException) { // We have encountered a duplicate entry in our hashtable; if we had used BindingFlags.IgnoreCase this // would have produced an AmbiguousMatchException. In the old code, before this cache existed, // that wouldn't have been thrown unless and until the project actually tried to set this ambiguous parameter. // So rather than fail here, we store a list of ambiguous names and throw later, when one of them // is requested. _namesOfPropertiesWithAmbiguousMatches[propertyInfo.Name] = String.Empty; } if (propertyInfos[i].Required) { // we have a require attribute defined, keep a record of that _namesOfPropertiesWithRequiredAttribute[propertyInfo.Name] = String.Empty; } if (propertyInfos[i].Output) { // we have a output attribute defined, keep a record of that _namesOfPropertiesWithOutputAttribute[propertyInfo.Name] = String.Empty; } } // Toss the dictionaries if we can as often they are empty (at least the last three are) _propertyInfoCache = (_propertyInfoCache.Count == 0) ? ReadOnlyEmptyDictionary <string, TaskPropertyInfo> .Instance : _propertyInfoCache; _namesOfPropertiesWithRequiredAttribute = (_namesOfPropertiesWithRequiredAttribute.Count == 0) ? ReadOnlyEmptyDictionary <string, string> .Instance : _namesOfPropertiesWithRequiredAttribute; _namesOfPropertiesWithOutputAttribute = (_namesOfPropertiesWithOutputAttribute.Count == 0) ? ReadOnlyEmptyDictionary <string, string> .Instance : _namesOfPropertiesWithOutputAttribute; _namesOfPropertiesWithAmbiguousMatches = (_namesOfPropertiesWithAmbiguousMatches.Count == 0) ? ReadOnlyEmptyDictionary <string, string> .Instance : _namesOfPropertiesWithAmbiguousMatches; } }
/// <summary> /// Gets the property value. /// </summary> /// <param name="property">The property.</param> /// <returns>The value of the property.</returns> public object GetPropertyValue(TaskPropertyInfo property) { dynamic res; dynamic variable = this.scope.GetVariable(RubyUtils.HasMangledName(property.Name) ? RubyUtils.TryMangleName(property.Name) : property.Name); variable.TryGetValue(out res); return(res); }
public TaskPropertyInfo[] GetTaskParameters() { PropertyInfo[] properties = this.TaskType.GetProperties(BindingFlags.Public | BindingFlags.Instance); TaskPropertyInfo[] infoArray2 = new TaskPropertyInfo[properties.Length]; for (int i = 0; i < properties.Length; i++) { infoArray2[i] = new TaskPropertyInfo(properties[i].Name, properties[i].PropertyType, properties[i].GetCustomAttributes(typeof(OutputAttribute), false).Length > 0, properties[i].GetCustomAttributes(typeof(RequiredAttribute), false).Length > 0); } return(infoArray2); }
/// <summary> /// Gets all of the parameters on the task. /// </summary> public TaskPropertyInfo[] GetTaskParameters() { PropertyInfo[] infos = TaskType.GetProperties(BindingFlags.Instance | BindingFlags.Public); var propertyInfos = new TaskPropertyInfo[infos.Length]; for (int i = 0; i < infos.Length; i++) { propertyInfos[i] = new ReflectableTaskPropertyInfo(infos[i]); } return propertyInfos; }
/// <summary> /// Get the descriptions for all the task's parameters. /// </summary> /// <returns>A non-null array of property descriptions.</returns> TaskPropertyInfo[] ITaskFactory.GetTaskParameters() { PropertyInfo[] infos = typeof(TTask).GetProperties(BindingFlags.Instance | BindingFlags.Public); var propertyInfos = new TaskPropertyInfo[infos.Length]; for (int i = 0; i < infos.Length; i++) { propertyInfos[i] = new TaskPropertyInfo( infos[i].Name, infos[i].PropertyType, infos[i].GetCustomAttributes(typeof(OutputAttribute), false).Length > 0, infos[i].GetCustomAttributes(typeof(RequiredAttribute), false).Length > 0); } return(propertyInfos); }
/// <summary> /// Sets the given property on the task. /// </summary> internal void SetPropertyValue(ITask task, TaskPropertyInfo property, object value) { ErrorUtilities.VerifyThrowArgumentNull(task, "task"); ErrorUtilities.VerifyThrowArgumentNull(property, "property"); IGeneratedTask generatedTask = task as IGeneratedTask; if (generatedTask != null) { generatedTask.SetPropertyValue(property, value); } else { ReflectableTaskPropertyInfo propertyInfo = (ReflectableTaskPropertyInfo)property; propertyInfo.Reflection.SetValue(task, value, null); } }
public bool Initialize(string taskName, IDictionary <string, TaskPropertyInfo> parameterGroup, string?taskBody, IBuildEngine taskFactoryLoggingHost) { _taskName = taskName; if (taskBody != null && taskBody.StartsWith("debug", StringComparison.InvariantCultureIgnoreCase)) { _logDebugTask = true; } var log = new TaskLoggingHelper(taskFactoryLoggingHost, _taskName); if (!ValidateParameterGroup(parameterGroup, log)) { return(false); } _taskProperties = new TaskPropertyInfo[parameterGroup.Count + 1]; _taskProperties[0] = new TaskPropertyInfo(nameof(JsonFilePath), typeof(string), output: false, required: true); parameterGroup.Values.CopyTo(_taskProperties, 1); return(true); }
public object GetPropertyValue(TaskPropertyInfo property) { if (_setParameters.TryGetValue(property.Name, out object value)) { // If we returned an exception, then we want to throw it when we // do the get. if (value is Exception ex) { throw ex; } return(value); } else { PropertyInfo parameter = _taskType.Type.GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public); return(parameter.GetValue(this, null)); } }
/// <summary> /// Returns the value of the requested task parameter /// </summary> public object GetPropertyValue(TaskPropertyInfo property) { if (_setParameters.ContainsKey(property.Name)) { object value = _setParameters[property.Name]; // If we returned an exception, then we want to throw it when we // do the get. if (value != null && (value as Exception) != null) { throw (Exception)value; } return(_setParameters[property.Name]); } else { PropertyInfo parameter = _taskType.Type.GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public); return(parameter.GetValue(this, null)); } }
/// <summary> /// Create a property (with the corresponding private field) from the given type information /// </summary> private static void CreateProperty(CodeTypeDeclaration codeTypeDeclaration, TaskPropertyInfo propInfo, object defaultValue) { CreateProperty(codeTypeDeclaration, propInfo.Name, propInfo.PropertyType, defaultValue); }
} // proc Dispose public object GetPropertyValue(TaskPropertyInfo property) => Lua.RtConvertValue(global[property.Name], property.PropertyType);
/// <summary> /// Sets a value on a property of this task instance. /// </summary> /// <param name="property">The property to set.</param> /// <param name="value">The value to set. The caller is responsible to type-coerce this value to match the property's <see cref="TaskPropertyInfo.PropertyType"/>.</param> /// <remarks> /// All exceptions from this method will be caught in the taskExecution host and logged as a fatal task error /// </remarks> public void SetPropertyValue(TaskPropertyInfo property, object value) { GetType().GetProperty(property.Name).SetValue(this, value, null); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="property">The property to get.</param> /// <returns> /// The value of the property, the value's type will match the type given by <see cref="TaskPropertyInfo.PropertyType"/>. /// </returns> /// <remarks> /// MSBuild calls this method after executing the task to get output parameters. /// All exceptions from this method will be caught in the taskExecution host and logged as a fatal task error /// </remarks> public object GetPropertyValue(TaskPropertyInfo property) { return(GetType().GetProperty(property.Name).GetValue(this, null)); }
} // proc Dispose public object GetPropertyValue(TaskPropertyInfo property) { return(Lua.RtConvertValue(global[property.Name], property.PropertyType)); } // func GetPropertyValue
} // func GetPropertyValue public void SetPropertyValue(TaskPropertyInfo property, object value) { global[property.Name] = value; } // proc SetPropertyValue
/// <summary> /// Initializes a new instance of the <see cref="ReflectableTaskPropertyInfo"/> class. /// </summary> /// <param name="taskPropertyInfo">The original property info that generated this instance.</param> /// <param name="taskType">The type to reflect over to get the reflection propertyinfo later.</param> internal ReflectableTaskPropertyInfo(TaskPropertyInfo taskPropertyInfo, Type taskType) : base(taskPropertyInfo.Name, taskPropertyInfo.PropertyType, taskPropertyInfo.Output, taskPropertyInfo.Required) { ErrorUtilities.VerifyThrowArgumentNull(taskType, "taskType"); _taskType = taskType; }
public object GetPropertyValue(TaskPropertyInfo property) => null !;
/// <summary> /// Sets the property value. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value to set.</param> public void SetPropertyValue(TaskPropertyInfo property, object value) { _taskScope.SetProperty((object)TaskInstance, property.Name, value); }
public object GetPropertyValue(TaskPropertyInfo property) { return(this.pipeline.Runspace.SessionStateProxy.GetVariable(property.Name)); }
public void SetPropertyValue(TaskPropertyInfo property, object value) { _setParameters[property.Name] = value; }
public void SetPropertyValue(TaskPropertyInfo property, object value) { }
/// <summary> /// Sets the property value. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value to set.</param> public void SetPropertyValue(TaskPropertyInfo property, object value) { ((ScriptScope)this.scope).SetVariable(property.Name, value); }
public TaskPropertyInfo[] GetTaskParameters() { TaskPropertyInfo[] array = new TaskPropertyInfo[this.taskParameterTypeInfo.Count]; this.taskParameterTypeInfo.Values.CopyTo(array, 0); return(array); }
public void SetPropertyValue(TaskPropertyInfo property, object value) { this.pipeline.Runspace.SessionStateProxy.SetVariable(property.Name, value); }
public object GetPropertyValue(TaskPropertyInfo property) { return(_taskScope.GetProperty((object)TaskInstance, property.Name, property.PropertyType)); }