public MethodCall DeserializeCall(Stream stream, IMethodBinder binder, ITargetSelector selector, object callContext) { var reader = CreateReader(stream).MoveToContent(); var rv = new MethodCall { Target = selector.GetTarget(reader.ReadProperty("Target").ToString(), callContext) }; var osig = reader.ReadProperty("MethodSignature"); var sig = osig as byte[] ?? Convert.FromBase64String((string)osig); rv.Method = binder.GetInfoProviderFor(rv.Target).GetMethod(sig); reader.ExpectProperty("Arguments"); var args = rv.Method.GetParameters(); if (_serializer.TypeNameHandling >= TypeNameHandling.All) { rv.Arguments = _serializer.Deserialize <object[]>(reader); for (var c = 0; c < rv.Arguments.Length && c < args.Length; c++) { if (args[c].ParameterType.GetTypeInfo().IsPrimitive) { rv.Arguments[c] = Convert.ChangeType(rv.Arguments[c], args[c].ParameterType); } } reader.Next(); } else { rv.Arguments = new object[args.Length]; if (reader.TokenType != JsonToken.StartArray) { throw new ArgumentException("Arguments should be an array"); } for (var c = 0; c < args.Length; c++) { rv.Arguments[c] = _serializer.Deserialize(reader.Next(), args[c].ParameterType); } if (reader.Next().TokenType != JsonToken.EndArray) { throw new ArgumentException("Expected end array"); } reader.Next(); } reader.MoveToEnd(); return(rv); }
public MethodCall DeserializeCall(Stream stream, IMethodBinder info, ITargetSelector selector) { var reader = XmlReader.Create(stream); while (reader.NodeType != XmlNodeType.Element) { reader.Read(); } var rv = new MethodCall(); reader.ReadStartElement("MethodCall"); //Skip root node rv.Target = selector.GetTarget(reader.ReadElementContentAsString()); rv.Method = info.GetInfoProviderFor(rv.Target).GetMethod(Convert.FromBase64String(reader.ReadElementContentAsString())); reader.ReadStartElement("Arguments"); var ctx = Cache.GetContext(); rv.Arguments = rv.Method.GetParameters().Select(parameter => ((ISerializable)ctx[parameter.ParameterType].Serializer.Deserialize(reader)).Value).ToArray(); return(rv); }