/// <summary> /// /// </summary> /// <param name="exogenous" /// /// ></param> /// <param name="sets"> /// /// </param> /// <returns> /// /// </returns> private static IEnumerable <VariableDefinition> SetExogenousVariables(string exogenous, IEnumerable <KeyValuePair <string, IImmutableList <string> > > sets) { sets = sets as KeyValuePair <string, IImmutableList <string> >[] ?? sets.ToArray(); foreach (Match match in VariableRegex.Matches(exogenous)) { VariableDefinition definition = new VariableDefinition( match.Groups["variable"].Value, true, match.Groups["indexes"] .Captures .Cast <Capture>() .Where(y => y.Length > 0) .Select(y => y.Value)); if (definition.Indexes.All(x => x.StartsWith("\""))) { yield return (new VariableDefinition( definition.Name, definition.IsExogenous, definition.Indexes.Select(x => x.Replace("\"", null).Replace(",", null)))); continue; } foreach (KeyValuePair <string, IImmutableList <string> > item in sets.Where(x => definition.Indexes.Contains(x.Key))) { foreach (string entry in item.Value) { yield return(new VariableDefinition(definition.Name, true, definition.Indexes.Replace(item.Key, entry).Select(x => x.Replace("\"", null).Replace(",", null)))); } } } }
public static List <string> GetVariables(string documentPath) { return(string.IsNullOrWhiteSpace(documentPath) ? new List <string>() : VariableRegex.Matches(documentPath).OfType <Match>().Select(x => VariableNameRegex.Match(x.Value).Value.Trim()).ToList()); }