인자로 리스트 있을때 처리
///ProductName은 리스트 구조라서 람다식안에서 foreach를 한번 돌려줬다
이렇게 해서 해결
public List<CompanyInfo> SearhCompanyInf(int value, string input, bool sort= true)
{
Func<CompanyInfo, bool> condition;
//Func<CompanyInfo, object> order;
string search = input.ToLower();
//if (value < 0 || value >= searchDropdown.options.Count)
// return new List<FixtureItemData>();
switch (value) //Dropdown value에 따라 조건 설정
{
case 0: // 제조사
condition = item => item.CompanyName.ToLower().Contains(search);
//order = item => item.CompanyName;
break;
case 1: // 조명 이름
///ProductName은 리스트 구조라서 람다식안에서 foreach를 한번 돌려줬다
condition = item =>
{
foreach (var x in item.ProductNames)
{
if (x.Contains(search))
return true;
}
return false;
};
//order = item => item.ProductNames;
//condition = item => item.FindCompany(search);
//order = item => item.ProductNames;
break;
//case 2: // 채널
// condition = item => item.channelList.Count.ToString().Contains(search);
// order = item => item.channelList.Count;
// break;
default: //모드
condition = item => item.CompanyName.ToLower().Contains(search);
//order = item => item.CompanyName;
break;
}
int i = 1;
IEnumerable<CompanyInfo> result;
result = originTable.Where(condition);
//result = sort ? result.OrderByDescending(order) : result.OrderBy(order);
result = result.Select(x => new CompanyInfo
{
CompanyName = x.CompanyName,
floorIdx = x.floorIdx,
ProductNames = x.ProductNames
});
return result.ToList();
}
///중복검색 제거 클래스
public class CompanyUiItem
{
public string companyName;
public string companyType;
public string url;
public List<string> products;
public List<string> cars;
public override bool Equals(object obj)
{
return this.companyName == ((CompanyUiItem)obj).companyName &&
this.companyType == ((CompanyUiItem)obj).companyType &&
this.cars.SequenceEqual(((CompanyUiItem)obj).cars)&&
this.products.SequenceEqual(((CompanyUiItem)obj).products)
;
}
public override int GetHashCode()
{
return companyName.GetHashCode() ^ companyType.GetHashCode() ^ cars.GetHashCode()^products.GetHashCode();
}
}
///다른방식의 검색
public List<CompanyUiItem> SearchTableData(string input)
{
if (input.Length == 0)
return originTable;
Func<CompanyUiItem,bool> condition_car; //검색 조건
Func<CompanyUiItem, bool> condition_products; //검색 조건
Func<CompanyUiItem, bool> condition_companyName; //검색 조건
Func<CompanyUiItem, bool> condition_companyType; //검색 조건
//Func<CompanyUiItem, object> order; //정렬 기준
string search = input.ToLower(); //소문자로 변환
condition_car = item => item.cars.Where(x=> x.ToLower().Contains(search)).Any();
condition_products = item => item.products.Where(x => x.ToLower().Contains(search)).Any();
condition_companyName = item => item.companyName.ToLower().Contains(search);
condition_companyType = item => item.companyType.ToLower().Contains(search);
IEnumerable<CompanyUiItem> result_car;
IEnumerable<CompanyUiItem> result_products;
IEnumerable<CompanyUiItem> result_company;
IEnumerable<CompanyUiItem> result_type;
result_car = originTable.Where(condition_car);
result_products = originTable.Where(condition_products);
result_company = originTable.Where(condition_companyName);
result_type = originTable.Where(condition_companyType);
//result = originTable.Where(condition_car).Where(condition_companyName).Where(condition_companyType).Where(condition_products);
result_car = result_car.Select(x => new CompanyUiItem
{
companyName = x.companyName,
companyType = x.companyType,
cars = x.cars,
products = x.products,
url = x.url,
});
result_products = result_products.Select(x => new CompanyUiItem
{
companyName = x.companyName,
companyType = x.companyType,
cars = x.cars,
products = x.products,
url = x.url,
});
result_company = result_company.Select(x => new CompanyUiItem
{
companyName = x.companyName,
companyType = x.companyType,
cars = x.cars,
products = x.products,
url = x.url,
});
result_type = result_type.Select(x => new CompanyUiItem
{
companyName = x.companyName,
companyType = x.companyType,
cars = x.cars,
products = x.products,
url = x.url,
});
IEnumerable<CompanyUiItem> result =
new[] { result_car, result_products, result_company, result_type }.
Where(x=>x!=null).
SelectMany(x => x).
Distinct();
//Debug.Log($"car {result_car.Count()}");
//Debug.Log($"products {result_products.Count()}");
//Debug.Log($"result_company {result_company.Count()}");
//Debug.Log($"result_type {result_type.Count()}");
//Debug.Log($"result{result.Count()}");
return result.ToList();
}
댓글 없음:
댓글 쓰기