コード例 #1
0
            public static TryCatch <T> Deserialize <T>(ReadOnlyMemory <byte> buffer)
            {
                TryCatch <CosmosElement> tryCreateFromBuffer = CosmosElement.Monadic.CreateFromBuffer(buffer);

                if (tryCreateFromBuffer.Failed)
                {
                    return(TryCatch <T> .FromException(tryCreateFromBuffer.Exception));
                }

                CosmosElement     cosmosElement    = tryCreateFromBuffer.Result;
                TryCatch <object> tryAcceptVisitor = cosmosElement.Accept(Visitor.Singleton, typeof(T));

                if (tryAcceptVisitor.Failed)
                {
                    return(TryCatch <T> .FromException(tryAcceptVisitor.Exception));
                }

                if (!(tryAcceptVisitor.Result is T typedResult))
                {
                    Type type = typeof(T);
                    if ((tryAcceptVisitor.Result is null) && (!type.IsValueType || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))))
                    {
                        return(TryCatch <T> .FromResult(default));