public sealed class NewCulture
{
private static CultureInfo uiCultureInfo;
private NewCulture() { }
[CultureSetter]
public static CultureInfo UICultureInfo
{
get
{
return uiCultureInfo;
}
set
{
if (uiCultureInfo != value)
{
uiCultureInfo = value;
StringResource.StringRes.Culture = value;
}
}
}
}
_______________________________________
[AttributeUsage(AttributeTargets.Property)]
public class CultureSetterAttribute : Attribute
{
}
_______________________________________
private void SetCultureInfo(Type type, CultureAttribute attri)
{
if (type != null )
{
BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
PropertyInfo[] propertyInfos = type.GetProperties(flags);
if (propertyInfos != null)
{
foreach (PropertyInfo property in propertyInfos)
{
if (property.CanWrite &&
property.PropertyType.Equals(typeof(CultureInfo)))
{
object[] attributes = property.GetCustomAttributes(typeof(CultureSetterAttribute), false);
if (attributes != null && attributes.Length == 1)
{
property.SetValue(null, NewUICulture.UICulture, null);
}
}
}
}
}
}