protected override void Deserialize(CodeReader reader) { var decls = new ArrayList(); while (reader.Current != WorkflowCommonDefs.CompilerSegmentEnd) { IContextSerializer instance = EngineContextFactory.Create(reader); var tpl = instance as EngineVariableTemplate; var node = instance as EngineContextNodeBase; if (tpl != null) { decls.Add(tpl); } else if (node != null) { this.Child = node; } } if (decls.Count > 0) { this.Declarations = (EngineVariableTemplate[])decls.ToArray(typeof(EngineVariableTemplate)); } }
private static object DeserializeValue( string name, string input, IContextSerializer serializer, Action <string, Exception> errorCallback) { try { return(serializer.Deserialize(input)); } catch (Exception error) { errorCallback?.Invoke($"Failed to deserialize value of property '{name}' from following string: '{input}'.", error); return(null); } }
public GenericSerializer(IContextSerializer <T> serializer) { this.serializer = serializer; }
internal static IContextSerializer Create(CodeReader reader) { IContextSerializer instance = null; Type t; int idx; Delegate d; switch (reader.Current) { case 'u': //root if (reader.TryRead(3) == WorkflowCommonDefs.CompilerNodeRoot) { reader.Ptr += 3; instance = new EngineContextRoot(); instance.Deserialize(reader); } break; case WorkflowCommonDefs.CompilerTypeVoid: //nop reader.Ptr++; instance = new EngineContextNop(); instance.Deserialize(reader); break; case 'v': //local-var declaration reader.Ptr++; t = GetTypeFromTag(reader.Read()); idx = reader.ReadIndex(); instance = new EngineVariableTemplate(t, idx.ToString()); instance.Deserialize(reader); break; case 'F': //global-func reference reader.Ptr++; idx = reader.ReadIndex(); d = reader.GlobalFuncs[idx]; instance = CreateFunc(d); instance.Deserialize(reader); break; case 'f': //local-func reference throw new NotSupportedException(); case 'L': //global-var reference reader.Ptr++; idx = reader.ReadIndex(); instance = new EngineContextGlobalVarReference(idx); instance.Deserialize(reader); break; case 'l': //local-var reference reader.Ptr++; idx = reader.ReadIndex(); instance = new EngineContextLocalVarReference(idx); instance.Deserialize(reader); break; case 'K': //constant value reader.Ptr++; t = GetTypeFromTag(reader.Read()); instance = new EngineContextConstantValue(t); instance.Deserialize(reader); break; case 'C': //cast reader.Ptr++; t = GetTypeFromTag(reader.Read()); instance = new EngineContextCast( GetTypeFromTag(reader.Read()), t); instance.Deserialize(reader); break; case 'S': //statement if (reader.TryRead(2) == WorkflowCommonDefs.CompilerNodeStatementSequence) { reader.Ptr += 2; instance = new EngineContextSequence(); instance.Deserialize(reader); } else if (reader.TryRead(2) == WorkflowCommonDefs.CompilerNodeStatementAssign) { reader.Ptr += 2; instance = new EngineContextAssign(); instance.Deserialize(reader); } else if (reader.TryRead(2) == WorkflowCommonDefs.CompilerNodeStatementWhile) { reader.Ptr += 2; instance = new EngineContextWhile(); instance.Deserialize(reader); } else if (reader.TryRead(2) == WorkflowCommonDefs.CompilerNodeStatementIf) { reader.Ptr += 2; instance = new EngineContextIf(); instance.Deserialize(reader); } break; } if (instance == null) { throw new NotSupportedException(); } return(instance); }