diff options
Diffstat (limited to 'mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItem.cs')
-rw-r--r-- | mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItem.cs | 201 |
1 files changed, 120 insertions, 81 deletions
diff --git a/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItem.cs b/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItem.cs index 393995e80c..cc187f9b94 100644 --- a/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItem.cs +++ b/mcs/class/Microsoft.Build/Microsoft.Build.Evaluation/ProjectItem.cs @@ -4,9 +4,10 @@ // Author: // Leszek Ciesielski (skolima@gmail.com) // Rolf Bjarne Kvinge (rolf@xamarin.com) +// Atsushi Enomoto (atsushi@xamarin.com) // // (C) 2011 Leszek Ciesielski -// Copyright (C) 2011 Xamarin Inc. +// Copyright (C) 2011,2013 Xamarin Inc. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -31,88 +32,126 @@ using System; using System.Collections.Generic; using System.Diagnostics; - +using System.Linq; using Microsoft.Build.Construction; +using System.IO; +using Microsoft.Build.Framework; namespace Microsoft.Build.Evaluation { - [DebuggerDisplay("{ItemType}={EvaluatedInclude} [{UnevaluatedInclude}] #DirectMetadata={DirectMetadataCount}")] - public class ProjectItem - { - internal ProjectItem (ProjectItemElement xml) - { - Xml = xml; - } - - public ProjectMetadata GetMetadata (string name) - { - throw new NotImplementedException (); - } - - public string GetMetadataValue (string name) - { - throw new NotImplementedException (); - } - - public bool HasMetadata (string name) - { - throw new NotImplementedException (); - } - - public bool RemoveMetadata (string name) - { - throw new NotImplementedException (); - } - - public void Rename (string name) - { - throw new NotImplementedException (); - } - - public void SetMetadataValue (string name, string unevaluatedValue) - { - throw new NotImplementedException (); - } - - public IEnumerable<ProjectMetadata> DirectMetadata { - get { throw new NotImplementedException (); } - } - - public int DirectMetadataCount { - get { throw new NotImplementedException (); } - } - - public string EvaluatedInclude { - get { throw new NotImplementedException (); } - } - - public bool IsImported { - get { throw new NotImplementedException (); } - } - - public string ItemType { - get { throw new NotImplementedException (); } - set { throw new NotImplementedException (); } - } - - public ICollection<ProjectMetadata> Metadata { - get { throw new NotImplementedException (); } - } - - public int MetadataCount { - get { throw new NotImplementedException (); } - } - - public Project Project { - get { throw new NotImplementedException (); } - } - - public string UnevaluatedInclude { - get { throw new NotImplementedException (); } - set { throw new NotImplementedException (); } - } - - public ProjectItemElement Xml { get; private set; } - - } + [DebuggerDisplay ("{ItemType}={EvaluatedInclude} [{UnevaluatedInclude}] #DirectMetadata={DirectMetadataCount}")] + public class ProjectItem + { + internal ProjectItem (Project project, ProjectItemElement xml, string evaluatedInclude) + { + this.project = project; + this.xml = xml; + if (project.ItemDefinitions.ContainsKey (ItemType)) + foreach (var md in project.ItemDefinitions [ItemType].Metadata) + metadata.Add (md); + foreach (var md in xml.Metadata) + metadata.Add (new ProjectMetadata (project, ItemType, metadata, m => metadata.Remove (m), md)); + this.evaluated_include = evaluatedInclude; + is_imported = project.ProjectCollection.OngoingImports.Any (); + } + + readonly Project project; + readonly ProjectItemElement xml; + readonly List<ProjectMetadata> metadata = new List<ProjectMetadata> (); + readonly bool is_imported; + readonly string evaluated_include; + + internal string RecursiveDir { get; set; } + + public ProjectMetadata GetMetadata (string name) + { + return metadata.FirstOrDefault (m => m.Name == name); + } + + public string GetMetadataValue (string name) + { + if (name == null) + throw new ArgumentNullException ("name"); + var wk = ProjectCollection.GetWellKnownMetadata (name, EvaluatedInclude, project.GetFullPath, RecursiveDir); + if (wk != null) + return wk; + var m = GetMetadata (name); + return m != null ? m.EvaluatedValue : string.Empty; + } + + public bool HasMetadata (string name) + { + return GetMetadata (name) != null; + } + + public bool RemoveMetadata (string name) + { + var m = GetMetadata (name); + if (m == null) + return false; + return metadata.Remove (m); + } + + public void Rename (string name) + { + throw new NotImplementedException (); + } + + public ProjectMetadata SetMetadataValue (string name, string unevaluatedValue) + { + // This has to do several tasks: + // - it cannot directly change Xml.Metadata because the ProjectItemElement might be shared + // among multiple ProjectItems. + // - hence it has to create another ProjectItemElement instance and add it to the project + // XML construction, with specific Include value that is assigned to this instance, and + // metadata values that are assigned to this instance. + throw new NotImplementedException (); + } + + public IEnumerable<ProjectMetadata> DirectMetadata { + get { + var list = new List<ProjectMetadata> (); + foreach (var xm in xml.Metadata) + yield return new ProjectMetadata (project, ItemType, list, p => list.Remove (p), xm); + } + } + + public int DirectMetadataCount { + get { return xml.Metadata.Count; } + } + + public string EvaluatedInclude { + get { return evaluated_include; } + } + + public bool IsImported { + get { return is_imported; } + } + + public string ItemType { + get { return Xml.ItemType; } + set { Xml.ItemType = value; } + } + + public ICollection<ProjectMetadata> Metadata { + get { return metadata; } + } + + public int MetadataCount { + get { return metadata.Count; } + } + + public Project Project { + get { return project; } + } + + public string UnevaluatedInclude { + get { return Xml.Include; } + set { Xml.Include = value; } + } + + public ProjectItemElement Xml { + get { return xml; } + } + } } |