C
C#2y ago
MurukuBaby

✅ Csharp serializing

Hello, I am really need this to work now and I am lost on how I can serialize because there are some errors which I do not really understand. I also am not sure where I should be serializing things.
46 Replies
Chiyoko_S
Chiyoko_S2y ago
What is this for?
MurukuBaby
MurukuBabyOP2y ago
I want to serialize a seatDoubleLinkedList which contains Nodes for holding a seat class
Chiyoko_S
Chiyoko_S2y ago
ok first, don't use BinarySerializer the design of it is not very secure and it is known to have caused many problems it is actively being discouraged from use; you should look for alternatives instead what is the "seatDoubleLinkedList"?
MurukuBaby
MurukuBabyOP2y ago
Oke, what should I use? and security not a problem since i just want to do a school homework
Chiyoko_S
Chiyoko_S2y ago
Yeah but overall it's very bad practice to use it
MurukuBaby
MurukuBabyOP2y ago
Haha oke, can i send my whole code?
Chiyoko_S
Chiyoko_S2y ago
Sure
MurukuBaby
MurukuBabyOP2y ago
Pls dun mind my bad coding
Chiyoko_S
Chiyoko_S2y ago
I guess looking at your directory structure you're practicing how to use linked list so I won't really comment on that part
MurukuBaby
MurukuBabyOP2y ago
I just send all this?
Chiyoko_S
Chiyoko_S2y ago
oh ok you don't need to send those based on the description seatList is a doubly linked list? it is completely unnecessary to serialize the list as a linked list, you could just walk over the list and just save the details of each seat
MurukuBaby
MurukuBabyOP2y ago
Yeh
Chiyoko_S
Chiyoko_S2y ago
one very common way to do that is to use something like JsonSerializer what does the list node look like?
MurukuBaby
MurukuBabyOP2y ago
Hmm wait give me a moment
public class Node
{

private Seat _seat;
private Node _prev;
private Node _next;

// Constructor
public Node(Seat pSeat)
{
_seat = pSeat;
_prev = null;
_next = null;
}

public Seat Seat { get { return _seat; } set { _seat = value; } }
public Node Next { get { return _next; } set { _next = value; } }
public Node Prev { get { return _prev; } set { _prev = value; } }
}
public class Node
{

private Seat _seat;
private Node _prev;
private Node _next;

// Constructor
public Node(Seat pSeat)
{
_seat = pSeat;
_prev = null;
_next = null;
}

public Seat Seat { get { return _seat; } set { _seat = value; } }
public Node Next { get { return _next; } set { _next = value; } }
public Node Prev { get { return _prev; } set { _prev = value; } }
}
Chiyoko_S
Chiyoko_S2y ago
so really, what you want to store is the individual Seats in the linked list
MurukuBaby
MurukuBabyOP2y ago
its just to store seat class and see whos next and prev
Chiyoko_S
Chiyoko_S2y ago
right?
MurukuBaby
MurukuBabyOP2y ago
yeh
Chiyoko_S
Chiyoko_S2y ago
so what you could do well actually before that how does the Seat look like?
MurukuBaby
MurukuBabyOP2y ago
public class Seat
{

private bool _bookStatus = false; // book selected?
private int _row;
private int _col;
private bool _isDisabled = false;
private Person _bookedBy = null; // booked by who?

// Constructor
public Seat(int row, int col)
{
_row = row;
_col = col;
}

// Properties
public int Row { get { return _row; } set { _row = value; } }

public int Col { get { return _col;} set { _col = value; } }

public bool BookStatus { get { return _bookStatus; } set { _bookStatus = value; } }

public Person BookedBy { get { return _bookedBy; } set { _bookedBy = value; } }

public bool IsDisabled { get { return _isDisabled; } set { _isDisabled = value; } }

public Label Label { get; set; }

// Class functions
public String ComputeSeatLabel()
{
return ((char)(_row + 64)).ToString() + _col.ToString();
/*return $"{Row}-{Col}";*/
}

}
public class Seat
{

private bool _bookStatus = false; // book selected?
private int _row;
private int _col;
private bool _isDisabled = false;
private Person _bookedBy = null; // booked by who?

// Constructor
public Seat(int row, int col)
{
_row = row;
_col = col;
}

// Properties
public int Row { get { return _row; } set { _row = value; } }

public int Col { get { return _col;} set { _col = value; } }

public bool BookStatus { get { return _bookStatus; } set { _bookStatus = value; } }

public Person BookedBy { get { return _bookedBy; } set { _bookedBy = value; } }

public bool IsDisabled { get { return _isDisabled; } set { _isDisabled = value; } }

public Label Label { get; set; }

// Class functions
public String ComputeSeatLabel()
{
return ((char)(_row + 64)).ToString() + _col.ToString();
/*return $"{Row}-{Col}";*/
}

}
Chiyoko_S
Chiyoko_S2y ago
hm ok I think you can use auto properties but that doesn't matter here
MurukuBaby
MurukuBabyOP2y ago
I dont know whats that 0.0
Chiyoko_S
Chiyoko_S2y ago
private int _row;
public int Row { get { return _row; } set { _row = value; } }
private int _row;
public int Row { get { return _row; } set { _row = value; } }
this can become
public int Row { get; set; }
public int Row { get; set; }
MurukuBaby
MurukuBabyOP2y ago
ooh
Chiyoko_S
Chiyoko_S2y ago
but anyway I think you're better of making the linked list into an array
MurukuBaby
MurukuBabyOP2y ago
This is my files
MurukuBaby
MurukuBabyOP2y ago
I cant my homework force me to use linkedlist
Chiyoko_S
Chiyoko_S2y ago
yes but you can always read the array back into a linked list when you load the file then once it's read into an array serializing the said array of Books into some format like JSON is much simpler there are probably solutions that can serialize the entire tree ("object graph" as they call it) but it seems completely unnecessary here and you definitely do not want to use BinaryFormatter
MurukuBaby
MurukuBabyOP2y ago
does jsonSerializer can serialize into binary, its smhow also a requirement after looking
Chiyoko_S
Chiyoko_S2y ago
not sure what you mean by "binary" does it actually tell you that as a requirement show full text?
MurukuBaby
MurukuBabyOP2y ago
Chiyoko_S
Chiyoko_S2y ago
arguable what constitutes as a "binary file" text files are also binary after all
MurukuBaby
MurukuBabyOP2y ago
hmm wait i got an example somewhere actually idk, i think the teacher meant to use the binarySerializer
MurukuBaby
MurukuBabyOP2y ago
I just want to save the entire state of booking, specifically the Seat and Person class and also the Stack class but since In the Form i design it that Form can access the PersonManager and SeatManager, PersonManager have access to the list of Person class, while SeatManager have access to the doubleLinkedList which have Nodes which have Seat class. So should I covert to array in the SeatManager class?
Omnissiah
Omnissiah2y ago
if you want a "more binary" version of json you could use bson 😜
MurukuBaby
MurukuBabyOP2y ago
I think i have to use binaryFormatter
MurukuBaby
MurukuBabyOP2y ago
I just dont understand why this is happening
Omnissiah
Omnissiah2y ago
is it written in the requirements "use binary formatter"?
MurukuBaby
MurukuBabyOP2y ago
I guess in this. The teacher also gave an example on how to use this and i used the exact code but i got error would the implementation of using other formatter be different?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MurukuBaby
MurukuBabyOP2y ago
I tried different formatter but i still failed to serialize am I doing something else wrong?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MurukuBaby
MurukuBabyOP2y ago
Oh no i cant serialize a class with Label? Like this one?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MurukuBaby
MurukuBabyOP2y ago
It alright already, it because Label is not serializable and the Seat class i have this
public Label Label { get; set; }
public Label Label { get; set; }
Ty guys
Want results from more Discord servers?
Add your server