Friday, December 21, 2018

What if I need to make a method to take only serializable objects?

Although there is an interface named ISerializable, it seems to purpose to customize details when a type is marked [Serializable] attribute. If I understood correctly, the [Serializable] attribute by itself does not touch anything on a type it is attached to, but at run-time things implementing IFormatter determine if a given object is marked [Serializble] attribute (through reflection? I guess). Also IFormatter.Serializble() method takes just any Object. Does it mean virtually every object in .NET can be serialized? If not, is there way to take only serializable objects and make a compile-time error if a non-serializable object is passed?

What if I need to make a method to take only serializable objects? Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team