public static void TestResxForInconsistencies(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var cultureResourceDictionaries = ResxTester.GetResxDictionaries(type); var emptyEntries = ResxTester.GetEmpty(cultureResourceDictionaries); var neutralLanguage = ResxTester.ExtractNeutralLanguage(cultureResourceDictionaries, type); var missingEntries = ResxTester.GetMissing(cultureResourceDictionaries, neutralLanguage); var dispensableEntries = ResxTester.GetDispensable(cultureResourceDictionaries, neutralLanguage); if (emptyEntries.Count > 0 || missingEntries.Count > 0 || dispensableEntries.Count > 0) { var message = new StringBuilder(); message.AppendFormat("Found resx errors in \"{0}\":", type); message.AppendLine(); message.AppendLine(); ResxTester.Append(message, emptyEntries, " Empty Entries ", "Entries which do not have a value."); ResxTester.Append(message, missingEntries, " Missing Entries ", "Entries which are specified in the neutral language but are missing in the specified language."); ResxTester.Append(message, dispensableEntries, " Dispensable Entries ", "Entries which are not specified in the neutral language but are present in the specified language and should be removed."); throw new AssertException(message.ToString()); } }
private static Dictionary <string, Dictionary <string, object> > GetResxDictionaries(Type type) { var availableResxsCultureInfos = ResxTester.GetAvailableResxCultureInfos(type.Assembly); var resourceManager = new ResourceManager(type.FullName, type.Assembly); var resxDictionaries = new Dictionary <string, Dictionary <string, object> >(); for (int i = 0; i < availableResxsCultureInfos.Length; i++) { var cultureInfo = availableResxsCultureInfos[i]; var resourceSet = resourceManager.GetResourceSet(cultureInfo, true, false); if (resourceSet == null) { throw new AssertException(string.Format("The language \"{0}\" is not specified in \"{1}\".", cultureInfo.Name, type)); } var dict = new Dictionary <string, object>(); foreach (DictionaryEntry item in resourceSet) { var key = item.Key.ToString(); var value = item.Value; dict.Add(key, value); } resxDictionaries.Add(cultureInfo.Name, dict); } return(resxDictionaries); }