/// <summary> /// Gets a lowercase noun decribing the element. Intended to be localized and substituted into localized strings. /// </summary> public static string GetKindNoun(this ValueInfo info) => info switch {
public static MSBuildValueKind InferValueKindIfUnknown(this ValueInfo variable) { if (variable.ValueKind != MSBuildValueKind.Unknown) { return(variable.ValueKind); } if (variable is MSBuildAttributeSyntax att) { switch (att.Name) { case "Include": case "Exclude": case "Remove": case "Update": return(MSBuildValueKind.File.List()); } } //assume known items are files if (variable.ValueKind == MSBuildValueKind.UnknownItem) { return(MSBuildValueKind.File); } if (variable.ValueKind == MSBuildValueKind.UnknownItem.List()) { return(MSBuildValueKind.File.List()); } bool isProperty = variable is PropertyInfo; if (isProperty || variable is MetadataInfo) { if (StartsWith("Enable") || StartsWith("Disable") || StartsWith("Require") || StartsWith("Use") || StartsWith("Allow") || EndsWith("Enabled") || EndsWith("Disabled") || EndsWith("Required")) { return(MSBuildValueKind.Bool); } if (EndsWith("DependsOn")) { return(MSBuildValueKind.TargetName.List()); } if (EndsWith("Path")) { return(MSBuildValueKind.FileOrFolder); } if (EndsWith("Paths")) { return(MSBuildValueKind.FileOrFolder.List()); } if (EndsWith("Directory") || EndsWith("Dir")) { return(MSBuildValueKind.Folder); } if (EndsWith("File")) { return(MSBuildValueKind.File); } if (EndsWith("FileName")) { return(MSBuildValueKind.Filename); } if (EndsWith("Url")) { return(MSBuildValueKind.Url); } if (EndsWith("Ext")) { return(MSBuildValueKind.Extension); } if (EndsWith("Guid")) { return(MSBuildValueKind.Guid); } if (EndsWith("Directories") || EndsWith("Dirs")) { return(MSBuildValueKind.Folder.List()); } if (EndsWith("Files")) { return(MSBuildValueKind.File.List()); } } //make sure these work even if the common targets schema isn't loaded if (isProperty) { switch (variable.Name.ToLowerInvariant()) { case "configuration": return(MSBuildValueKind.Configuration); case "platform": return(MSBuildValueKind.Platform); } } return(MSBuildValueKind.Unknown); bool StartsWith(string prefix) => variable.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) && variable.Name.Length > prefix.Length && char.IsUpper(variable.Name[prefix.Length]); bool EndsWith(string suffix) => variable.Name.EndsWith(suffix, StringComparison.OrdinalIgnoreCase); }