private void OutputAtts(XmlNode natts) { for (int i = 0; i < atts.Length; ++i) { var t = atts[i].GetType(); if (MustSkipAttrType(t)) { continue; } XmlNode node = document.CreateElement("attribute"); AddAttribute(node, "name", t.ToString()); XmlNode properties = null; foreach (var pi in TypeData.GetProperties(t)) { if (pi.Name == "TypeId") { continue; } if (properties == null) { properties = node.AppendChild(document.CreateElement("properties")); } try { var o = pi.GetValue(atts[i], null); var n = properties.AppendChild(document.CreateElement("property")); AddAttribute(n, "name", pi.Name); if (o == null) { AddAttribute(n, "null", "true"); continue; } string value = o.ToString(); if (t == typeof(GuidAttribute)) { value = value.ToUpper(); } AddAttribute(n, "value", value); } catch (TargetInvocationException) { continue; } } natts.AppendChild(node); } }
public override void DoOutput() { if (document == null) { throw new InvalidOperationException("Document not set"); } if (atts == null || atts.Length == 0) { return; } XmlNode natts = parent.SelectSingleNode("attributes"); if (natts == null) { natts = document.CreateElement("attributes", null); parent.AppendChild(natts); } for (int i = 0; i < atts.Length; ++i) { Type t = atts [i].GetType(); if (!t.IsPublic && !t.Name.EndsWith("TODOAttribute")) { continue; } // we ignore attributes that inherit from SecurityAttribute on purpose as they: // * aren't part of GetCustomAttributes in Fx 1.0/1.1; // * are encoded differently and in a different metadata table; and // * won't ever exactly match MS implementation (from a syntax pov) if (t.IsSubclassOf(typeof(SecurityAttribute))) { continue; } XmlNode node = document.CreateElement("attribute"); AddAttribute(node, "name", t.ToString()); XmlNode properties = null; foreach (PropertyInfo pi in TypeData.GetProperties(t)) { if (pi.Name == "TypeId") { continue; } if (properties == null) { properties = node.AppendChild(document.CreateElement("properties")); } try { object o = pi.GetValue(atts [i], null); XmlNode n = properties.AppendChild(document.CreateElement("property")); AddAttribute(n, "name", pi.Name); if (o == null) { AddAttribute(n, "null", "true"); continue; } string value = o.ToString(); if (t == typeof(GuidAttribute)) { value = value.ToUpper(); } AddAttribute(n, "value", value); } catch (TargetInvocationException) { continue; } } natts.AppendChild(node); } }