Hi Damian,
If you are using GeoSerializer, here below is an example how you can customize the GeoSerilizer to exclude certain fields.
var obj = new GridFeatureSource();
obj.PathFilename = "D:\Data\Mosquitos.grd";
obj.Open();
GeoSerializer geoSerializer = new GeoSerializer();
geoSerializer.Formatter = new XmlGeoSerializationFormatter();
var a = geoSerializer.Serialize(obj);
internal class XmlGeoSerializationFormatter : GeoSerializationFormatter
{
/// <summary>
/// Creates an instance of GeoSerializationFormatter.
/// </summary>
public XmlGeoSerializationFormatter()
{ }
/// <summary>
/// Format a GeoObjectModel into XML, and save the XML into a stream.
/// </summary>
/// <param name="model">The GeoObjectModel to create XML for.</param>
/// <param name="stream">The Stream to save XML into.</param>
protected override void SaveCore(GeoObjectModel model, Stream stream)
{
if (model.RootNode.Name == "GridFeatureSource")
{
for (int i = model.RootNode.Children.Count - 1; i >= 0; i--)
{
if (model.RootNode.Children[i] is GeoObjectNode)
{
var objectNode = (GeoObjectNode)model.RootNode.Children[i];
if (objectNode.Name == "gridValuesString")
{
model.RootNode.Children.RemoveAt(i);
break;
}
}
}
}
StreamWriter sw = new StreamWriter(stream, Encoding);
using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true }))
{
Save(model.RootNode, xmlWriter);
}
}
......
}
The complete class XmlGeoSerializationFormatter is attached below.
XmlGeoSerializationFormatter.txt (5.2 KB)
You can also try the Newtonsoft Json one if you want. It only serialize the public properties, it might / might not fit your case better.
Thanks,
Ben