Esempio n. 1
0
            public object Deserialize(ChunkedMemoryStream cms, TextReader reader, StreamingContext context)
            {
                if (Converter == null)
                {
                    try
                    {
                        if (context.Context == null)
                        {
                            return(JsonNet.Deserialize(new JsonTextReader(reader), Target));
                        }
                        var jsonNet = new JsonSerializer();
                        jsonNet.Converters.Add(EnumConverter);
                        jsonNet.Converters.Add(TextReaderConverter);
                        jsonNet.Converters.Add(TreePathConverter);
                        jsonNet.TypeNameHandling = TypeNameHandling.Auto;
                        jsonNet.Context          = context;
                        jsonNet.Binder           = Binder;
                        return(jsonNet.Deserialize(new JsonTextReader(reader), Target));
                    }
                    catch (TargetInvocationException tex)
                    {
                        if (tex.InnerException != null)
                        {
                            throw tex.InnerException;
                        }
                        throw;
                    }
                }
                object result;
                var    btr = reader as BufferedTextReader;

                if (btr != null)
                {
                    result = Converter.Deserialize(btr, context, JsonNet.Deserialize);
                }
                else if (cms != null)
                {
                    result = Converter.Deserialize(cms.UseBufferedReader(reader), context, JsonNet.Deserialize);
                }
                else
                {
                    using (var cms2 = ChunkedMemoryStream.Create())
                        result = Converter.Deserialize(cms2.UseBufferedReader(reader), context, JsonNet.Deserialize);
                }
                if (IsSimple)
                {
                    return(result);
                }
                if (IsArray)
                {
                    return((result as List <T>).ToArray());
                }
                if (IsSet)
                {
                    return(new HashSet <T>(result as List <T>));
                }
                if (IsList)
                {
                    return(result);
                }
                if (IsStack)
                {
                    var list = result as List <T>;
                    list.Reverse();
                    return(new Stack <T>(list));
                }
                if (IsQueue)
                {
                    return(new Queue <T>(result as List <T>));
                }
                if (IsLinkedList)
                {
                    return(new LinkedList <T>(result as List <T>));
                }
                return(result);
            }