Beispiel #1
0
        /// <summary>
        /// Tries the get serialization information.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="serializationInfoCache">The serialization information cache.</param>
        /// <param name="serializationInfo">The serialization information.</param>
        /// <returns></returns>
        public static bool TryGetSerializationInfo(Expression node, Dictionary <Expression, BsonSerializationInfo> serializationInfoCache, out BsonSerializationInfo serializationInfo)
        {
            var finder = new BsonSerializationInfoFinder(serializationInfoCache);

            serializationInfo = finder.Visit(node);
            return(serializationInfo != null);
        }
        // public static methods
        /// <summary>
        /// Gets the serialization info for the node utilizing precalculated serialization information.
        /// </summary>
        /// <param name="node">The expression.</param>
        /// <param name="serializationInfoCache">The serialization info cache.</param>
        /// <returns>BsonSerializationInfo for the expression.</returns>
        public static BsonSerializationInfo GetSerializationInfo(Expression node, Dictionary <Expression, BsonSerializationInfo> serializationInfoCache)
        {
            var finder            = new BsonSerializationInfoFinder(serializationInfoCache);
            var serializationInfo = finder.Visit(node);

            if (serializationInfo == null)
            {
                string message = string.Format("Unable to determine the serialization information for the expression: {0}.",
                                               ExpressionFormatter.ToString(node));
                throw new NotSupportedException(message);
            }

            return(serializationInfo);
        }