Reputation: 323
Hello i need to skip a determinate field group in my library. Reason: Cross porting.
One my problem is during deserialization. I Have a Editor and Client.
Editor serialize information, list and graphics component. But the client dont have possibility to deserialize a graphics element,
my code:
//DirectX Light
[Serializable]
public struct _light
{
public int id;
public float Color1;
public float Color2;
public float Color3;
public float Color4;
public float Power;
public int decay;
public float x;
public float y;
public float z;
public bool enabled;
}
[Serializable]
public struct _ev
{
public int evntID;
public int PositionX;
public int PosotionY;
public List<string> ComCode;
public byte[] EventGraphics;
public List<Graphics.Node> NodeGraph; //Editor only information
public List<pages> Pages;
public List<EventItem> Event;
}
i need to read this field on the Editor and no to Client. But client and Editor use same file for reading information.
Problem are inside to List<Graphics.Node>
it's a windows component.
and client cannot read this. Giving me back an exception.
This is a my Simple BluePrint Code Generator
maybe i can skip all field on Client and no to editor. but this struct is a vital for the Editor.
Solution?
Upvotes: 0
Views: 223
Reputation: 1202
You can use NonSerialized here is the link to msdn
This is how it should look like as suggested by @ZoharPeled
[Serializable]
public class _light
{
public int id {get; set;};
public float Color1 {get; set;};
public float Color2 {get; set;};
public float Color3 {get; set;};
public float Color4 {get; set;};
public float Power {get; set;};
public int decay {get; set;};
public float x {get; set;};
public float y {get; set;};
public float z {get; set;};
public bool enabled {get; set;};
}
[Serializable]
public class _ev
{
public int evntID {get; set;};
public int PositionX {get; set;};
public int PosotionY {get; set;};
public List<string> ComCode {get; set;};
public byte[] EventGraphics {get; set;};
//Indicates that a field of a serializable class should not be serialized
[NonSerialized]
public List<Graphics.Node> NodeGraph {get; set;}; //Editor only information
public List<pages> Pages {get; set;};
public List<EventItem> Event {get; set;};
}
Or You could make two models, one for client and for your work
[Serializable]
public class _ev_backend
{
public int evntID {get; set;};
public int PositionX {get; set;};
public int PosotionY {get; set;};
public List<string> ComCode {get; set;};
public byte[] EventGraphics {get; set;};
public List<Graphics.Node> NodeGraph {get; set;}; //Editor only information
public List<pages> Pages {get; set;};
public List<EventItem> Event {get; set;};
}
[Serializable]
public class _ev_client
{
public int evntID {get; set;};
public int PositionX {get; set;};
public int PosotionY {get; set;};
public List<string> ComCode {get; set;};
public byte[] EventGraphics {get; set;};
public List<pages> Pages {get; set;};
public List<EventItem> Event {get; set;};
}
Upvotes: 3