mp
2016-12-15 18:33:53 UTC
trying this
interface iSerializer
{
void Serialize(object objectToSerialize, string filename);
object DeSerialize(string filename);
}
interface ISerializerJson : ISerializer
{
new void Serialize(object objectToSerialize, string filename);
new object DeSerialize(string filename);
}
interface ISerializerXml : ISerializer
{
new void Serialize(object objectToSerialize, string filename);
new object DeSerialize(string filename);
}
interface ISerializerBinary : ISerializer
{
new void Serialize(object objectToSerialize, string filename);
new object DeSerialize(string filename);
}
does this look like the right direction?
it compiled but when i made a class that implemented the interface
i get a runtime error as shown below
public class SerializerJson : ISerializerJson
{
public void Serialize(object objectToSerialize, string fileName)
{
WriteToFile(fileName, Json1.Serialize(objectToSerialize));
}
public object DeSerialize<T>(string fileName)
{
return Json1.Deserialize<T>(ReadFromFile(fileName));
}
private void WriteToFile(string fileName, string encodingString)
{
System.IO.File.WriteAllText(@fileName, encodingString);
}
private string ReadFromFile(string fileName)
{
return System.IO.File.ReadAllText(fileName);
}
}
static void Main()
{
Console.WriteLine("testing BuildingComponents Application");
// First write something so that there is something to read
...
var FirstBuilding = new Building("First Building");
var SecondBuilding = new Building("Second Building");
var filename = "C:/temp/testSerialize.txt";
var serializerJSON = new SerializerJson();
Console.WriteLine("First Building name starts " +
FirstBuilding.Name);
Console.WriteLine("try to write to file");
//bombs on this line now
serializerJSON.Serialize(FirstBuilding, filename);
Console.WriteLine("try to read from file");
SecondBuilding = (Building)
serializerJSON.DeSerialize<Building>(filename);
Console.WriteLine("After DeSerialization Second Building
name " + SecondBuilding.Name);
}
Exception thrown: 'System.Runtime.Serialization.SerializationException'
in System.Runtime.Serialization.dll
the same basic code worked when hard coded in main but when i put in
object it bombs, do you see anything obvious i'm missing?
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
interface iSerializer
{
void Serialize(object objectToSerialize, string filename);
object DeSerialize(string filename);
}
interface ISerializerJson : ISerializer
{
new void Serialize(object objectToSerialize, string filename);
new object DeSerialize(string filename);
}
interface ISerializerXml : ISerializer
{
new void Serialize(object objectToSerialize, string filename);
new object DeSerialize(string filename);
}
interface ISerializerBinary : ISerializer
{
new void Serialize(object objectToSerialize, string filename);
new object DeSerialize(string filename);
}
does this look like the right direction?
it compiled but when i made a class that implemented the interface
i get a runtime error as shown below
public class SerializerJson : ISerializerJson
{
public void Serialize(object objectToSerialize, string fileName)
{
WriteToFile(fileName, Json1.Serialize(objectToSerialize));
}
public object DeSerialize<T>(string fileName)
{
return Json1.Deserialize<T>(ReadFromFile(fileName));
}
private void WriteToFile(string fileName, string encodingString)
{
System.IO.File.WriteAllText(@fileName, encodingString);
}
private string ReadFromFile(string fileName)
{
return System.IO.File.ReadAllText(fileName);
}
}
static void Main()
{
Console.WriteLine("testing BuildingComponents Application");
// First write something so that there is something to read
...
var FirstBuilding = new Building("First Building");
var SecondBuilding = new Building("Second Building");
var filename = "C:/temp/testSerialize.txt";
var serializerJSON = new SerializerJson();
Console.WriteLine("First Building name starts " +
FirstBuilding.Name);
Console.WriteLine("try to write to file");
//bombs on this line now
serializerJSON.Serialize(FirstBuilding, filename);
Console.WriteLine("try to read from file");
SecondBuilding = (Building)
serializerJSON.DeSerialize<Building>(filename);
Console.WriteLine("After DeSerialization Second Building
name " + SecondBuilding.Name);
}
Exception thrown: 'System.Runtime.Serialization.SerializationException'
in System.Runtime.Serialization.dll
the same basic code worked when hard coded in main but when i put in
object it bombs, do you see anything obvious i'm missing?
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus