示例#1
0
        public void CanGenerateDebugReports()
        {
            var ceras = new CerasSerializer();

            var reportBool   = ceras.GenerateSerializationDebugReport(typeof(bool));
            var reportType   = ceras.GenerateSerializationDebugReport(typeof(Type));
            var reportString = ceras.GenerateSerializationDebugReport(typeof(string));

            var reportList       = ceras.GenerateSerializationDebugReport(typeof(List <int>));
            var reportTuple      = ceras.GenerateSerializationDebugReport(typeof(Tuple <string, int>));
            var reportValueTuple = ceras.GenerateSerializationDebugReport(typeof(ValueTuple <string, int>));
            var reportPerson     = ceras.GenerateSerializationDebugReport(typeof(Issue25.Adult));
        }
            public static T Deserialize <T>(ReadOnlySpan <byte> data, bool suppressErrors = true, bool preserveTypeInfo = true, bool compatibleWithDataContractSerializer = true, params Type[] knownTypes)
            {
                var serializerPool = GetPool(preserveTypeInfo, compatibleWithDataContractSerializer, knownTypes);

                CerasSerializer serializer = null;

                try
                {
                    serializer = serializerPool.Get();
                    return(serializer.Deserialize <T>(data.ToArray()));
                }
                catch (Exception e)
                {
                    if (!suppressErrors)
                    {
                        e.Data["SerializerDebugReport"] = serializer?.GenerateSerializationDebugReport(typeof(T));
                        ExceptionDispatchInfo.Capture(e).Throw();
                    }
                    return(default);