private void BtnReadSelectors_Click(object sender, RoutedEventArgs e) { string[] selectors = txtSelectors.Text.Split(';'); foreach (var selector in selectors) { if (!selector.Equals("") && CustomSelectors.Any(s => s.Equals(selector)) == false) { CustomSelectors.Add(selector); } } }
private void CustomSelector(string name, bool hasArguments) { DelegateInfo deleg; if (!CustomSelectors.TryGetValue(name, out deleg)) { throw new FormatException(string.Format("Unknown pseudo-selector '{0}'.", name)); } var formalParameters = deleg.ParameterTypes; var actualParameters = new object[formalParameters.Count]; for (int i = 0; i < formalParameters.Count; i++) { if (i != 0) { Read(ToTokenSpec(Token.Semicolon())); Read(ToTokenSpec(TokenKind.WhiteSpace)); } Type type = (Type)formalParameters[i]; var typeName = type.Name; if (typeName == TypeCode.String.ToString()) { actualParameters[i] = Read(ToTokenSpec(TokenKind.String)).Text; } else if ( typeName == TypeCode.Byte.ToString() || typeName == TypeCode.UInt16.ToString() || typeName == TypeCode.UInt32.ToString() || typeName == TypeCode.UInt64.ToString() || typeName == TypeCode.SByte.ToString() || typeName == TypeCode.Int16.ToString() || typeName == TypeCode.Int32.ToString() || typeName == TypeCode.Int64.ToString() ) { actualParameters[i] = int.Parse(Read(ToTokenSpec(TokenKind.Integer)).Text, CultureInfo.InvariantCulture); } else if (type.GetGenericTypeDefinition() == typeof(Selector <>)) { actualParameters[i] = ParseSubGenerator().Selector; } else { throw new ArgumentException(string.Format("Unsupported parameter type for custom selector '{0}'", name)); } } var selector = deleg.Method.DynamicInvoke(actualParameters); _generator.CustomSelector(selector); }