I want to send parameter-settings from a backendapplication to the frontend. I also need to be able to have different type of parameters (Portnumbers, folders, static strings and such).
So I've designed a baseclass, Parameter as such:
public abstract class Parameter
{
public abstract bool isValid();
}
Let's say that we have two types of folder parameters:
public abstract class Folder : Parameter
{
public string folderName { get; set; }
protected Folder(string folderName)
{
this.folderName = folderName;
}
}
public class ReadWriteFolder : Folder
{
public ReadWriteFolder(string folderName) : base(folderName)
{
}
public override bool isValid()
{
return isReadable() && isWritable();
}
}
public class ReadFolder : Folder
{
public ReadFolder(string folderName) : base(folderName)
{
}
public override bool isValid()
{
return isReadable();
}
}
This is used from a WebAPI, so this is my controller:
public Dictionary<String, Parameter> Get()
{
Dictionary<String, Parameter> dictionary = new Dictionary<String, Parameter>();
dictionary.Add("TemporaryFiles", new ReadWriteFolder("C:\\temp\\"));
dictionary.Add("AnotherTemporaryFiles", new ReadWriteFolder("D:\\temp\\"));
return dictionary;
}
This yields the following JSON-serialisation:
{"TemporaryFiles":{"folderName":"C:\\temp\\"},"AnotherTemporaryFiles":{"folderName":"D:\\temp\\"}}
which seems reasonable.
My question is this: How can I deserialize this back into the original types? Or change the serialization into something that is more easy to deserialize?