/// <summary> /// Initializes this instance of the <see cref="WindowsRuntimeResourceManager"/> class. /// </summary> /// <param name="resourceSource"> /// The <see cref="Type"/> which contains the resource data for this instance of the /// <see cref="WindowsRuntimeResourceManager"/>. /// </param> private void Initialize(Type resourceSource) { var resourcesFiles = new List <string>(WindowsRuntimeResourceManager.GetFileNamesForResourceType(resourceSource.FullName)); foreach (var file in resourcesFiles) { var underscoreSplit = file.Split( new[] { WindowsRuntimeResourceManager.CultureDelimiter }, StringSplitOptions.None); var cultureInfo = CultureInfo.InvariantCulture; if (file.Contains(WindowsRuntimeResourceManager.CultureDelimiter) && file.Contains('.')) { cultureInfo = new CultureInfo(underscoreSplit[1].Split('.')[0]); } var resources = WindowsRuntimeResourceManager.ReadFile(file); if (!this.resourcesDictionary.ContainsKey(cultureInfo)) { this.resourcesDictionary.Add( cultureInfo, new Dictionary <string, string>(WindowsRuntimeResourceManager.GetResourceDictionary(resources))); } this.resourcesSource = resourceSource; this.InjectThisInstanceIntoResxGeneratedApplicationResourcesClass(resourceSource); } }
/// <summary> /// Gets the file name of the resource file represented by the given name of the resource <see cref="Type"/> for the /// given <see cref="CultureInfo"/>. /// </summary> /// <param name="resourceSourceTypeName"> /// The fully qualified name of the resource <see cref="Type"/> (eg 'Shared.Resources.LocalizationResources'). /// </param> /// <returns> /// The file name of the resource file represented by the given name of the resource <see cref="Type"/> for the given /// <see cref="CultureInfo"/>. /// </returns> private static IEnumerable <string> GetFileNamesForResourceType(string resourceSourceTypeName) { if (!resourceSourceTypeName.Contains('.')) { return(null); } var resourceIdentifier = resourceSourceTypeName.Remove(0, resourceSourceTypeName.Split('.')[0].Length + 1); var pathComponents = resourceIdentifier.Split('.'); var fileNameWithoutPath = resourceIdentifier.Remove( 0, pathComponents.Take(pathComponents.Length - 1).Aggregate(0, (i, s) => s.Length) + 1); var resourceDirectory = string.Empty; if (resourceIdentifier.Length != fileNameWithoutPath.Length) { resourceDirectory = resourceIdentifier.Remove( resourceIdentifier.Length - fileNameWithoutPath.Length - 1, fileNameWithoutPath.Length + 1); } var defaultCultureFileName = $"{resourceIdentifier}.txt"; var fileNames = new List <string> { defaultCultureFileName }; fileNames.AddRange( WindowsRuntimeResourceManager.GetFileNamesInDirectory(resourceDirectory). Where( file => defaultCultureFileName != file && file.EndsWith(".txt") && file.Contains(fileNameWithoutPath.Split('.')[0]))); return(fileNames); }