Portable class library: recommended replacement for [Serializable]

后端 未结 3 1621
不思量自难忘°
不思量自难忘° 2020-12-08 00:47

I am porting a .NET Framework C# class library to a Portable Class Library. One recurring problem is how to deal with classes decorated with the [Serializable]

3条回答
  •  盖世英雄少女心
    2020-12-08 00:59

    One thing you could do to eliminate the clutter that the constant preprocessor directives causes is to push that off to one new SerializableAttribute class and basically trick the compiler.

    #if PORTABLE
    namespace System
    {
       public class SerializableAttribute : Attribute
       {
           //this does nothing
       }  
    }
    #endif
    

    Then just continue to decorate your classes with Serializable as normal...

提交回复
热议问题