F# Serialization of Record types

后端 未结 4 1111
南旧
南旧 2021-02-04 08:42

I know how to serialize in F# using mutable objects, but is there a way to serialize/deserialize using record types using either XmlSerializer or the DataContractSerializer? loo

4条回答
  •  一个人的身影
    2021-02-04 09:18

    Beginning with F# 3.0, serialization of record types is now supported by applying the CliMutableAttribute to the type. Example:

    [] 
    type MyRecord = { Name : string; Age : int }
    

    This example is taken from http://blogs.msdn.com/b/fsharpteam/archive/2012/07/19/more-about-fsharp-3.0-language-features.aspx, which includes a discussion of this feature and three other new features in F# 3.0: triple-quoted strings, automatic properties, and unused variable warnings.

提交回复
热议问题