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?
How can I make a method to take only serializable objects?
98 Views Asked by minhee At
1
There are 1 best solutions below
Related Questions in .NET
- Does compiler optimize operation on const variable and literal const number?
- What is the point of definnig Asp.net Intrinsic Objects In different places and what is the different betwen them?
- Deleting Orphans with Fluent NHibernate
- IOrderedEnumerable to vb.net IOrderedEnumerable Conversion
- What is this namespace ITypeOfObjectsBoundToListBox ? Couldn't find it
- .net rest service with JSON string and consumed with java client
- What is best way to check if any of the property of object is null or empty?
- Telerik's WPF RadColorPicker NoColorText property not working
- Possible consequences of duplicate ProgId for different classes
- How are multiple requests to Task.Run handled from a resource management standpoint?
- Optimizing C++ call from C#
- Make a per-web-application object available to Web API and SignalR controllers
- System.ComponentModel.DataAnnotations.Schema namespace conflict
- LINQ Except/Distinct based on few columns only, to not add duplicates
- Not displaying content by its URL string - absolute urls
Related Questions in SERIALIZABLE
- Serializable class with ISerializable constructor
- Error in passing data between activites android while using a custom object
- Redis Serialization and Deserialization
- Implementing both Serializable and Parcelable interfaces from an object in Android - conflict
- Serializing look up object for App Fabric
- What are the conditions for Serializable?
- java.util.Set, java.util.List Serializable issue
- Could anyone tell me whats use of implements interface which extended with "Serializable" interface with example?
- how to pass a list of objects of View in a bundle
- Sending Parcelable Objects as Serializable
- Setting non-serializable attribute value into HttpSession
- WRITE over READ in mysql
- Implement Serializable to a class implementing an Interface
- Including outside variables when serializing an object
- HtmlUnit: HtmlPage Serialization Exception
Related Questions in TYPE-SAFETY
- C++ - Safety of reinterpret_cast for pointer-to-primitives
- Under Xcode 6.3, NULL C++ reference address evaluates as non-zero
- How to design a serializable class such that any non-serialized attribute leads to a compile-time error?
- How do I combine the safety of type requirements with the safety of enums?
- C# Generics and Type Safety at Runtime
- ArrayList contains wrong type objects without explicit raw-type casting
- How to prevent arithmetic operations between different kinds of integers?
- Java: Type aliases support annotation processing tool (APT)?
- Type safety of input.nextLine?
- GSON and InstanceCreator issue
- JComboBox is a raw type. References to generic type JComboBox<E> should be parameterized
- Changing a property of a embedded struct using a method from it's parent
- Function that takes one explicit type
- Can I use a set type as an array index?
- Is static_cast misused?
Related Questions in ISERIALIZABLE
- Serialization when extending a class whose GetObjectData method is not marked virtual
- Linq-to-SQL overriding my OnSerializing attribute
- ISerializable for Collection<T>
- Serializing events with circular references using ISerializable
- Sonar Qube Error Update this implementation of 'ISerializable' to conform to the recommended serialization pattern
- Custom object XML serialization whithout any xml tags
- ISerializable de-serialization performance
- Deserialization constructor not called
- How to structure classes to Implement IEquatable and ISerializable
- Is there a shortcut to binary-serialize every property in an object?
- How to Serialize collection
- Using WCF DataContract in MVC SessionState using AppFabric cache
- Passing recursive collection through WCF
- ISerializable and DataContract
- What's the difference between using the Serializable attribute & implementing ISerializable?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
No, there is no way to do this for all types that might be serializable, except perhaps by writing a custom Roslyn analyzer that applies the exact rules you want, and adds the warnings that you want. This is a lot of work, and it may be simpler to simply add unit tests / integration tests that cover the serialization scenarios that you intend to support.
Additional notes:
[Serializable]is a pseudo-attribute - it actually maps to an IL flag, not a regular attribute annotation, and additionally it is only used by some serializers (very much not all)ISerializable/IFormatterAPIs are generally the last serializers you want to use for most general purpose scenarios - they are typically much more brittle and type-bound that other more forgiving serializers (json, xml, protobuf etc)No. However, different serializers have different rules for when things can be serialized, and those rules are often multiple and varied... i.e. it can look like X or like Y or like Z. As such, the only API that accepts all 3 is:
object