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