private ProjectImageMoniker ReadProjectImageMoniker() { Tokenizer tokenizer = Tokenizer(Delimiters.BracedPropertyValue); string guidAsString = tokenizer.ReadIdentifier(IdentifierParseOptions.Required); if (!Guid.TryParseExact(guidAsString, "D", out Guid guid)) { throw _tokenizer.FormatException(ProjectTreeFormatError.GuidExpected, $"Expected GUID, but encountered '{guidAsString}'"); } tokenizer.Skip(TokenType.WhiteSpace); string idAsString = tokenizer.ReadIdentifier(IdentifierParseOptions.Required); if (!int.TryParse(idAsString, out int id)) { throw _tokenizer.FormatException(ProjectTreeFormatError.IntegerExpected, $"Expected integer, but encountered '{idAsString}'"); } return(new ProjectImageMoniker(guid, id)); }
private void ReadVisibility(MutableProjectItemTree tree) { // Parse 'visible' in 'visibility:visible' or 'invisible' in 'visibility:invisible" Tokenizer tokenizer = Tokenizer(Delimiters.PropertyValue); string visibility = tokenizer.ReadIdentifier(IdentifierParseOptions.Required); tree.Visible = visibility switch { "visible" => true, "invisible" => false, _ => throw FormatException(ProjectTreeFormatError.UnrecognizedPropertyValue, $"Expected 'visible' or 'invisible', but encountered '{visibility}'."), }; }
private void ReadFields(MutableProjectTree tree) { // Parses ', FilePath: "C:\Temp\Foo"' // This section is optional while (_tokenizer.SkipIf(TokenType.Comma)) { _tokenizer.Skip(TokenType.WhiteSpace); Tokenizer tokenizer = Tokenizer(Delimiters.PropertyName); string fieldName = tokenizer.ReadIdentifier(IdentifierParseOptions.Required); switch (fieldName) { case "FilePath": tokenizer.Skip(TokenType.Colon); tokenizer.Skip(TokenType.WhiteSpace); ReadFilePath(tree); break; case "Icon": tokenizer.Skip(TokenType.Colon); tokenizer.Skip(TokenType.WhiteSpace); ReadIcon(tree, expandedIcon: false); break; case "ExpandedIcon": tokenizer.Skip(TokenType.Colon); tokenizer.Skip(TokenType.WhiteSpace); ReadIcon(tree, expandedIcon: true); break; case "DisplayOrder": tokenizer.Skip(TokenType.Colon); tokenizer.Skip(TokenType.WhiteSpace); ReadDisplayOrder(tree); break; case "ItemName": tokenizer.Skip(TokenType.Colon); tokenizer.Skip(TokenType.WhiteSpace); ReadItemName(tree); break; default: throw _tokenizer.FormatException(ProjectTreeFormatError.UnrecognizedPropertyName, $"Expected 'FilePath', 'Icon' or 'ExpandedIcon', but encountered '{fieldName}'."); } } }
private void ReadVisibility(MutableProjectTree tree) { // Parse 'visible' in 'visibility:visible' or 'invisible' in 'visibility:invisible" Tokenizer tokenizer = Tokenizer(Delimiters.PropertyValue); string visibility = tokenizer.ReadIdentifier(IdentifierParseOptions.Required); switch (visibility) { case "visible": tree.Visible = true; break; case "invisible": tree.Visible = false; break; default: throw _tokenizer.FormatException(ProjectTreeFormatError.UnrecognizedPropertyValue, $"Expected 'visible' or 'invisible', but encountered '{visibility}'."); } }
private void ReadProperty(MutableProjectTree tree) { Tokenizer tokenizer = Tokenizer(Delimiters.PropertyName); string propertyName = tokenizer.ReadIdentifier(IdentifierParseOptions.Required); switch (propertyName) { case "visibility": tokenizer.Skip(TokenType.Colon); tokenizer.Skip(TokenType.WhiteSpace); ReadVisibility(tree); break; case "flags": tokenizer.Skip(TokenType.Colon); tokenizer.Skip(TokenType.WhiteSpace); ReadCapabilities(tree); break; default: throw _tokenizer.FormatException(ProjectTreeFormatError.UnrecognizedPropertyName, $"Expected 'visibility' or 'flags', but encountered '{propertyName}'."); } }
private void ReadCaption(MutableProjectTree tree) { Tokenizer tokenizer = Tokenizer(Delimiters.Caption); tree.Caption = tokenizer.ReadIdentifier(IdentifierParseOptions.Required); }
private string ReadPropertyValue() { Tokenizer tokenizer = Tokenizer(Delimiters.PropertyValue); return(tokenizer.ReadIdentifier(IdentifierParseOptions.None)); }