Skip to content

Commit

Permalink
add serialization support for scriptcs submission types
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Nov 25, 2015
1 parent 7a40894 commit 1046bb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/FsPickler/PicklerGeneration/FieldPicklers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ type internal ClassFieldPickler =

static member Create<'T when 'T : not struct>(resolver : IPicklerResolver) =
let ty = typeof<'T>
let isEDI = not runsOnMono && isExceptionDispatchInfo ty // ExceptionDispatchInfo serialization not supported in mono.
// ExceptionDispatchInfo serialization not supported in mono.
let isEDI = not runsOnMono && isExceptionDispatchInfo ty
// we need to be capable of serializing ScriptCs submission types
let isScriptCsSubmissionType = isScriptCsSubmissionType ty
// compiler generated types in C# are not marked as serializable, but should in principle be treated as such.
let isCompilerGeneratedType = containsAttr<System.Runtime.CompilerServices.CompilerGeneratedAttribute> ty
let isSerializable =
isReflectionSerializable ty
// compiler generated types in C# are not marked as serializable, but should in principle be treated as such.
|| containsAttr<System.Runtime.CompilerServices.CompilerGeneratedAttribute> ty
|| isScriptCsSubmissionType
|| isCompilerGeneratedType
|| isEDI
|| PicklerPluginRegistry.IsDeclaredSerializable ty

Expand All @@ -137,7 +142,13 @@ type internal ClassFieldPickler =
if isEDI then fields |> Array.filter (fun f -> not <| f.Name.Contains "Watson")
else fields

let fields =
// if scriptcs submission, do not serialize its "InteractiveSession" field
if isScriptCsSubmissionType then fields |> Array.filter (fun f -> not <| isScriptCsInteractiveHostObject f.FieldType)
else fields

let picklers = fields |> Array.map (fun f -> resolver.Resolve f.FieldType)

let tags = fields |> Array.mapi (fun i f -> getNormalizedFieldName i f.Name)

let isDeserializationCallback = isAssignableFrom typeof<IDeserializationCallback> ty
Expand Down
5 changes: 5 additions & 0 deletions src/FsPickler/Utils/Reflection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ type MethodInfo with

member m.GetParameterTypes() = m.GetParameters() |> Array.map (fun p -> p.ParameterType)

let isScriptCsSubmissionType (t : Type) =
t.Name.StartsWith "Submission#" && t.Assembly.GetName().Name.StartsWith "ℛ*"

let isScriptCsInteractiveHostObject (t : Type) =
t.Name = "InteractiveHostObject" && t.Assembly.GetName().Name = "Microsoft.CodeAnalysis.InteractiveFeatures"

type ConstructorInfo with
member c.GetParameterTypes() = c.GetParameters() |> Array.map (fun p -> p.ParameterType)
Expand Down

0 comments on commit 1046bb8

Please sign in to comment.