This project is read-only.

an issue with exclusion of certain Properties

Aug 2, 2011 at 11:35 PM


It's a real gift to be able to use this tool, and study your code !

I have been experimenting with serializing to XML with a few classes that include properties within the WinForms library.

I've found the following will serialize, but will not de-serialize: Cursor, Icon, Font, and IWindowTarget.

In trying to exclude these types from serialization, I used:

serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(Cursor), "Cursor");

serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(Icon), "Icon");

serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(Font), "Font");

serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(System.Windows.Forms.IWindowTarget), "WindowTarget");

But, they are still written out into the XML file.

In order to "work around" encountering these types in de-serializing, I added the following to the start of the SerializeCore method in SerializeProperty.cs:

if (property.Name == "Cursor") return;

if (property.Name == "Icon") return;

if (property.Name == "Font") return;

if (property.Name == "WindowTarget") return;

And, that does allow me to successfully de-serialize most of the other WinForms properties.

Just curious if there is any other way to exclude such types.

By the way, I was able to serialize a static dictionary<string, System.Windows.Forms.Control> filled with KeyValue Pairs inside a Public Class that did have a Constructor with a parameter.

Many thanks for your generosity in creating this tool, and supporting it.

best, Bill

Aug 3, 2011 at 9:04 PM
Edited Aug 14, 2011 at 12:30 PM

hi Bill, thanks!

Afaik your samples (Cursor, Icon, Font, and IWindowTarget) do not have the standard constructor and therefore they cannot be deserialized.

If you want to exclude them from the serialization from a build in .NET class you can use syntax with PropertiesToIgnore just as you use it with a following difference

serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(Cursor), "Cursor");

should be:
serializer.PropertyProvider.PropertiesToIgnore.Add(typeof(ClassWhereTheCursorPropertyIs), "Cursor");

In the method Add() the first parameter is the type name of the parent class which have a property/member named "Cursor"

There is another work around to serialize types which have no standard constructor: