Hi
I have a Dictionary<stri ng, List<string>>, which i have successfully
filled. My problem is I need to create a filter expression using all
possible permutations of its contents.
i.e. the dictionary essentially creates the following array:
Key Value
Column1 1
Column1 2
Column2 17
I want to then create an number of filter expressions:
Column1 = 1 AND Column2 = 17
Column1 = 2 AND Column2 = 17
I used a permutation library i found PermuteUtils (
) and the following code:
Dictionary<stri ng, List<string>dis tinctCellValues = new
Dictionary<stri ng, List<string>>() ;
ArrayList queryClause = new ArrayList();
{
foreach (KeyValuePair<s tring, List<string>kvp in
distinctCellVal ues)
{
foreach (string value in kvp.Value)
{
queryClause.Add (kvp.Key + " = " + value);
}
}
//Convert array to string array
string[] queryClauseStri ng = queryClause.ToA rray(typeof(str ing)) as
string[];
CreateFilterPer mutations<strin g>(queryClauseS tring,
distinctCellVal ues.Count);
}
private void CreateFilterPer mutations<T>(IE numerable<Tinpu t, int
count)
{
foreach (IEnumerable<Tp ermutation in
PermuteUtils.Pe rmute<T>(input, count))
{
foreach (T i in permutation)
{
filterExpressio ns.Add(i);
}
}
}
This seems to work OK as far as running the CreateFilterPer mutations
method, where i just cannot get it to do what i need.
I've manage to get myself very confused by all this, and this only
contains 2 columns. Potentially i could need to be generating
permutations of 10 columns/values or more!! I'm hoping someone can
straighten out my thoughts before my head explodes!!
Thanks
I have a Dictionary<stri ng, List<string>>, which i have successfully
filled. My problem is I need to create a filter expression using all
possible permutations of its contents.
i.e. the dictionary essentially creates the following array:
Key Value
Column1 1
Column1 2
Column2 17
I want to then create an number of filter expressions:
Column1 = 1 AND Column2 = 17
Column1 = 2 AND Column2 = 17
I used a permutation library i found PermuteUtils (
) and the following code:
Dictionary<stri ng, List<string>dis tinctCellValues = new
Dictionary<stri ng, List<string>>() ;
ArrayList queryClause = new ArrayList();
{
foreach (KeyValuePair<s tring, List<string>kvp in
distinctCellVal ues)
{
foreach (string value in kvp.Value)
{
queryClause.Add (kvp.Key + " = " + value);
}
}
//Convert array to string array
string[] queryClauseStri ng = queryClause.ToA rray(typeof(str ing)) as
string[];
CreateFilterPer mutations<strin g>(queryClauseS tring,
distinctCellVal ues.Count);
}
private void CreateFilterPer mutations<T>(IE numerable<Tinpu t, int
count)
{
foreach (IEnumerable<Tp ermutation in
PermuteUtils.Pe rmute<T>(input, count))
{
foreach (T i in permutation)
{
filterExpressio ns.Add(i);
}
}
}
This seems to work OK as far as running the CreateFilterPer mutations
method, where i just cannot get it to do what i need.
I've manage to get myself very confused by all this, and this only
contains 2 columns. Potentially i could need to be generating
permutations of 10 columns/values or more!! I'm hoping someone can
straighten out my thoughts before my head explodes!!
Thanks
Comment