本文整理汇总了C#中Microsoft.Build.Evaluation.ProjectItem.GetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectItem.GetMetadata方法的具体用法?C# ProjectItem.GetMetadata怎么用?C# ProjectItem.GetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.ProjectItem
的用法示例。
在下文中一共展示了ProjectItem.GetMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArgumentNullException
void IProjectItemListProvider.AddProjectItem(ProjectItem item)
{
if (item == null)
throw new ArgumentNullException("item");
if (item.Project != this)
throw new ArgumentException("item does not belong to this project", "item");
if (item.IsAddedToProject)
throw new ArgumentException("item is already added to project", "item");
WorkbenchSingleton.AssertMainThread();
using (var c = OpenCurrentConfiguration()) {
items.Add(item);
itemsReadOnly = null; // remove readonly variant of item list - will regenerate on next Items call
/*foreach (var g in projectFile.ItemGroups) {
if (!string.IsNullOrEmpty(g.Condition) || g.Count == 0)
continue;
var firstItemInGroup = g.Items.First();
if (firstItemInGroup.Name == item.ItemType.ItemName) {
MSBuildInternals.AddItemToGroup(g, item);
return;
}
if (firstItemInGroup.ItemType == ItemType.Reference.ItemName)
continue;
if (ItemType.DefaultFileItems.Contains(new ItemType(firstItemInGroup.ItemType))) {
if (ItemType.DefaultFileItems.Contains(item.ItemType)) {
MSBuildInternals.AddItemToGroup(g, item);
return;
} else {
continue;
}
}
MSBuildInternals.AddItemToGroup(g, item);
return;
}
var newGroup = projectFile.AddItemGroup();
MSBuildInternals.AddItemToGroup(newGroup, item);*/
string newInclude = item.TreatIncludeAsLiteral ? MSBuildInternals.Escape(item.Include) : item.Include;
var newMetadata = new Dictionary<string, string>();
foreach (string name in item.MetadataNames) {
newMetadata[name] = item.GetMetadata(name);
}
var newItems = c.Project.AddItem(item.ItemType.ItemName, newInclude, newMetadata);
if (newItems.Count != 1)
throw new InvalidOperationException("expected one new item, but got " + newItems.Count);
item.BuildItem = new MSBuildItemWrapper((MSBuildBasedProject)item.Project, newItems[0]);
Debug.Assert(item.IsAddedToProject);
}
}
示例2: SpecialCharactersInMetadataValueTests
/// <summary>
/// Helper for SpecialCharactersInMetadataValue tests
/// </summary>
internal static void SpecialCharactersInMetadataValueTests(ProjectItem item)
{
Assert.Equal("%3B", item.GetMetadata("EscapedSemicolon").UnevaluatedValue);
Assert.Equal("%3B", item.GetMetadata("EscapedSemicolon").EvaluatedValueEscaped);
Assert.Equal(";", item.GetMetadata("EscapedSemicolon").EvaluatedValue);
Assert.Equal("%3B", Project.GetMetadataValueEscaped(item, "EscapedSemicolon"));
Assert.Equal(";", item.GetMetadataValue("EscapedSemicolon"));
Assert.Equal("%24", item.GetMetadata("EscapedDollarSign").UnevaluatedValue);
Assert.Equal("%24", item.GetMetadata("EscapedDollarSign").EvaluatedValueEscaped);
Assert.Equal("$", item.GetMetadata("EscapedDollarSign").EvaluatedValue);
Assert.Equal("%24", Project.GetMetadataValueEscaped(item, "EscapedDollarSign"));
Assert.Equal("$", item.GetMetadataValue("EscapedDollarSign"));
}