Esempio n. 1
0
        private void SetResource(Type type, object control, string controlName, Type viewType)
        {
            TextResourceKeyRule rule = RuleProvider.GetTextResourceKeyRule(type);

            if (rule == null)
            {
                return;
            }

            PropertyInfo pInfo = type.GetProperty(rule.ResourcePropertyName);

            if (pInfo == null)
            {
                return;
            }

            pInfo.SetValue(control, ResourceHandler.GetResource(rule.GetResourceKey(viewType, controlName), true));
        }
Esempio n. 2
0
        /// <summary>
        /// Set's the resources based on the reource rules for the passed <paramref name="view"/>.
        /// </summary>
        /// <param name="view">The view on which the defined resources should be set.</param>
        public void SetResources(object view)
        {
            //if no rules defined for textresources --> nothing to do
            if (!RuleProvider.AreTextResourceKeyRulesDefined)
            {
                return;
            }

            //first check for the view itself if a resource was defined which should be set.
            Type viewType            = view.GetType();
            TextResourceKeyRule rule = RuleProvider.GetTextResourceKeyRule(viewType);

            if (rule != null)
            {
                SetResource(viewType, view, null, viewType);
            }

            // second enumerate through the fields of the view to set the resources.
            EnumerateFields(viewType, info =>
            {
                SetResource(info.FieldType, info.GetValue(view), info.Name, viewType);
            });
        }