private bool Verify(TagNode parent, TagNode tag, SchemaNode schema) { if (tag == null) { return(OnMissingTag(new TagEventArgs(schema.Name))); } SchemaNodeScaler scaler = schema as SchemaNodeScaler; if (scaler != null) { return(VerifyScaler(tag, scaler)); } SchemaNodeString str = schema as SchemaNodeString; if (str != null) { return(VerifyString(tag, str)); } SchemaNodeArray array = schema as SchemaNodeArray; if (array != null) { return(VerifyArray(tag, array)); } SchemaNodeIntArray intarray = schema as SchemaNodeIntArray; if (intarray != null) { return(VerifyIntArray(tag, intarray)); } SchemaNodeShortArray shortarray = schema as SchemaNodeShortArray; if (shortarray != null) { return(VerifyShortArray(tag, shortarray)); } SchemaNodeList list = schema as SchemaNodeList; if (list != null) { return(VerifyList(tag, list)); } SchemaNodeCompound compound = schema as SchemaNodeCompound; if (compound != null) { return(VerifyCompound(tag, compound)); } return(OnInvalidTagType(new TagEventArgs(schema.Name, tag))); }
/// <summary> /// Copies all the elements of this <see cref="SchemaNodeCompound"/> into <paramref name="tree"/>. /// </summary> /// <param name="tree">The destination <see cref="SchemaNodeCompound"/> to copy <see cref="SchemaNode"/> elements into.</param> /// <returns>A reference to <paramref name="tree"/>.</returns> public SchemaNodeCompound MergeInto(SchemaNodeCompound tree) { foreach (var node in _subnodes) { var f = tree._subnodes.Find(n => n.Name == node.Name); if (f != null) { continue; } tree.Add(node); } return(tree); }
private bool VerifyCompound(TagNode tag, SchemaNodeCompound schema) { TagNodeCompound ctag = tag as TagNodeCompound; if (ctag == null) { if (!OnInvalidTagType(new TagEventArgs(schema, tag))) { return(false); } } bool pass = true; Dictionary <string, TagNode> _scratch = new Dictionary <string, TagNode>(); foreach (SchemaNode node in schema) { TagNode value; ctag.TryGetValue(node.Name, out value); if (value == null) { if ((node.Options & SchemaOptions.CREATE_ON_MISSING) == SchemaOptions.CREATE_ON_MISSING) { _scratch[node.Name] = node.BuildDefaultTree(); continue; } else if ((node.Options & SchemaOptions.OPTIONAL) == SchemaOptions.OPTIONAL) { continue; } } pass = Verify(tag, value, node) && pass; } foreach (KeyValuePair <string, TagNode> item in _scratch) { ctag[item.Key] = item.Value; } _scratch.Clear(); return(pass); }
/// <summary> /// Constructs a new <see cref="SchemaNodeCompound"/> with additional options. /// </summary> /// <param name="name">The name of the corresponding <see cref="TagNodeCompound"/>.</param> /// <param name="subschema">A <see cref="SchemaNodeCompound"/> representing a schema to verify against the corresponding <see cref="TagNodeCompound"/>.</param> /// <param name="options">One or more option flags modifying the processing of this node.</param> public SchemaNodeCompound(string name, SchemaNode subschema, SchemaOptions options) : base(name, options) { _subnodes = new List <SchemaNode>(); SchemaNodeCompound schema = subschema as SchemaNodeCompound; if (schema == null) { return; } foreach (SchemaNode node in schema._subnodes) { _subnodes.Add(node); } }