public static void Enable(Type resourcesType)
        {
            if (null == resourcesType)
            {
                throw new ArgumentNullException("resourcesType");
            }

            // Get the ResourceManager property
            var resourceManagerProperty = resourcesType.GetProperty("ResourceManager", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
            if (null == resourceManagerProperty)
            {
                throw new NotSupportedException("RESX managed wrapper class does not contain the expected internal/public static ResourceManager property.");
            }

            // Get the ResourceManager value (ensures the resourceMan field gets initialized)
            var resourceManagerValue = resourceManagerProperty.GetValue(null, null) as ResourceManager;
            if (null == resourceManagerValue)
            {
                throw new NotSupportedException("RESX managed wrapper class returned null for the ResourceManager property getter.");
            }

            // Get the resourceMan field
            var resourceManField = resourcesType.GetField("resourceMan", BindingFlags.Static | BindingFlags.NonPublic);
            if (null == resourceManField)
            {
                throw new NotSupportedException("RESX managed wrapper class does not contain the expected private static resourceMan field.");
            }

            // Create a substitute ResourceManager to do the pseudo-localization
            var resourceManSubstitute = new PseudoLocalizerResourceManager(resourceManagerValue.BaseName, resourcesType.Assembly);

            // Replace the resourceMan field value
            resourceManField.SetValue(null, resourceManSubstitute);
        }
Exemple #2
0
        public static void Enable(Type resourcesType)
        {
            if (null == resourcesType)
            {
                throw new ArgumentNullException("resourcesType");
            }

            // Get the ResourceManager property
            var resourceManagerProperty = resourcesType.GetProperty("ResourceManager", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);

            if (null == resourceManagerProperty)
            {
                throw new NotSupportedException("RESX managed wrapper class does not contain the expected internal/public static ResourceManager property.");
            }

            // Get the ResourceManager value (ensures the resourceMan field gets initialized)
            var resourceManagerValue = resourceManagerProperty.GetValue(null, null) as ResourceManager;

            if (null == resourceManagerValue)
            {
                throw new NotSupportedException("RESX managed wrapper class returned null for the ResourceManager property getter.");
            }

            // Get the resourceMan field
            var resourceManField = resourcesType.GetField("resourceMan", BindingFlags.Static | BindingFlags.NonPublic);

            if (null == resourceManField)
            {
                throw new NotSupportedException("RESX managed wrapper class does not contain the expected private static resourceMan field.");
            }

            // Create a substitute ResourceManager to do the pseudo-localization
            var resourceManSubstitute = new PseudoLocalizerResourceManager(resourceManagerValue.BaseName, resourcesType.Assembly);

            // Replace the resourceMan field value
            resourceManField.SetValue(null, resourceManSubstitute);
        }