Beispiel #1
0
        private static LocalizationInfo GetLocalizationInfo(PropertyInfo prop)
        {
            var attr = prop.GetCustomAttribute<LocalizeAttribute>();
            if(attr == null)
            {
                return null;
            }
            var info = new LocalizationInfo
            {
                ResourceName = attr.ResourceName ?? (prop.DeclaringType.Name + "_" + prop.Name)
            };

            if(info.ResourceType != null)
            {
                info.ResourceType = attr.ResourceType;
            }
            else
            {
                var parent = prop.DeclaringType.GetTypeInfo().GetCustomAttribute<LocalizeAttribute>();
                if(parent == null || parent.ResourceType == null)
                {
                    throw new ArgumentException(String.Format(
                        "The property '{0}' or its parent class '{1}' must define a ResourceType in order to be localized.",
                        prop.Name, prop.DeclaringType.Name));
                }
                info.ResourceType = parent.ResourceType;
            }

            return info;
        }
Beispiel #2
0
        private static LocalizationInfo GetLocalizationInfo(Type type)
        {
            var attr = type.GetTypeInfo().GetCustomAttribute<LocalizeAttribute>();
            if (attr == null || attr.ResourceType == null)
            {
                throw new ArgumentException(String.Format(
                    "The class '{0}' must define a ResourceType in order to be localized.",
                    type.Name));
            }
            var info = new LocalizationInfo
            {
                ResourceType = attr.ResourceType,
                ResourceName = attr.ResourceName ?? type.Name
            };

            return info;
        }