public static T ParseTypeMember <T>(string expr, bool expectErrors = false) where T : EntityDeclaration { CSharpParser parser = new CSharpParser(); var members = parser.ParseTypeMembers(new StringReader(expr)); if (parser.HasErrors) { parser.ErrorPrinter.Errors.ForEach(err => Console.WriteLine(err.Message)); } Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); EntityDeclaration m = members.Single(); Type type = typeof(T); Assert.IsTrue(type.IsAssignableFrom(m.GetType()), String.Format("Parsed member was {0} instead of {1} ({2})", m.GetType(), type, m)); return((T)m); }
public static string Description(EntityDeclaration e) { if (e == null) { return(""); } var t = e.GetType(); if (e is MethodDeclaration) { return("Method"); } else if (e is ConstructorDeclaration) { return("Constructor"); } else if (e is PropertyDeclaration) { return("Property"); } else if (e is DelegateDeclaration) { return("Delegate"); } else if (e is FieldDeclaration) { return("Field"); } if (t.IsClass) { return("Class"); } else if (t.IsEnum) { return("Enum"); } else if (t.IsInterface) { return("Interface"); } else { return(""); } }
public static T ParseTypeMember <T>(string expr, bool expectErrors = false) where T : EntityDeclaration { CSharpParser parser = new CSharpParser(); var members = parser.ParseTypeMembers(expr); StringBuilder errorOutput = new StringBuilder(); foreach (var error in parser.Errors) { errorOutput.AppendLine(error.Message); } Assert.AreEqual(expectErrors, parser.HasErrors, errorOutput.ToString()); EntityDeclaration m = members.Single(); Type type = typeof(T); Assert.IsTrue(type.IsAssignableFrom(m.GetType()), String.Format("Parsed member was {0} instead of {1} ({2})", m.GetType(), type, m)); return((T)m); }
private void FillMembersComboBox() { EntityDeclaration c = GetCurrentSelectedClass(); if (c != null && _lastClassInMembersComboBox != c) { _lastClassInMembersComboBox = c; ArrayList items = new ArrayList(); bool partialMode = false; EntityDeclaration currentPart = c; //if (c.iIsPartial) //{ // CompoundClass cc = c.GetCompoundClass() as CompoundClass; // if (cc != null) // { // partialMode = true; // c = cc; // } //} // TODO lock has been removed... //lock (c) { if (c.GetType() == typeof(DelegateDeclaration)) { DelegateDeclaration de = (DelegateDeclaration)c; if (de != null) { items.Add(new ComboBoxItem(de, de.Name, (int)0, true, "delegate")); } } if (c.GetType() == typeof(TypeDeclaration)) { TypeDeclaration dd = (TypeDeclaration)c; int lastIndex = 0; IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture); foreach (EntityDeclaration m in dd.Members) { Type T = m.GetType(); if (m.GetType() == typeof(MethodDeclaration)) { items.Add(new ComboBoxItem(m, m.Name, (int)0, true, "method")); } //items.Sort(lastIndex, c.Methods.Count, comparer); lastIndex = items.Count; if (m.GetType() == typeof(ConstructorDeclaration)) { items.Add(new ComboBoxItem(m, m.Name, (int)0, true, "Class")); } //items.Sort(lastIndex, c.Methods.Count, comparer); lastIndex = items.Count; if (m.GetType() == typeof(PropertyDeclaration)) { items.Add(new ComboBoxItem(m, m.Name, (int)0, true, "property")); } //items.Sort(lastIndex, c.Properties.Count, comparer); lastIndex = items.Count; if (m.GetType() == typeof(FieldDeclaration)) { string s = m.Name; FieldDeclaration g = (FieldDeclaration)m; if (g.Variables != null) { if (g.Variables.Count > 0) { AstNodeCollection <VariableInitializer> v = g.Variables; foreach (VariableInitializer vv in v) { s = vv.Name; } } } items.Add(new ComboBoxItem(m, s, (int)0, true, "Class")); } //items.Sort(lastIndex, c.Fields.Count, comparer); lastIndex = items.Count; if (m.GetType() == typeof(EventDeclaration)) { items.Add(new ComboBoxItem(m, m.Name, (int)0, true, "Class")); } } //items.Sort(lastIndex, c.Events.Count, comparer); lastIndex = items.Count; } } _membersComboBox.BeginUpdate(); _membersComboBox.Items.Clear(); _membersComboBox.Items.AddRange(items.ToArray()); _membersComboBox.EndUpdate(); UpdateMembersComboBox(); } }