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
- file download method in visual studio 2017
- Repository manager receives the wrong connection string in .net core
- MongoDb not connecting C#
- The current .NET SDK does not support targeting .NET Core 6.0. Brand new WPF Project VS Community 2022 17.9.5
- Why Scanning GSI on DynamoDb doesnt work as fast as expected when using CONTAINS?
- Are "blittable types" really unmanaged types for StructLayout Sequential
- Failed to fetch dynamically imported module on Blazor JS Interop
- Problem to upload several images per one request
- Implementing Azure AD B2C Authentication in .NET 8 Blazor Project (RenderMode: InteractiveAuto)
- Stripe connect payout - throws exceptions
- 'IOException: The cloud file provider is not running', when trying to delete 'cloud' folder
- Azure Application Insights Not Displaying Custom Logs for Azure Functions with .NET 8
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Socket.io nodejs server .NET connection
- Producer Batching Service Bus Vs Kafka
Related Questions in SERIALIZABLE
- Is there any solution that enable LAZY FETCH when implementing Serializable
- How to check if a [Serializable] class object is null or not in Unity C#?
- Serialization of 3rd party subtyped classes at runtime in Kotlin
- How to declare an unmodifiable serializable List in Java
- Encapsulating member variables of a raw C# class that was marked as serializable
- Dump with SERIALIZABLE more consistent than `--single-transaction` (REPEATABLE READ) in MySQL
- Handling inconsistency in a highly normalized DB with long load times
- KTOR: Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied
- Spark with Scala: Task not serializable due to sparkContext
- Migrating Old Serialized Data to Externalizable Data
- springframework.data.redis.serializer.SerializationException: Cannot serialize
- select for update and insert on SERIALIZABLE isolation level
- Attribute @click is not serializable as XML 1.0., and other Errors
- How to create a new instance Serializable class by reflection in Kotlin?
- Issue while parsing a list of objects retrieved from Firebase Firestore collection
Related Questions in TYPE-SAFETY
- Is there a way to add type safety to page form store in SvelteKit?
- Abstract TypeScript property type guarding logic in a typesafe way
- What is the proper way of wrapping an Int (not a general type) in another type if type safety is the only motive?
- Why isn't it an error if the arguments are more than required in std::format?
- How to safety cast raw Map to Map<String, List<Int>> in Kotlin?
- How to store keys of a type argument in typescript without passing an instant?
- What does the usage of restrict mean in the man page for 'fwrite'?
- How do I replace the setTimeout method in a typesafe manner?
- Defining an infinite family of classes "MatrixMxN" in C#
- More sound approach to designing a spline functor?
- Using Templated Parameter Functions That Call Type Functions
- Type safety doesn't work with Angular dependency injection
- Seeking Recommendations for Lightweight Libraries for Strongly Typed TypeScript RESTful API Endpoints
- How do I enforce a maximum depth and value requirements for a multi-dimensional object containing objects and arrays of primitive (only) values?
- TypeScript returning arbitrary type
Related Questions in ISERIALIZABLE
- Sonar Qube Error Update this implementation of 'ISerializable' to conform to the recommended serialization pattern
- Serialization/Deserialization with ISerializable
- How to correctly serialize Exceptions in .net 4.7.[x]+, and .net Standard 2.[x]+
- Sonarcube does not like my implementation of serializable exception class
- WCF Serialization using ISerializable Interface
- How to fix an inner NullReferenceException when working with a serializable class using the ISerializable interface?
- Using ISerializable breaks serialization for previously supported types
- How to implement GetObjectData in object with ISerializable field that itself has custom serialization?
- How can I make a method to take only serializable objects?
- ISerializable for Collection<T>
- System.InvalidCastException "Object must implement IConvertible." when deserializing a Dictionary using a BinaryFormatter
- Custom object XML serialization whithout any xml tags
- Binary serialization versioning issue
- C#: [NonSerialized] when implementing ISerializable
- C# custom serialization of a class with list of interfaces
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 # Hahtags
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