Serialize using an interface?

  • Thread starter Thread starter Julia
  • Start date Start date
J

Julia

Hi,
I have an two classes derived from ICommand interface

for example SubscribeCommand,and RetryCommand

i want to do the following

ICommand command1=new SubscribeCommand()

ICommand command2=new RetryCommand()

Now i want to

Serialize

both command1 and command2 to a string

is it possible?

thanks.
 
Hi Julia,

It will be possible only if classes SubscriberCommand
and RetryCommand support serialization (e.g. ICommand
inherits ISerializable).

What do you mean: serialize to a string?

Cheers!

Marcin
 
Why should I derive from ISerializable?

I was thinking that GetType() will return ICommand but it returning the
derived class type
(the one I need) so wouldn't it work as an ordinary serialization?

thanks
 
If you declare both classes as [Serialize()] as well as the structs in
the classes etc, then you should be able to. Also you need to make
sure that SubscribeCommand and RetryCommand extend ICommand.
 
Back
Top