Пример #1
0
        /// <summary>
        /// Read the property with the specified <paramref name="name"/>. If the property does not exists, This function returns <paramref name="defaultValue"/>.
        /// </summary>
        /// <param name="image">The <see cref="OpenSlideImage"/> object.</param>
        /// <param name="name">The property name.</param>
        /// <param name="defaultValue">The value returned when the specified property does not exists.</param>
        /// <returns>The value of the property or <paramref name="defaultValue"/>.</returns>
        public static string?GetProperty(this OpenSlideImage image, string name, string?defaultValue)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            if (!image.TryGetProperty(name, out string?value))
            {
                return(defaultValue);
            }
            return(value);
        }
Пример #2
0
        /// <summary>
        /// Read the property with the specified <paramref name="name"/> and parse it as a <see cref="int"/> value. If the property does not exists or can not be parsed as <see cref="int"/>, This function returns <paramref name="defaultValue"/>.
        /// </summary>
        /// <param name="image">The <see cref="OpenSlideImage"/> object.</param>
        /// <param name="name">The property name.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>The value of the property or <paramref name="defaultValue"/>.</returns>
        public static int GetProperty(this OpenSlideImage image, string name, int defaultValue)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            if (!image.TryGetProperty(name, out string?value))
            {
                return(defaultValue);
            }
            if (!int.TryParse(value, out var result))
            {
                return(defaultValue);
            }
            return(result);
        }