/// <summary> /// Reads a <see cref="TokenElement"/> and creates a <see cref="PropertyReader"/> /// </summary> /// <param name="tokenElement">The tokenElement configuration element</param> /// <returns>A <see cref="PropertyReader"/></returns> private PropertyReader ReadConfigToken(TokenElement tokenElement) { bool formatConfigured = !string.IsNullOrEmpty(tokenElement.Format); bool typeConfigured = !string.IsNullOrEmpty(tokenElement.TypeName); bool dataPropertyConfigured = IsDataPropertyConfigured(tokenElement); if ((formatConfigured && typeConfigured) || (formatConfigured && dataPropertyConfigured) || (typeConfigured && dataPropertyConfigured)) { throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, Resources.TokenElementIncorrect, tokenElement.Name)); } if (formatConfigured) { return(_combinedFactory.Create(tokenElement.Format, this)); } if (dataPropertyConfigured) { return(Create(tokenElement.DataProperty)); } Type type = Type.GetType(tokenElement.TypeName, true); return((PropertyReader)Activator.CreateInstance(type)); }
public TokenElement ParseToken() { ParseToken("token"); string name = ParseName(); TokenElement token = new TokenElement(name); ParseToken("="); for (Token tk = this.PeekToken(); tk != null && tk.Value != ";"; tk = this.PeekToken()) { switch (tk.TokenType) { case TokenType.Name: token.AddPrimaryExpression(this.ParseIdentifier()); break; case TokenType.String: token.AddPrimaryExpression(this.ParseTextLiteral()); break; default: throw new UnexpectedTokenException(tk); } } ParseToken(";"); return(token); }
public bool Equals(TokenElement other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.Token, Token); }
public bool Equals(TokenElement other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.Token, Token)); }
public void ShouldParseTokenWithTwoTextLiterals() { Parser parser = new Parser("token Main = \"Hello\" \"World\";"); TokenElement token = parser.ParseToken(); Assert.IsNotNull(token); Assert.AreEqual("Main", token.Name); Assert.AreEqual(2, token.Expressions.Count); foreach (PrimaryExpression expression in token.Expressions) { Assert.IsInstanceOfType(expression, typeof(TextLiteral)); } }
public void ShouldParseTokenWithTwoIdentifiers() { Parser parser = new Parser("token Main = Hello World;"); TokenElement token = parser.ParseToken(); Assert.IsNotNull(token); Assert.AreEqual("Main", token.Name); Assert.AreEqual(2, token.Expressions.Count); foreach (PrimaryExpression expression in token.Expressions) { Assert.IsInstanceOfType(expression, typeof(Identifier)); } }
public void ShouldParseTokenWithOneIdentifier() { Parser parser = new Parser("token Main = Hello;"); TokenElement token = parser.ParseToken(); Assert.IsNotNull(token); Assert.AreEqual("Main", token.Name); Assert.AreEqual(1, token.Expressions.Count); Assert.IsInstanceOfType(token.Expressions.First(), typeof(Identifier)); Identifier identifier = (Identifier)token.Expressions.First(); Assert.AreEqual("Hello", identifier.Name); }
public void ShouldParseTokenWithOneTextLiteral() { Parser parser = new Parser("token Main = \"Hello\";"); TokenElement token = parser.ParseToken(); Assert.IsNotNull(token); Assert.AreEqual("Main", token.Name); Assert.AreEqual(1, token.Expressions.Count); Assert.IsInstanceOfType(token.Expressions.First(), typeof(TextLiteral)); TextLiteral literal = (TextLiteral)token.Expressions.First(); Assert.AreEqual("Hello", literal.Value); }
private void LoadConfiguredTokens() { // We need to load the tokens from configuration the first time this is accessed. UkadcDiagnosticsSection section; if (UkadcDiagnosticsSection.TryReadConfigSection(out section)) { if (section.Tokens != null) { for (int i = 0; i < section.Tokens.Count; i++) { TokenElement token = section.Tokens[i]; AddToken(token.Name, ReadConfigToken(token)); } } } }