CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
public class Program
{
public static void Main()
{
EquipmentFilterPack pack = new EquipmentFilterPack
{
ColumnNames = new string[] {"C1", "C2" },
keywords = new string[] { "kw1", "kw1" },
FilterTypes = new string[] { "ٍIS", "ٍIS NOT" },
Operands = new string[] { "AND", "AND" },
};
List<EquipmentListFilter> filters = new List<EquipmentListFilter>();
// With loop
/*
for (int i = 0; i < pack.ColumnNames.Count(); i++)
{
filters.Add(new EquipmentListFilter
{
ColumnName = pack.ColumnNames[i],
Keyword = pack.keywords[i],
FilterType = pack.FilterTypes[i],
Operand = pack.Operands[i],
});
}
*/
// With cross join
filters = (from a in pack.ColumnNames
from b in pack.keywords
from c in pack.FilterTypes
from d in pack.Operands
select new EquipmentListFilter
{
ColumnName = a,
Keyword = b,
FilterType = c,
Operand = d,
}).ToList();
Console.WriteLine(JsonConvert.SerializeObject(filters));
}
}
public class EquipmentListFilter
{
public string ColumnName { get; set; }
public string Keyword { get; set; }
public string Operand { get; set; }
public string FilterType { get; set; }
}
public class EquipmentFilterPack
{
public string[] ColumnNames { get; set; }
public string[] keywords { get; set; }
public string[] FilterTypes { get; set; }
public string[] Operands { get; set; }
}