/// <summary> /// A utility class to instatiate this <see cref="ClientSideResourceManager"/> instance, /// and put it in place of the default one in the generated static class from .resx file. /// So you can continue using the generated class, and get correct culture fallback at client side power /// from <see cref="ClientSideResourceManager"/> at the same time. /// </summary> /// <param name="classType">Class type of the generated class from .resx file. /// Be sure to generate from only the neutral one.</param> /// <param name="overrideClassNamespace">class namespace of the type if resource namespace is override by resource generator tool. /// Be sure to generate from only the neutral one.</param> /// <param name="resourceFieldName">resourceFileName to be overriten, defauklts to resourceMan</param> public static void HackResourceClass(Type classType, string overrideClassNamespace, string resourceFieldName = "resourceMan") { var newRm = new ClientSideResourceManager(classType.Assembly, overrideClassNamespace); var fieldToHack = classType.GetField(resourceFieldName, BindingFlags.Static | BindingFlags.NonPublic); fieldToHack.SetValue(null, newRm); }
/// <summary> /// A utility class to instatiate this <see cref="ClientSideResourceManager"/> instance, /// and put it in place of the default one in the generated static class from .resx file. /// So you can continue using the generated class, and get correct culture fallback at client side power /// from <see cref="ClientSideResourceManager"/> at the same time. /// </summary> /// <param name="classType">Class type of the generated class from .resx file. /// Be sure to generate from only the neutral one.</param> public static void HackResourceClass(Type classType) { var newRm = new ClientSideResourceManager(classType.Assembly, classType.FullName); var fieldToHack = classType.GetField("resourceMan", BindingFlags.Static | BindingFlags.NonPublic); fieldToHack.SetValue(null, newRm); }
///// <summary> ///// When all Resources are registered, we hack them by calling Startup ///// </summary> public static void Startup() { foreach (var res in _resources) { try { ClientSideResourceManager.HackResourceClass(res); } catch (Exception e) { Console.Error.WriteLine(e); } } }