public override object Convert(IParserType text) { var parserValue = text as ParserValue; if (parserValue == null) { return(InvalidValue); } return(parserValue.Value); }
public bool RemoveChild(IParserType parserType) { foreach (var keyValue in _hashTable) { if (keyValue.Value == parserType) { _hashTable.Remove(keyValue.Key); return(true); } } return(false); }
public override object Convert(IParserType text) { var parserValue = text as ParserValue; if (parserValue == null) { return(InvalidValue); } try { var floatValue = float.Parse(parserValue.Value); return(floatValue); } catch { return(InvalidValue); } }
public IParserType Parse() { context = new ParserObject(); foreach (var filePath in filePaths) { var text = File.ReadAllText(filePath); foreach (var ch in text) { if (ch == '\t' || ch == '\r') { ; // Do nothing } else { context = context.HandleCharacter(ch); } } } return(context); }
public override object Convert(IParserType type) { var parserObject = type as ParserObject; var parserArray = type as ParserArray; float x = 0f, y = 0f; if (parserObject != null) { if (!(parserObject.HashTable.ContainsKey("x") || parserObject.HashTable.ContainsKey("y"))) { Debug.Log("x or y could not be found in Vector2 object!"); return(InvalidValue); } var xVal = parserObject.HashTable["x"]; var yVal = parserObject.HashTable["y"]; if (!(xVal is ParserValue && yVal is ParserValue)) { Debug.Log("x or y aren't values!"); return(InvalidValue); } var xStr = (xVal as ParserValue).Value; var yStr = (yVal as ParserValue).Value; if (!(float.TryParse(xStr, out x) || float.TryParse(yStr, out y))) { Debug.Log("x or y could not be read as a number!"); return(InvalidValue); } } else if (parserArray != null) { var values = parserArray.Values; if (values.Length < 2) { Debug.Log("Vector2 array has less than 2 children!"); return(InvalidValue); } var xVal = values[0]; var yVal = values[1]; if (!(xVal is ParserValue && yVal is ParserValue)) { Debug.Log("Vector2 array children are not values!"); return(InvalidValue); } var xStr = (xVal as ParserValue).Value; var yStr = (yVal as ParserValue).Value; if (!(float.TryParse(xStr, out x) && float.TryParse(yStr, out y))) { Debug.Log("Vector2 array values could not be read as numbers!"); return(InvalidValue); } } else { return(InvalidValue); } return(new Vector2(x, y)); }
public bool RemoveChild(IParserType parserType) { return(_types.Remove(parserType)); }
public bool AddChild(string key, IParserType parserType) { _types.Add(parserType); return(true); }
public bool AddChild(string key, IParserType parserType) { _hashTable[key] = parserType; return(true); }
public abstract object Convert(IParserType type);