0

So I have a problem where I have an Object2D which contains components derived from Component2D

public class Object2D
{
     // Lets say that this contains Image2DComponent
     public List<Component2D> Components = new List<Component2D>();
}

public class Image2DComponent : Component2D
{
     public string TexturePath;
     public override void Draw() { // Drawing code for the Image }
}

However, once I serialize them into Json, I can't convert them back into their respective component (e.g. Image2DComponent) and run their respective methods again.

{"ObjectName":"Editor_Preset2DObject_Image","Parent":null,"Layer":0.0,"Pivot":"0.5, 0.5","Children":[],"Size":"50, 50","Components":[{"TexturePath":"Pixel.png","Color":{"B":255,"G":255,"R":255,"A":255},"SubLayer":0,"ComponentType":"Rander._2D.Image2DComponent, Rander, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}],"ComponentType":"Rander._2D.Object2D, Rander, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Enabled":true,"Align":4,"Rotation":0.0,"RelativeRotation":0.0,"RelativePosition":"0, 0","Position":"0, 0"}

Is there a way to convert it back without redesigning anything?

SeaPeaMe
  • 109
  • 8

0 Answers0