/// <summary> /// Initializes the <see cref="EnglishGrammar" /> class. /// </summary> static EnglishGrammar() { //some of the magic of this class //is that it uses the NamedFormatHelper //on all STATIC fields. //so that it can replace text it finds with values from other properties. var members = typeof(EnglishGrammar).GetMembers(); foreach (var f in members.OfType <FieldInfo>().Where(x => x.FieldType == typeof(string))) { if (f.IsStatic) //check to see if field is static { f.SetValue(null, NamedFormatHelper.NamedFormat(f.GetValue(null) as string, typeof(EnglishGrammar))); } } foreach (var p in members.OfType <PropertyInfo>().Where(x => x.PropertyType == typeof(string))) { //check to see if property has a static getter if (p.CanRead && p.CanWrite && p.GetSetMethod().IsStatic) { p.SetValue(null, NamedFormatHelper.NamedFormat(p.GetValue(null, null) as string, typeof(EnglishGrammar)), null); } } }
static GermanGrammar() { var members = typeof(GermanGrammar).GetMembers(); foreach (var f in members.OfType <FieldInfo>().Where(x => x.FieldType == typeof(string))) { f.SetValue(null, NamedFormatHelper.NamedFormat(f.GetValue(null) as string, typeof(GermanGrammar))); } foreach (var p in members.OfType <PropertyInfo>().Where(x => x.PropertyType == typeof(string))) { if (p.CanRead && p.CanWrite) { p.SetValue(null, NamedFormatHelper.NamedFormat(p.GetValue(null, null) as string, typeof(GermanGrammar)), null); } } }