本文整理汇总了C#中ITaskItem.CloneCustomMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# ITaskItem.CloneCustomMetadata方法的具体用法?C# ITaskItem.CloneCustomMetadata怎么用?C# ITaskItem.CloneCustomMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITaskItem
的用法示例。
在下文中一共展示了ITaskItem.CloneCustomMetadata方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildItem
public BuildItem (string itemName, ITaskItem taskItem)
{
if (taskItem == null)
throw new ArgumentNullException ("taskItem");
this.name = itemName;
this.finalItemSpec = taskItem.ItemSpec;
this.itemInclude = MSBuildUtils.Escape (taskItem.ItemSpec);
this.evaluatedMetadata = (Hashtable) taskItem.CloneCustomMetadata ();
this.unevaluatedMetadata = (Hashtable) taskItem.CloneCustomMetadata ();
}
示例2: LogItemMetadata
private static void LogItemMetadata(Task task, ITaskItem item, MessageImportance importance)
{
var metadata = item.CloneCustomMetadata();
foreach (var name in metadata.Keys.Cast<string>())
{
LogMetadata(task, name, (string)metadata[name], importance);
}
}
示例3: TaskItem
public TaskItem (ITaskItem sourceItem)
{
if (sourceItem == null)
throw new ArgumentNullException ("sourceItem");
this.itemSpec = sourceItem.ItemSpec;
this.metadata = sourceItem.CloneCustomMetadata ();
}
示例4: GetCustomItemMetadata
public static NameValueCollection GetCustomItemMetadata(ITaskItem taskItem)
{
var nameValueCollection = new NameValueCollection();
foreach (string key in taskItem.CloneCustomMetadata().Keys)
{
nameValueCollection.Add(key, taskItem.GetMetadata(key));
}
return nameValueCollection;
}
示例5: ConvertToPackageFile
private static ITaskItem ConvertToPackageFile(ITaskItem output)
{
var fileName = output.ItemSpec;
var frameworkNameMoniker = output.GetTargetFrameworkMoniker();
var packageDirectory = output.GetPackageDirectory();
var targetFramework = frameworkNameMoniker.GetShortFrameworkName();
var metadata = output.CloneCustomMetadata();
metadata[Metadata.TargetFramework] = targetFramework;
metadata[Metadata.PackageDirectory] = packageDirectory.ToString();
metadata[Metadata.FileTarget] = packageDirectory.Combine(targetFramework, Path.GetFileName(fileName));
return new TaskItem(fileName, metadata);
}
示例6: TaskItem
public TaskItem (ITaskItem sourceItem)
{
if (sourceItem == null)
throw new ArgumentNullException ("sourceItem");
var ti2 = sourceItem as ITaskItem2;
if (ti2 != null) {
escapedItemSpec = ti2.EvaluatedIncludeEscaped;
escapedMetadata = ti2.CloneCustomMetadataEscaped ();
} else
{
escapedItemSpec = MSBuildUtils.Escape (sourceItem.ItemSpec);
escapedMetadata = sourceItem.CloneCustomMetadata ();
foreach (string key in new ArrayList (escapedMetadata.Keys))
escapedMetadata [key] = MSBuildUtils.Escape ((string)escapedMetadata [key]);
}
}
示例7: ConvertToPackageFile
private static ITaskItem ConvertToPackageFile(ITaskItem output)
{
var fileName = output.ItemSpec;
var targetPath = output.GetMetadata("TargetPath");
targetPath = string.IsNullOrEmpty(targetPath) ? Path.GetFileName(fileName) : targetPath;
var frameworkNameMoniker = output.GetTargetFrameworkMoniker();
var packageDirectory = output.GetPackageDirectory();
var targetSubdirectory = output.GetTargetSubdirectory();
var targetFramework = packageDirectory == PackageDirectory.Analyzers
? frameworkNameMoniker.GetAnalyzersFrameworkName()
: frameworkNameMoniker.GetShortFrameworkName();
var metadata = output.CloneCustomMetadata();
metadata[Metadata.TargetFramework] = targetFramework;
metadata[Metadata.PackageDirectory] = packageDirectory.ToString();
metadata[Metadata.TargetSubdirectory] = targetSubdirectory;
metadata[Metadata.FileTarget] = packageDirectory.Combine(targetFramework, targetSubdirectory, targetPath);
return new TaskItem(fileName, metadata);
}
示例8: TestCloneCustomMetadata
public void TestCloneCustomMetadata ()
{
item = new TaskItem ();
item.SetMetadata ("AAA", "111");
item.SetMetadata ("aaa", "222");
item.SetMetadata ("BBB", "111");
string [] metakeys = new string [] { "aaa", "BBB" };
IDictionary meta = item.CloneCustomMetadata ();
Assert.IsTrue (CompareStringCollections (meta.Keys, metakeys), "A1");
metakeys [0] = "aAa";
Assert.IsTrue (CompareStringCollections (meta.Keys, metakeys), "A2");
Assert.AreEqual ("222", meta ["aaa"], "A3");
Assert.AreEqual ("222", meta ["AAA"], "A4");
Assert.AreEqual ("222", meta ["aAa"], "A5");
Assert.AreEqual ("111", meta ["BbB"], "A5");
}
示例9: Publish
private void Publish(IS3Client client,
ITaskItem sourceFolder,
string bucket,
string destinationFolder,
bool publicRead,
int timeoutMilliseconds)
{
var dirInfo = new DirectoryInfo(sourceFolder.GetMetadata("Identity"));
var headers = MsBuildHelpers.GetCustomItemMetadata(sourceFolder);
var files = dirInfo.GetFiles();
foreach (var f in files)
{
Logger.LogMessage(MessageImportance.Normal, string.Format("Copying file {0}", f.FullName));
client.PutFileWithHeaders(bucket, CreateRelativePath(destinationFolder, f.Name), f.FullName, headers, publicRead, timeoutMilliseconds);
}
var dirs = dirInfo.GetDirectories();
foreach (var d in dirs)
{
Publish(client, new TaskItem(d.FullName, sourceFolder.CloneCustomMetadata()), bucket, CreateRelativePath(destinationFolder, d.Name), publicRead, timeoutMilliseconds);
}
}
示例10: AddEvaluatedItem
void AddEvaluatedItem (Project project, bool evaluatedTo, ITaskItem taskitem)
{
if (IsDynamic && evaluatedTo && !KeepDuplicates && ContainsItem (project, taskitem))
return;
BuildItemGroup big;
BuildItem bi = new BuildItem (this);
bi.finalItemSpec = taskitem.ItemSpec;
foreach (DictionaryEntry de in taskitem.CloneCustomMetadata ()) {
bi.unevaluatedMetadata.Add ((string) de.Key, (string) de.Value);
bi.evaluatedMetadata.Add ((string) de.Key, (string) de.Value);
}
project.EvaluatedItemsIgnoringCondition.AddItem (bi);
if (evaluatedTo) {
project.EvaluatedItems.AddItem (bi);
if (!project.EvaluatedItemsByName.ContainsKey (bi.Name)) {
big = new BuildItemGroup (null, project, null, true);
project.EvaluatedItemsByName.Add (bi.Name, big);
} else {
big = project.EvaluatedItemsByName [bi.Name];
}
big.AddItem (bi);
}
if (!project.EvaluatedItemsByNameIgnoringCondition.ContainsKey (bi.Name)) {
big = new BuildItemGroup (null, project, null, true);
project.EvaluatedItemsByNameIgnoringCondition.Add (bi.Name, big);
} else {
big = project.EvaluatedItemsByNameIgnoringCondition [bi.Name];
}
big.AddItem (bi);
if (IsDynamic)
AddAndRemoveMetadata (project, bi);
}
示例11: AreEqual
/// <summary>
/// Asserts the equality (or lack thereof) of two ITaskItems.
/// </summary>
internal static void AreEqual(ITaskItem x, ITaskItem y)
{
if (x == null && y == null)
{
return;
}
if (x == null || y == null)
{
Assert.True(false, "The two items are not equal -- one of them is null");
}
Assert.Equal(x.ItemSpec, y.ItemSpec);
IDictionary metadataFromX = x.CloneCustomMetadata();
IDictionary metadataFromY = y.CloneCustomMetadata();
Assert.Equal(metadataFromX.Count, metadataFromY.Count);
foreach (object metadataName in metadataFromX.Keys)
{
if (!metadataFromY.Contains(metadataName))
{
Assert.True(false, string.Format("Only one item contains the '{0}' metadata", metadataName));
}
else
{
Assert.Equal(metadataFromX[metadataName], metadataFromY[metadataName]);
}
}
}
示例12: BuildItem
/// <summary>
/// This constructor creates a new virtual (non-persisted) item based
/// on a ITaskItem object that was emitted by a task.
/// </summary>
public BuildItem(string itemName, ITaskItem taskItem)
{
ErrorUtilities.VerifyThrowArgumentNull(taskItem, "taskItem");
string itemInclude = EscapingUtilities.Escape(taskItem.ItemSpec);
BuildItemHelper
(
null /* this is a virtual item with no backing XML */,
itemName,
itemInclude,
false, /* PERF NOTE: don't waste time creating a new custom metadata cache,
* because we're going to clone the given task item's custom metadata */
null /* no definition library */
);
IDictionary rawSourceTable = taskItem.CloneCustomMetadata();
// Go through and escape the metadata as necessary.
string[] keys = new string[rawSourceTable.Count];
rawSourceTable.Keys.CopyTo(keys, 0);
foreach (string singleMetadataName in keys)
{
string singleMetadataValue = (string) rawSourceTable[singleMetadataName];
rawSourceTable[singleMetadataName] = EscapingUtilities.Escape(singleMetadataValue);
}
this.unevaluatedCustomMetadata = new CopyOnWriteHashtable(rawSourceTable, StringComparer.OrdinalIgnoreCase);
this.evaluatedCustomMetadata = new CopyOnWriteHashtable(rawSourceTable, StringComparer.OrdinalIgnoreCase);
this.isPartOfProjectManifest = false;
}
示例13: GetAttributeArguments
private string GetAttributeArguments(ITaskItem attributeItem, string namedArgumentString)
{
// Some attributes only allow positional constructor arguments, or the user may just prefer them.
// To set those, use metadata names like "_Parameter1", "_Parameter2" etc.
// If a parameter index is skipped, it's an error.
IDictionary customMetadata = attributeItem.CloneCustomMetadata();
// Initialize count + 1 to access starting at 1
List<string> orderedParameters = new List<string>(new string[customMetadata.Count + 1]);
List<string> namedParameters = new List<string>();
foreach (DictionaryEntry entry in customMetadata)
{
string name = (string) entry.Key;
string value = entry.Value is string ? [email protected]"""{entry.Value}""" : entry.Value.ToString();
if (name.StartsWith("_Parameter", StringComparison.OrdinalIgnoreCase))
{
int index;
if (!int.TryParse(name.Substring("_Parameter".Length), out index))
{
Log.LogErrorWithCodeFromResources("General.InvalidValue", name, "WriteCodeFragment");
return null;
}
if (index > orderedParameters.Count || index < 1)
{
Log.LogErrorWithCodeFromResources("WriteCodeFragment.SkippedNumberedParameter", index);
return null;
}
// "_Parameter01" and "_Parameter1" would overwrite each other
orderedParameters[index - 1] = value;
}
else
{
namedParameters.Add($"{name}{namedArgumentString}{value}");
}
}
bool encounteredNull = false;
for (int i = 0; i < orderedParameters.Count; i++)
{
if (orderedParameters[i] == null)
{
// All subsequent args should be null, else a slot was missed
encounteredNull = true;
continue;
}
if (encounteredNull)
{
Log.LogErrorWithCodeFromResources("WriteCodeFragment.SkippedNumberedParameter", i + 1 /* back to 1 based */);
return null;
}
}
return string.Join(", ", orderedParameters.Union(namedParameters).Where(p => !string.IsNullOrWhiteSpace(p)));
}
示例14: GenerateCodeFile
private bool GenerateCodeFile(ITaskItem item)
{
var codeFile = item.ItemSpec;
string[] conditionalConstants;
string className;
string[] classModifiers;
ClassMemberTypes classMemberType;
if (GetConditionalConstants(item, out conditionalConstants) &&
GetClassName(item, out className) &&
GetClassModifiers(item, out classModifiers) &&
GetClassMemberType(item, out classMemberType))
{
if (File.Exists(codeFile) && !ForceOverwrite)
{
Log.LogError("Code file \"{0}\" already exist.", codeFile);
return false;
}
using (var writer = File.CreateText(codeFile))
{
var dict = item.CloneCustomMetadata();
if (conditionalConstants.Length > 0)
writer.WriteLine(string.Format("#if {0}", string.Join(" && ", conditionalConstants)));
if (classModifiers.Length > 0)
writer.Write(string.Format("{0} ", string.Join(" ", classModifiers)));
writer.WriteLine(string.Format("class {0}", className));
writer.WriteLine("{");
foreach (DictionaryEntry e in dict)
{
var name = e.Key.ToString();
if (name.Contains("-")) continue;
WriteMember(writer, classMemberType, name, e.Value.ToString());
}
writer.WriteLine("}");
if (conditionalConstants.Length > 0)
writer.WriteLine("#endif");
}
return true;
}
return false;
}