private void Write(ITaskItem item, bool writeMetadata = true)
        {
            WriteDeduplicatedString(item.ItemSpec);
            if (!writeMetadata)
            {
                Write((byte)0);
                return;
            }

            // WARNING: Can't use AddRange here because CopyOnWriteDictionary in Microsoft.Build.Utilities.v4.0.dll
            // is broken. Microsoft.Build.Utilities.v4.0.dll loads from the GAC by XAML markup tooling and it's
            // implementation doesn't work with AddRange because AddRange special-cases ICollection<T> and
            // CopyOnWriteDictionary doesn't implement it properly.
            foreach (var kvp in item.EnumerateMetadata())
            {
                nameValueListBuffer.Add(kvp);
            }

            // Don't sort metadata because we want the binary log to be fully roundtrippable
            // and we need to preserve the original order.
            //if (nameValueListBuffer.Count > 1)
            //{
            //    nameValueListBuffer.Sort((l, r) => StringComparer.OrdinalIgnoreCase.Compare(l.Key, r.Key));
            //}

            WriteNameValueList();

            nameValueListBuffer.Clear();
        }
Ejemplo n.º 2
0
        private void WriteMetadata(BinaryWriter writer, ITaskItem taskItem)
        {
            if (reusableMetadataList == null)
            {
                reusableMetadataList = new List <KeyValuePair <string, string> >();
            }

            // WARNING: Can't use AddRange here because CopyOnWriteDictionary in Microsoft.Build.Utilities.v4.0.dll
            // is broken. Microsoft.Build.Utilities.v4.0.dll loads from the GAC by XAML markup tooling and it's
            // implementation doesn't work with AddRange because AddRange special-cases ICollection<T> and
            // CopyOnWriteDictionary doesn't implement it properly.
            foreach (var kvp in taskItem.EnumerateMetadata())
            {
                reusableMetadataList.Add(kvp);
            }

            writer.Write7BitEncodedInt(reusableMetadataList.Count);
            if (reusableMetadataList.Count == 0)
            {
                return;
            }

            foreach (var kvp in reusableMetadataList)
            {
                writer.Write(kvp.Key);
                writer.Write(kvp.Value);
            }

            reusableMetadataList.Clear();
        }
Ejemplo n.º 3
0
        public TaskItemData(ITaskItem original)
        {
            ItemSpec = original.ItemSpec;
            var metadata = original.EnumerateMetadata();

            // Can't preallocate capacity because we don't know how large it will get
            // without enumerating the enumerable
            var dictionary = new Dictionary <string, string>();

            foreach (var item in metadata)
            {
                dictionary.Add(item.Key, item.Value);
            }

            Metadata = dictionary;
        }