public void CamlTag_CreatesTagWithAttributes() { Expected = "<Tag Attr='a1' Xy='zz' />"; var tag = new CamlTag("Tag"); tag.MergeAttribute("Attr", "a1"); tag.MergeAttribute("Xy", "zz"); var caml = tag.ToString(); Assert.That(caml, Is.EqualTo(Expected)); }
/// <summary> /// Used internaly to get CAML markup from elements. /// </summary> public virtual string GetCaml() { var tag = new CamlTag(Tag.ToString()); var properties = GetType().GetProperties(); foreach (var property in properties) { var attribute = (CQAttributeAttribute)property.GetCustomAttributes(typeof(CQAttributeAttribute), true).FirstOrDefault(); if (attribute == null) continue; var name = attribute.Name ?? property.Name; tag.MergeAttribute(name, property.GetValue(this, null)); } if (_elements.Count != 0) { var builder = new StringBuilder(); foreach (var element in _elements) { builder.Append(element.GetCaml()); } tag.InnerText = builder.ToString(); } else { tag.InnerText = InnerText; } return tag.ToString(); }