0

Good morning, I am working on a C# application and I need to serialize an object with ISerializable interface but I do not how to do it. My object has no properties, it just have some methods. See below the code :

public interface ILogger  
{  
  void logErrorMessage(string errorMessage);  
  void logInfoMessage(string infoMessage);  
  void logWarningMessage(string warningMessage);  
}  



[Serializable]  
class MessageLogger: ILogger, ISerializable  
{  
  
  public MessageLogger()  
  { }  
  
  public void logErrorMessage(string errorMessage)  
  {  
    System.Diagnostics.Debug.WriteLine("ERROR :" + errorMessage);  
  }  
  
  public void logInfoMessage(string infoMessage)  
  {  
    System.Diagnostics.Debug.WriteLine("INFO:" + infoMessage);  
  }  
  
  public void logWarningMessage(string warningMessage)  
  {  
    System.Diagnostics.Debug.WriteLine("WARNING:" + warningMessage);  
  }  
  
  public virtual void GetObjectData(SerializationInfo info, StreamingContext context)  
  {  
  }  
}  

My question is what I have to put in GetObjectData ?

Thank you in advance for any help.

Romain.

Zaraki21
  • 21
  • 1
  • 4
  • 2
    for me it makes no sense to serialize a logger, as you noticed it has no meaningful state/properties. for example it would serialize to `{}` as JSON, wich is completely useless – Patrick Beynio Oct 28 '20 at 10:11

1 Answers1

-1

Take a look a this, it explains it pretty clearly: Microsoft Docs

ynkf
  • 36
  • 1
  • 6
  • 3
    Please edit the answer to contain relevant info, see [why link-only answers are bad](https://meta.stackexchange.com/a/8259/299295). – Sinatr Oct 28 '20 at 10:19