VsTeXProject.VisualStudio.Project.ProjectConfig.SetPropertyUnderCondition C# (CSharp) Méthode

SetPropertyUnderCondition() private méthode

Emulates the behavior of SetProperty(name, value, condition) on the old MSBuild object model. This finds a property group with the specified condition (or creates one if necessary) then sets the property in there.
private SetPropertyUnderCondition ( string propertyName, string propertyValue, string condition ) : void
propertyName string
propertyValue string
condition string
Résultat void
        private void SetPropertyUnderCondition(string propertyName, string propertyValue, string condition)
        {
            var conditionTrimmed = condition == null ? string.Empty : condition.Trim();

            if (conditionTrimmed.Length == 0)
            {
                ProjectMgr.BuildProject.SetProperty(propertyName, propertyValue);
                return;
            }

            // New OM doesn't have a convenient equivalent for setting a property with a particular property group condition. 
            // So do it ourselves.
            MSBuildConstruction.ProjectPropertyGroupElement newGroup = null;

            foreach (var group in ProjectMgr.BuildProject.Xml.PropertyGroups)
            {
                if (string.Equals(group.Condition.Trim(), conditionTrimmed, StringComparison.OrdinalIgnoreCase))
                {
                    newGroup = group;
                    break;
                }
            }

            if (newGroup == null)
            {
                newGroup = ProjectMgr.BuildProject.Xml.AddPropertyGroup();
                    // Adds after last existing PG, else at start of project
                newGroup.Condition = condition;
            }

            foreach (var property in newGroup.PropertiesReversed) // If there's dupes, pick the last one so we win
            {
                if (string.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase) &&
                    property.Condition.Length == 0)
                {
                    property.Value = propertyValue;
                    return;
                }
            }

            newGroup.AddProperty(propertyName, propertyValue);
        }