In order to make the converter configurable we mark the class for content entry. First add the following usings to the top of the converter class file, using Ant.ContentEntry.Converters, Ant.ContentEntry.ClassInformation and Ant.ContentEntry.FieldDisplayers;
Then add a [ClassOverview] attribute top of the class. Add the following code to the class.
// adding configuration
int divisor=3;
[PropertyInformation(typeof(Int32Converter), typeof(InputEntry), true, 0)]
[PropertyLanguage("ENGLISH", "Divisor", "Specify the divisor", "*")]
public int Divisor {get {return divisor;} set {divisor = value;}}
// finishing configuration
Add the code to handle unpacking of the configuration information. This code is added to the Init method.
String xml = def.XmlFragment;
if (xml != null && xml.Length != 0)
{
XmlDocument instance = new XmlDocument();
try
{
instance.LoadXml(xml);
}
catch (XmlException e)
{
throw new ContentEntryException("Failed to parse xml "+xml, e);
}
instance = XmlHelper.GetExtensionBlock(instance, GetType().FullName);
if (instance != null)
{
ContentDefinition myDef = new ContentDefinitionFactory(def.ContentDefinition.User,
def.ContentDefinition.Language, def.ContentDefinition.State).ForClass(this.GetType());
XmlHelper.PutValuesIntoObjectFromInstance(myDef, instance, this);
}
}
Finally remove the reference to 3 in the code and replace by divisor.
We now have the code need to handle configuration.