public IAssignment HandleCharacter(char c, IParseObject obj) { // Handle comments. if (Utils.IsComment(c)) { return(new CommentAssignment(this)); } // If the character is an ignored character, the assignment is complete and it is time for a new name. if (Utils.IsNewline(c)) { return(new NameAssignment()); } // If the character is a brace, we need to switch to a brace assignment. if (c == '{') { return(new BraceAssignment()); } // If the character is a quote mark, we need to switch to a quote assignment. if (c == '\"') { return(new QuoteAssignment()); } // Otherwise we can pass along the character and keep the assignment. obj.TakeCharacter(c); return(this); }
public IAssignment HandleCharacter(char c, IParseObject obj) { // Check for comments. if (Utils.IsComment(c)) { return(new CommentAssignment(this)); } // If the character is an opening brace, we need increase the indentation and let the object handle the character. if (c == '{') { _indentation++; obj.TakeCharacter(c); return(this); } // If the character is a closing brace, we need to decrease the indentation and either switch assignments // or handle the character. if (c == '}') { // If the level of indentation is 0, we are done. if (_indentation == 0) { return(new NameAssignment()); } // Otherwise the level of indentation is decreased and the character is handled. _indentation--; obj.TakeCharacter(c); return(this); } obj.TakeCharacter(c); return(this); }
/// <summary> /// Resolves changes in assignment methods. /// </summary> /// <param name="old">The current assignment method.</param> /// <param name="newA">The assignment method that may be used in the future.</param> protected void HandleAssignmentChange(IAssignment old, IAssignment newA) { // Don't do anything when the assignments are equal. var areEqual = old.GetType().Equals(newA.GetType()); if (areEqual) { return; } // Assign the new assignment method. Assignment = newA; // If the new assignment is a name assignment, a new name object should be assigned. if (newA is NameAssignment) { Object = new NameObject(); return; } // If the assignment method switches from the name object, there should be a new object to write to. if (old is NameAssignment && !(newA is NameAssignment)) { var nameObject = Object as NameObject; var name = nameObject?.Name?.Trim() ?? ""; if (name.Length > 0) { CreateObject(name); } } }
public BaseParseObject(Type childType) { Children = new DynamicObjectList <T>(); Assignment = new NameAssignment(); Object = new NameObject(); _propertyMap = CreatePropertyMap(childType); }
public IAssignment HandleCharacter(char c, IParseObject obj) { // If the character is a ", the value has been written completely. if (c == '\"') { return(new NameAssignment()); } // Otherwise just pass along the value and reuse this assignment. obj.TakeCharacter(c); return(this); }
/// <summary> /// Creates an object for the specified name. The specific type of object that is created depends on whether the /// name has been specified in the derived class' properties. /// </summary> /// <param name="name">The name of the created object.</param> protected void CreateObject(string name) { // Check if there is a property with that name. var property = GetNamedProperty(name); // If the property was not registered, we need to create a dynamic object. if (property == null) { Object = Children.CreateObject(name); return; } // Create and assign the property. Object = Activator.CreateInstance(property.PropertyType) as IParseObject; property.SetValue(this, Object); }
public IAssignment HandleCharacter(char c, IParseObject obj) { // Handle all characters other than newline with the current comment. if (!Utils.IsNewline(c)) { return(this); } // If the previous assignment is a brace, quote or value, include the enter. if (_prev is BraceAssignment || _prev is QuoteAssignment || _prev is ValueAssignment) { obj.TakeCharacter(c); return(_prev); } // Otherwise we will write a new value and need to use a name assignment. return(new NameAssignment()); }
public IAssignment HandleCharacter(char c, IParseObject obj) { // Handle comments. if (Utils.IsComment(c)) { return(new CommentAssignment(this)); } // If the character is ignored, don't pass it along and keep reusing this assignment. if (Utils.IsSpace(c) || Utils.IsNewline(c)) { return(this); } // If the character is the assignment character, then return the value assignment method. if (c == '=') { return(new ValueAssignment()); } // Otherwise, pass along the character and keep reusing this assignment. obj.TakeCharacter(c); return(this); }
public void Update(IParseObject o, Action <Response <DateTime> > callback) { Update(o.Id, o, callback); }
public void Update(IParseObject o) { Update(o, null); }