コード例 #1
0
        /// <summary>
        ///     Extension method to get the canonical file extension for a <see cref="CustomDataSourceReference"/>.
        /// </summary>
        /// <returns>
        ///     <inheritdoc cref="FileExtensionUtils.CanonicalizeExtension(string)"/>
        /// </returns>
        public static string TryGetCanonicalFileExtension(this CustomDataSourceReference self)
        {
            var fileDataSource          = self.DataSource as FileDataSourceAttribute;
            var fileDataSourceExtension = fileDataSource?.FileExtension;

            return(FileExtensionUtils.CanonicalizeExtension(fileDataSourceExtension));
        }
コード例 #2
0
        /// <summary>
        ///     Extension method to check if the file is supported by the <see cref="ICustomDataSource"/>.
        /// </summary>
        /// <param name="filePath">
        ///     Full path to the file being checked.
        /// </param>
        /// <returns>
        ///     <inheritdoc cref="ICustomDataSource.IsFileSupported(string)"/>
        /// </returns>
        public static bool Supports(this ICustomDataSource self, string filePath)
        {
            var supportedExtension = FileExtensionUtils.CanonicalizeExtension(self.TryGetFileExtension());
            var fileExtension      = FileExtensionUtils.CanonicalizeExtension(Path.GetExtension(filePath));

            // Should this be invariant culture?
            return(StringComparer.CurrentCultureIgnoreCase.Equals(fileExtension, supportedExtension) &&
                   self.IsFileSupported(filePath));
        }