示例#1
0
        /// <summary>
        /// Gets the values of the specified metadata for the given item.
        /// The keys in the dictionary returned may be qualified and/or unqualified, exactly
        /// as they are found in the metadata reference.
        /// For example if %(x) is found, the key is "x", if %(z.x) is found, the key is "z.x".
        /// This dictionary in each bucket is used by Expander to expand exactly the same metadata references, so
        /// %(x) is expanded using the key "x", and %(z.x) is expanded using the key "z.x".
        /// </summary>
        /// <returns>the metadata values</returns>
        private static Dictionary <string, string> GetItemMetadataValues
        (
            XmlNode parentNode,
            BuildItem item,
            Dictionary <string, MetadataReference> consumedMetadataReferences
        )
        {
            Dictionary <string, string> itemMetadataValues = new Dictionary <string, string>(consumedMetadataReferences.Count, StringComparer.OrdinalIgnoreCase);

            foreach (KeyValuePair <string, MetadataReference> consumedMetadataReference in consumedMetadataReferences)
            {
                string metadataQualifiedName = consumedMetadataReference.Key;
                string metadataItemName      = consumedMetadataReference.Value.itemName;
                string metadataName          = consumedMetadataReference.Value.metadataName;

                if (
                    (metadataItemName != null) &&
                    (!String.Equals(item.Name, metadataItemName, StringComparison.OrdinalIgnoreCase))
                    )
                {
                    itemMetadataValues[metadataQualifiedName] = String.Empty;
                }
                else
                {
                    try
                    {
                        itemMetadataValues[metadataQualifiedName] = item.GetEvaluatedMetadataEscaped(metadataName);
                    }
                    catch (InvalidOperationException e)
                    {
                        ProjectErrorUtilities.VerifyThrowInvalidProject(false, parentNode,
                                                                        "CannotEvaluateItemMetadata", metadataName, e.Message);
                    }
                }
            }

            return(itemMetadataValues);
        }
示例#2
0
        /// <summary>
        /// Retrieves the value of the given metadata for the item currently being transformed.
        /// </summary>
        /// <remarks>This method is a MatchEvaluator delegate passed to Regex.Replace().</remarks>
        /// <owner>SumedhK</owner>
        /// <param name="itemMetadataMatch"></param>
        /// <returns>item metadata value</returns>
        private string ExpandItemMetadata(Match itemMetadataMatch)
        {
            ErrorUtilities.VerifyThrow(itemUnderTransformation != null, "Need item to get metadata value from.");

            string itemMetadataName = itemMetadataMatch.Groups["NAME"].Value;

            ProjectErrorUtilities.VerifyThrowInvalidProject(itemMetadataMatch.Groups["ITEM_SPECIFICATION"].Length == 0,
                                                            parentNode, "QualifiedMetadataInTransformNotAllowed", itemMetadataMatch.Value, itemMetadataName);

            string itemMetadataValue = null;

            try
            {
                itemMetadataValue = itemUnderTransformation.GetEvaluatedMetadataEscaped(itemMetadataName);
            }
            catch (InvalidOperationException e)
            {
                ProjectErrorUtilities.VerifyThrowInvalidProject(false, parentNode,
                                                                "CannotEvaluateItemMetadata", itemMetadataName, e.Message);
            }

            return(itemMetadataValue);
        }
示例#3
0
        /// <summary>
        /// Gets the values of the specified metadata for the given item.
        /// The keys in the dictionary returned may be qualified and/or unqualified, exactly
        /// as they are found in the metadata reference. 
        /// For example if %(x) is found, the key is "x", if %(z.x) is found, the key is "z.x".
        /// This dictionary in each bucket is used by Expander to expand exactly the same metadata references, so
        /// %(x) is expanded using the key "x", and %(z.x) is expanded using the key "z.x".
        /// </summary>
        /// <returns>the metadata values</returns>
        private static Dictionary<string, string> GetItemMetadataValues
        (
            XmlNode parentNode,
            BuildItem item,
            Dictionary<string, MetadataReference> consumedMetadataReferences
        )
        {
            Dictionary<string, string> itemMetadataValues = new Dictionary<string, string>(consumedMetadataReferences.Count, StringComparer.OrdinalIgnoreCase);

            foreach (KeyValuePair<string, MetadataReference> consumedMetadataReference in consumedMetadataReferences)
            {
                string metadataQualifiedName = consumedMetadataReference.Key;
                string metadataItemName = consumedMetadataReference.Value.itemName;
                string metadataName = consumedMetadataReference.Value.metadataName;

                if  (
                        (metadataItemName != null) &&
                        (0 != String.Compare(item.Name, metadataItemName, StringComparison.OrdinalIgnoreCase))
                    )
                {
                    itemMetadataValues[metadataQualifiedName] = String.Empty;
                }
                else
                {
                    try
                    {
                        itemMetadataValues[metadataQualifiedName] = item.GetEvaluatedMetadataEscaped(metadataName);
                    }
                    catch (InvalidOperationException e)
                    {
                        ProjectErrorUtilities.VerifyThrowInvalidProject(false, parentNode,
                            "CannotEvaluateItemMetadata", metadataName, e.Message);
                    }
                }
            }

            return itemMetadataValues;
        }