/// <summary> /// Try to infer <see cref="ILineFileFormat"/> from <paramref name="filename"/>. /// </summary> /// <param name="map"></param> /// <param name="filename"></param> /// <returns>file format or null</returns> public static ILineFileFormat TryGetFormatByFilename(this IReadOnlyDictionary <string, ILineFileFormat> map, string filename) { string ext = LineFileFormatMap.GetExtension(filename); ILineFileFormat fileFormat; if (ext != null && map.TryGetValue(ext, out fileFormat)) { return(fileFormat); } return(null); }
/// <summary> /// Infer and get <see cref="ILineFileFormat"/> from <paramref name="filename"/>. /// </summary> /// <param name="map"></param> /// <param name="filename"></param> /// <returns>file format</returns> /// <exception cref="ArgumentException">thrown if fileformat was not found</exception> public static ILineFileFormat GetFormatByFilename(this IReadOnlyDictionary <string, ILineFileFormat> map, string filename) { string ext = LineFileFormatMap.GetExtension(filename); ILineFileFormat fileFormat; if (ext != null && map.TryGetValue(ext, out fileFormat)) { return(fileFormat); } throw new ArgumentException("Could not resolve file format for filename \"{filename}\""); }
/// <summary> /// Create localization asset source that reads embedded resource <paramref name="resourceName"/>. /// </summary> /// <param name="fileFormatProvider"></param> /// <param name="assembly"></param> /// <param name="resourceName"></param> /// <param name="lineFormat">(optional) </param> /// <param name="throwIfNotFound">if file is not found and value is true, <see cref="FileNotFoundException"/> is thrown, otherwise zero elements are returned</param> /// <returns>asset source</returns> /// <exception cref="System.Collections.Generic.KeyNotFoundException">If file format was not found in <paramref name="fileFormatProvider"/></exception> public static LineEmbeddedSource EmbeddedAssetSource(this IReadOnlyDictionary <string, ILineFileFormat> fileFormatProvider, Assembly assembly, string resourceName, ILineFormat lineFormat = default, bool throwIfNotFound = true) => fileFormatProvider[LineFileFormatMap.GetExtension(resourceName)].EmbeddedAssetSource(assembly, resourceName, lineFormat, throwIfNotFound);
/// <summary> /// Create localization asset source that reads file <paramref name="filename"/>. /// </summary> /// <param name="fileFormatProvider"></param> /// <param name="filename"></param> /// <param name="lineFormat">(optional) possibly needed for string and line conversions. Used also for choosing whether to instantiate parameter into hint or key</param> /// <param name="throwIfNotFound">if file is not found and value is true, <see cref="FileNotFoundException"/> is thrown, otherwise zero elements are returned</param> /// <returns>asset source</returns> /// <exception cref="KeyNotFoundException">If file format was not found in <paramref name="fileFormatProvider"/></exception> public static LineFileSource FileAssetSource(this IReadOnlyDictionary <string, ILineFileFormat> fileFormatProvider, string filename, ILineFormat lineFormat = default, bool throwIfNotFound = true) => fileFormatProvider[LineFileFormatMap.GetExtension(filename)].FileAssetSource(filename, lineFormat, throwIfNotFound);
/// <summary> /// Read file into strings file. /// </summary> /// <param name="fileFormatProvider"></param> /// <param name="filename"></param> /// <param name="lineFormat">(optional) possibly needed for string and line conversions. Used also for choosing whether to instantiate parameter into hint or key</param> /// <param name="throwIfNotFound">if file is not found and value is true, <see cref="FileNotFoundException"/> is thrown, otherwise zero elements are returned</param> /// <returns>lines</returns> /// <exception cref="KeyNotFoundException">If file format was not found in <paramref name="fileFormatProvider"/></exception> public static IEnumerable <KeyValuePair <string, IString> > ReadStringLines(this IReadOnlyDictionary <string, ILineFileFormat> fileFormatProvider, string filename, ILineFormat lineFormat = default, bool throwIfNotFound = true) => fileFormatProvider[LineFileFormatMap.GetExtension(filename)].ReadStringLines(filename, lineFormat, throwIfNotFound);
/// <summary> /// Create localization asset source that reads FileProvider resource at <paramref name="filepath"/>. /// </summary> /// <param name="fileFormatProvider"></param> /// <param name="fileProvider"></param> /// <param name="filepath"></param> /// <param name="lineFormat">(optional) possibly needed for string and line conversions. Used also for choosing whether to instantiate parameter into hint or key</param> /// <param name="throwIfNotFound">if file is not found and value is true, <see cref="FileNotFoundException"/> is thrown, otherwise zero elements are returned</param> /// <returns>asset</returns> /// <exception cref="System.Collections.Generic.KeyNotFoundException">If file format was not found in <paramref name="fileFormatProvider"/></exception> public static IAsset FileProviderAsset(this IReadOnlyDictionary <string, ILineFileFormat> fileFormatProvider, IFileProvider fileProvider, string filepath, ILineFormat lineFormat = default, bool throwIfNotFound = true) => fileFormatProvider[LineFileFormatMap.GetExtension(filepath)].FileProviderAsset(fileProvider, filepath, lineFormat, throwIfNotFound);