uploadDataList
List<string> keyList = new List<string>();
foreach (PropertyInfo pi in propertys)
{
KeyAttribute keyAttribute = (KeyAttribute)Attribute.GetCustomAttribute(t.GetType(), typeof(KeyAttribute));
if (keyAttribute != null)
{
keyList.Add(t.GetType().Name);
}
}
uj5u.com熱心網友回復:
沒能理解你代碼的用意。不過要判斷重復,可以用HashSet。var keyList = new HashSet<string>();
foreach (PropertyInfo pi in properties)
{
var keyAttribute = (KeyAttribute)Attribute.GetCustomAttribute(t.GetType(), typeof(KeyAttribute));
if (keyAttribute != null)
{
if (!keyList.Add(t.GetType().Name))
{
throw new InvalidOperationException($"Key '{t.GetType().Name}'重復");
}
}
}
uj5u.com熱心網友回復:
我的那段代碼是不知道怎么寫隨便寫的,不具備參考價值,只是把key特性的name都找出來了
比如我有uploadDataList,需要反射找帶key特性的屬性,然后判斷key值組合是否重復,重復的就提取list出來
var repetitionList=uploadDataList.GroupBy(m=>new { NCMP = m.NCMP, PINO = m.PINO }) .Where(g=>g.Count()>1).Select(y=>y.Key).ToList();
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/89099.html
標籤:LINQ
