public void AllCodesAreUniqueToOneLanguage() { // Test that each language code only appears against one enum entry. // If more than one entry had the same code, the behaviour of which one will be returned // is undefined, so lets avoid it. Dictionary <string, Language> taken = new Dictionary <string, Language>(); foreach (Language lang in Enum.GetValues(typeof(Language))) { LanguageAttribute attr = lang.GetAttributeOfType <LanguageAttribute>(); foreach (string code in attr.Codes) { // Rather than using assert, conditional & write details to console, making fixing any problem easier if (taken.ContainsKey(code)) { Console.WriteLine("Code {0} is against multiple languages: {1} & {2}", code, taken[code], lang); Assert.Fail(); } else { taken.Add(code, lang); } } } }
private static void SearchThroughGameObject(GameObject go) { MonoBehaviour[] components = go.GetComponents <MonoBehaviour>(); //Debug.Log(components.Length); foreach (var component in components) { //Debug.Log("searching in component " + component.GetType().FullName; if (component is Text) { lines.Add(GetPath(component) + "," + (component as Text).text); Debug.Log("Found Attrib text " + GetPath(component)); } PropertyInfo[] props = component.GetType().GetProperties(); foreach (var prop in props) { object[] attrs = prop.GetCustomAttributes(true); foreach (var attr in attrs) { LanguageAttribute langAttr = attr as LanguageAttribute; if (langAttr != null) { string path = GetPath(component) + "." + prop.Name; if (langAttr.path != null) { path += " - " + langAttr.path; } lines.Add(langAttr.path); Debug.Log("Found Attrib on " + path); } } } FieldInfo[] fields = component.GetType().GetFields(); foreach (var field in fields) { object[] attrs = field.GetCustomAttributes(true); foreach (var attr in attrs) { LanguageAttribute langAttr = attr as LanguageAttribute; if (langAttr != null) { string path = GetPath(component) + "." + field.Name; if (langAttr.path != null) { path += " - " + langAttr.path; } lines.Add(langAttr.path); Debug.Log("Found Field on " + path); } } } } for (int i = 0; i < go.transform.childCount; i++) { SearchThroughGameObject(go.transform.GetChild(i).gameObject); } }
private void ShowLanguageInfo() { if (_grammar == null) return; var langAttr = LanguageAttribute.GetValue(_grammar.GetType()); if (langAttr == null) return; lblLanguage.Text = langAttr.LanguageName; lblLanguageVersion.Text = langAttr.Version; lblLanguageDescr.Text = langAttr.Description; txtGrammarComments.Text = _grammar.GrammarComments; }
public GrammarItem(Type grammarClass, string assemblyLocation) { _loading = true; Location = assemblyLocation; TypeName = grammarClass.FullName; //Get language name from Language attribute Caption = grammarClass.Name; //default caption LongCaption = Caption; var langAttr = LanguageAttribute.GetValue(grammarClass); if (langAttr != null) { Caption = langAttr.LanguageName; if (!string.IsNullOrEmpty(langAttr.Version)) { Caption += ", version " + langAttr.Version; } LongCaption = Caption; if (!string.IsNullOrEmpty(langAttr.Description)) { LongCaption += ": " + langAttr.Description; } } }