Reputation: 1127
I am having problems saving serialized data from a nested custom class list. How do you properly serialize these classes?
[System.Serialize]
public class OuterClass() {
List<InnerClass> someList = new List<InnerClass>();
public OuterClass() {}
}
public class InnerClass() {
public int someInt;
public InnerClass(int _someInt) {
someInt = _someInt;
}
}
Upvotes: 4
Views: 1982
Reputation: 51634
Both the containing and the contained class must be decorated with the [Serializable]
attribute.
Upvotes: 0
Reputation: 21409
The InnerClass
class should have the [System.Serialize]
attribute as well to be able to serialize it. Something along these lines:
[System.Serialize]
public class OuterClass() {
List<InnerClass> someList = new List<InnerClass>();
[System.Serialize]
public class InnerClass() {
public int someInt;
}
}
On a side note, your InnerClass
is not nested. It should be defined inside the OuterClass
if you want to call it "nested class"
Upvotes: 0