/// <summary> /// Queries for specific fields in a class /// </summary> /// <param name="query">Query string</param> /// <remarks> /// The field query must contain at least the field type and name to query for. Access modifier /// are optional /// Example: /// public * * /// protectd * * /// static readonly protected * * /// string m_* /// * my* // Get all fields which field name begins with my /// </remarks> public FieldQuery(string query) : base(query) { Parser = FieldQueryParser; var match = Parser.Match(query); if (!match.Success) { throw new ArgumentException( String.Format("The field query string {0} was not a valid query.", query)); } myExcludeCompilerGeneratedFields = true; SetModifierFilter(match); FieldTypeFilter = GenericTypeMapper.ConvertClrTypeNames(Value(match, "fieldType")); if (!FieldTypeFilter.StartsWith("*")) { FieldTypeFilter = "*" + FieldTypeFilter; } if (FieldTypeFilter == "*") { FieldTypeFilter = null; } NameFilter = Value(match, "fieldName"); }
private Regex CreateRegularExpressionFromTypeString(string newTypeName) { newTypeName = CreateRegexFilterFromTypeName(newTypeName); if (newTypeName.StartsWith("*")) { newTypeName = "." + newTypeName; } newTypeName = GenericTypeMapper.TransformGenericTypeNames(newTypeName, CreateRegexFilterFromTypeName); newTypeName = Regex.Escape(newTypeName); // unescape added wild cards newTypeName = newTypeName.Replace("\\.\\*", ".*"); return(new Regex(newTypeName, RegexOptions.IgnoreCase));; }
public EventQuery(string query) : base("*") { if (String.IsNullOrEmpty(query)) { throw new ArgumentNullException("query string was empty"); } if (query == "*") { return; } // Get cached regex Parser = EventQueryParser; var match = Parser.Match(query); if (!match.Success) { throw new ArgumentException( String.Format("The event query string {0} was not a valid query.", query)); } SetModifierFilter(match); EventTypeFilter = GenericTypeMapper.ConvertClrTypeNames(Value(match, "eventType")); EventTypeFilter = PrependStarBeforeGenericTypes(EventTypeFilter); if (!EventTypeFilter.StartsWith("*")) { EventTypeFilter = "*" + EventTypeFilter; } if (EventTypeFilter == "*") { EventTypeFilter = null; } NameFilter = Value(match, "eventName"); }
internal List <KeyValuePair <Regex, string> > InitArgumentFilter(string argFilter) { if (argFilter == null || argFilter == "*") { return(null); } // To query for void methods if (argFilter == "") { return(new List <KeyValuePair <Regex, string> >()); } int inGeneric = 0; bool bIsType = true; List <KeyValuePair <Regex, string> > list = new List <KeyValuePair <Regex, string> >(); StringBuilder curThing = new StringBuilder(); string curType = null; string curArgName = null; char prev = '\0'; char current; for (int i = 0; i < argFilter.Length; i++) { current = argFilter[i]; if (current != ' ') { curThing.Append(current); } if ('<' == current) { inGeneric++; } else if ('>' == current) { inGeneric--; } if (inGeneric > 0) { continue; } if (i > 0) { prev = argFilter[i - 1]; } // ignore subsequent spaces if (' ' == current && prev == ' ') { continue; } // Got end of file argument name if (',' == current && curThing.Length > 0) { curThing.Remove(curThing.Length - 1, 1); curArgName = curThing.ToString().Trim(); curThing.Length = 0; if (curType == null || curArgName == null) { throw new ArgumentException( String.Format("Method argument filter is of wrong format: {0}", argFilter)); } list.Add(AssignArrayBracketsToTypeName(curType, curArgName)); curType = null; curArgName = null; bIsType = true; } if (current == ' ' && curThing.Length > 0 && bIsType != false) { curType = GenericTypeMapper.ConvertClrTypeNames(curThing.ToString().Trim()); curThing.Length = 0; bIsType = false; } } if (curType != null) { list.Add(AssignArrayBracketsToTypeName(curType, curThing.ToString().Trim())); } return(list); }