0

I have class with property of type ISet. I want to serialize that class but don't know how to do with ISet.

[Serializable]    
class Question: ISerializable
{
  private int id;
  public int Id
  {
    get{return id;}
    set{id = value;}
  }

  private ISet answerChoice;
  public ISet AnswerChoices
  {
   get{return answerChoices;}
   set { answerChoices = value; }
  }

  public Question(SerializationInfo info, StreamingContext context)
  {
       id = info.GetInt32("id");
       answerChoices = //how to deserialize this collection
  }

  void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
  {
       info.AddValue("id", id);
       info.AddValue("ac", answerChoices);
  }
}

Do anyone try to make the same? Please, help me.

Kate
  • 751
  • 1
  • 12
  • 26

1 Answers1

1

How about:

info.GetValue("ac",...);

And why do you implement you own serialization if you do not add any additional value?

Alex Reitbort
  • 13,504
  • 1
  • 40
  • 61
  • And why do you implement you own serialization if you do not add any additional value? --- To add object to ViewState you should implement ISerializable interface - it is a rule! How about: info.GetValue("ac",...); --- What I should write in place of ellipsis? – Kate Aug 26 '10 at 12:19
  • No you do not, you just need to mark it as serializable(and make sure it is serializable) – Alex Reitbort Aug 26 '10 at 12:33
  • 1
    @Kate, info.GetValue("ac", typeof(ISet)) should work. @Alex, @Kate - note that for serialization to work as above, type implementing ISet has to be serializable. – VinayC Aug 26 '10 at 12:50
  • Thank you very mutch. It is so simple, why i don't think about it! – Kate Aug 26 '10 at 13:18