Example #1
0
        public string GetPropertyValue(string propertyName)
        {
            if (_properties.IsDynamicProperty(propertyName))
            {
                string currentState = (string)_state[propertyName];

                // check for circular references
                if (currentState == PropertyDictionary.Visiting)
                {
                    // Currently visiting this node, so have a cycle
                    throw PropertyDictionary.CreateCircularException(propertyName, _visiting);
                }

                _visiting.Push(propertyName);
                _state[propertyName] = PropertyDictionary.Visiting;

                string propertyValue = _properties.Lookup(propertyName);
                if (propertyValue == null)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           ResourceUtils.GetString("NA1053"), propertyName));
                }

                Location propertyLocation = Location.UnknownLocation;

                // TODO - get the proper location of the property declaration

                propertyValue = _properties.ExpandProperties(propertyValue,
                                                             propertyLocation, _state, _visiting);

                _visiting.Pop();
                _state[propertyName] = PropertyDictionary.Visited;
                return(propertyValue);
            }
            else
            {
                string propertyValue = _properties.Lookup(propertyName);
                if (propertyValue == null)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           ResourceUtils.GetString("NA1053"), propertyName));
                }

                return(propertyValue);
            }
        }
Example #2
0
        /// <summary>
        /// Gets a value indicating whether the target should be executed.
        /// </summary>
        /// <value>
        /// <see langword="true" /> if the target should be executed; otherwise,
        /// <see langword="false" />.
        /// </value>
        public bool IfDefined(PropertyAccessor propertyAccesor)
        {
            // expand properties in condition
            string expandedCondition = propertyAccesor.ExpandProperties(IfCondition, Location);

            // if a condition is supplied, it should evaluate to a bool
            if (!String.IsNullOrEmpty(expandedCondition))
            {
                try
                {
                    return(Convert.ToBoolean(expandedCondition, CultureInfo.InvariantCulture));
                }
                catch (FormatException)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           ResourceUtils.GetString("NA1070"), expandedCondition), Location);
                }
            }

            // no condition is supplied
            return(true);
        }