Microsoft.VisualStudio.Project.ProjectElement.GetMetadata C# (CSharp) Method

GetMetadata() public method

Get the value of an attribute on a project element
public GetMetadata ( string attributeName ) : string
attributeName string Name of the attribute to get the value for
return string
        public string GetMetadata(string attributeName)
        {
            if (attributeName == null)
                throw new ArgumentNullException("attributeName");
            if (string.IsNullOrEmpty(attributeName))
                throw new ArgumentException("attributeName cannot be null or empty");
            if (HasItemBeenDeleted)
                throw new InvalidOperationException("The item has been deleted.");

            if(this.IsVirtual)
            {
                // For virtual items, use our virtual property collection
                if(!virtualProperties.ContainsKey(attributeName))
                    return String.Empty;

                return ProjectCollection.Unescape(virtualProperties[attributeName]);
            }

            // cannot ask MSBuild for Include, so intercept it and return the corresponding property
            if(String.Equals(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase))
                return Item.EvaluatedInclude;

            // Build Action is the type, not a property, so intercept this one as well
            if(String.Equals(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase))
                return Item.ItemType;

            return Item.GetMetadataValue(attributeName);
        }

Usage Example

Esempio n. 1
0
        public int get_CanonicalName(out string pbstrCanonicalName)
        {
            // Get the output assembly path (including the name)
            pbstrCanonicalName = output.GetMetadata(ProjectFileConstants.Include);
            Debug.Assert(!String.IsNullOrEmpty(pbstrCanonicalName), "Output Assembly not defined");

            // Make sure we have a full path
            if (!System.IO.Path.IsPathRooted(pbstrCanonicalName))
            {
                pbstrCanonicalName = new Url(project.BaseURI, pbstrCanonicalName).AbsoluteUrl;
            }
            return(VSConstants.S_OK);
        }
All Usage Examples Of Microsoft.VisualStudio.Project.ProjectElement::GetMetadata