public void SimpleCopyMetadataTo() { TaskItem from = new TaskItem("myfile.txt"); from.SetMetadata("Culture", "fr"); TaskItem to = new TaskItem("myfile.bin"); from.CopyMetadataTo(to); Assertion.AssertEquals("fr", to.GetMetadata("Culture")); }
private void ProcessInclude(ITaskItem include_item, Dictionary <string, bool> excludedItems, List <ITaskItem> includedItems) { string[] separatedPath; FileInfo[] fileInfo; string name = include_item.ItemSpec; if (!HasWildcard(name)) { if (!excludedItems.ContainsKey(Path.GetFullPath(name))) { includedItems.Add(include_item); } } else { if (name.Split(Path.DirectorySeparatorChar).Length > name.Split(Path.AltDirectorySeparatorChar).Length) { separatedPath = name.Split(new char [] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); } else { separatedPath = name.Split(new char [] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); } if (separatedPath.Length == 1 && separatedPath [0] == String.Empty) { return; } int offset = 0; string full_path; if (Path.IsPathRooted(name)) { // The path may start with a root indicator, but at the same time can // contain relative paths inbetween full_path = Path.GetFullPath(name); baseDirectory = new DirectoryInfo(Path.GetPathRoot(name)); if (IsRunningOnWindows) { // skip the "drive:" offset = 1; } } else { full_path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, name)); } fileInfo = ParseIncludeExclude(separatedPath, offset, baseDirectory); int wildcard_offset = full_path.IndexOf("**"); foreach (FileInfo fi in fileInfo) { string itemName = fi.FullName; if (!Path.IsPathRooted(name) && itemName.Length > baseDirectory.FullName.Length && itemName.StartsWith(baseDirectory.FullName)) { itemName = itemName.Substring(baseDirectory.FullName.Length + 1); } if (!excludedItems.ContainsKey(itemName) && !excludedItems.ContainsKey(Path.GetFullPath(itemName))) { TaskItem item = new TaskItem(include_item); item.ItemSpec = itemName; if (wildcard_offset >= 0) { string rec_dir = Path.GetDirectoryName(fi.FullName.Substring(wildcard_offset)); if (rec_dir.Length > 0) { rec_dir += Path.DirectorySeparatorChar; } item.SetMetadata("RecursiveDir", rec_dir); } includedItems.Add(item); } } } }
public void CreateNullNamedMetadata() { TaskItem item = new TaskItem("foo"); item.SetMetadata(null, "x"); }
public void CreateEmptyNamedMetadata() { TaskItem item = new TaskItem("foo"); item.SetMetadata("", "x"); }
private void ProcessInclude(ITaskItem include_item, Dictionary <string, bool> excludedItems, List <ITaskItem> includedItems) { string[] separatedPath; FileInfo[] fileInfo; string name = include_item.ItemSpec; if (name.IndexOf('?') == -1 && name.IndexOf('*') == -1) { if (!excludedItems.ContainsKey(Path.GetFullPath(name))) { includedItems.Add(include_item); } } else { if (name.Split(Path.DirectorySeparatorChar).Length > name.Split(Path.AltDirectorySeparatorChar).Length) { separatedPath = name.Split(new char [] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); } else { separatedPath = name.Split(new char [] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); } if (separatedPath.Length == 1 && separatedPath [0] == String.Empty) { return; } int offset = 0; if (Path.IsPathRooted(name)) { baseDirectory = new DirectoryInfo(Path.GetPathRoot(name)); if (IsRunningOnWindows) { // skip the "drive:" offset = 1; } } string full_path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, include_item.ItemSpec)); fileInfo = ParseIncludeExclude(separatedPath, offset, baseDirectory); int wildcard_offset = full_path.IndexOf("**"); foreach (FileInfo fi in fileInfo) { if (!excludedItems.ContainsKey(fi.FullName)) { TaskItem item = new TaskItem(include_item); item.ItemSpec = fi.FullName; string rec_dir = Path.GetDirectoryName(fi.FullName.Substring(wildcard_offset)); if (rec_dir.Length > 0) { rec_dir += Path.DirectorySeparatorChar; } item.SetMetadata("RecursiveDir", rec_dir); includedItems.Add(item); } } } }