示例#1
0
        /// <summary>
        /// Tries to retrieve the value from the given path. The path is a dot separated string of property names.
        /// </summary>
        /// <typeparam name="T">The expected type of the value.</typeparam>
        /// <param name="instance">The root instance to start the lookup from.</param>
        /// <param name="path">A dot separated string of property names. Spreaded properties can be indexed using [N] for example "MySpread[0]" retrieves the first value in MySpread.</param>
        /// <param name="defaultValue">The default value to use in case the lookup failed.</param>
        /// <param name="value">The returned value.</param>
        /// <returns>True if the lookup succeeded.</returns>
        public static bool TryGetValueByPath <T>(this IVLObject instance, string path, T defaultValue, out T value)
        {
            var spine = instance.GetSpine(path);
            var entry = spine.Pop();
            var leaf  = entry.Value;

            return(TryGetValueByExpression(leaf, entry.Key, defaultValue, out value));
        }