/* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Apache License, Version 2.0. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Apache License, Version 2.0, please send an email to * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Apache License, Version 2.0. * * You must not remove this notice, or any other, from this software. * * ***************************************************************************/ using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; namespace Microsoft.VisualStudio.Project { class VirtualProjectElement : ProjectElement { private readonly Dictionary _virtualProperties; /// /// Constructor to Wrap an existing MSBuild.ProjectItem /// Only have public constructors as the only one who should be creating /// such object is the project itself (see Project.CreateFileNode()). /// /// Project that owns this item /// an MSBuild.ProjectItem; can be null if virtualFolder is true /// Is this item virtual (such as reference folder) public VirtualProjectElement(ProjectNode project) : base(project) { _virtualProperties = new Dictionary(); } protected override string ItemType { get { return ""; } set { } } /// /// Set an attribute on the project element /// /// Name of the attribute to set /// Value to give to the attribute public override void SetMetadata(string attributeName, string attributeValue) { Debug.Assert(String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) != 0, "Use rename as this won't work"); // For virtual node, use our virtual property collection _virtualProperties[attributeName] = attributeValue; } /// /// Get the value of an attribute on a project element /// /// Name of the attribute to get the value for /// Value of the attribute public override string GetMetadata(string attributeName) { // For virtual items, use our virtual property collection if (!_virtualProperties.ContainsKey(attributeName)) { return String.Empty; } return _virtualProperties[attributeName]; } public override void Rename(string newPath) { _virtualProperties[ProjectFileConstants.Include] = newPath; } public override bool Equals(object obj) { return Object.ReferenceEquals(this, obj); } public override int GetHashCode() { return RuntimeHelpers.GetHashCode(this); } public override string EvaluatedInclude { get { return null; } } } }