public static void Write(IGISAttributes attributes, JsonTextWriter jwriter, string[] nonSerializedFields) { if (attributes == null) { return; } if (jwriter == null) { throw new ArgumentNullException("jwriter", "A valid JSON writer object is required."); } jwriter.WriteStartObject(); IEnumerable <string> names = attributes.GetKeys(); foreach (string name in names) { if (nonSerializedFields != null && Contains(nonSerializedFields, name)) { continue; } jwriter.WriteMember(name); jwriter.WriteString(attributes.GetValue(name).ToString()); } jwriter.WriteEndObject(); }
public static void Write(IGISAttributes attributes, XmlWriter xwriter) { if (attributes == null) { throw new ArgumentNullException("attributes"); } if (xwriter == null) { throw new ArgumentNullException("xwriter"); } xwriter.WriteStartElement("Attributes"); IEnumerable <string> names = attributes.GetKeys(); foreach (string name in names) { xwriter.WriteStartElement("item"); //write the key xwriter.WriteElementString("key", name); //write the qualified type name of the value //write the value object value = attributes.GetValue(name); if (value == null) { xwriter.WriteElementString("type", null); xwriter.WriteElementString("value", null); } else { TypeConverter typeConverter = TypeDescriptor.GetConverter(value.GetType()); xwriter.WriteElementString("type", value.GetType().AssemblyQualifiedName); xwriter.WriteElementString("value", typeConverter.ConvertToString(value)); } xwriter.WriteEndElement(); } xwriter.WriteEndElement(); }
public static void Write(IGISAttributes attributes, JsonTextWriter jwriter, string[] nonSerializedFields) { if (attributes == null) return; if (jwriter == null) throw new ArgumentNullException("jwriter", "A valid JSON writer object is required."); jwriter.WriteStartObject(); IEnumerable<string> names = attributes.GetKeys(); foreach (string name in names) { if (nonSerializedFields != null && Contains(nonSerializedFields, name)) continue; jwriter.WriteMember(name); jwriter.WriteString(attributes.GetValue(name).ToString()); } jwriter.WriteEndObject(); }