Home > Net >  According to the characteristics to determine whether a combination key repeat
According to the characteristics to determine whether a combination key repeat

Time:09-27

 
UploadDataList
List KeyList=new List (a);
The foreach (PropertyInfo PI in propertys)
{
The KeyAttribute KeyAttribute=(KeyAttribute Attribute. GetCustomAttribute (t.G etType (), typeof (KeyAttribute));
If (keyAttribute!=null)
{
KeyList. Add (t.G etType (). The Name).
}
}

CodePudding user response:

Failed to understand your code, but to tell if repeated, can use HashSet,

 var keyList=new HashSet (a); 
The foreach (PropertyInfo PI in properties)
{
Var keyAttribute=(keyAttribute Attribute. GetCustomAttribute (t.G etType (), typeof (keyAttribute));
If (keyAttribute!=null)
{
if (! KeyList. Add (t.G etType (). The Name))
{
Throw new InvalidOperationException ($" Key '{t.G etType (). The Name}' repeat ");
}
}
}

CodePudding user response:

reference 1st floor github_36000833 response:
failed to understand your code, but to tell if repeated, can use HashSet,

 var keyList=new HashSet (a); 
The foreach (PropertyInfo PI in properties)
{
Var keyAttribute=(keyAttribute Attribute. GetCustomAttribute (t.G etType (), typeof (keyAttribute));
If (keyAttribute!=null)
{
if (! KeyList. Add (t.G etType (). The Name))
{
Throw new InvalidOperationException ($" Key '{t.G etType (). The Name}' repeat ");
}
}
}

My game code is don't know how to write write casually, do not have reference value, only to find the key features of the name is
Such as I have uploadDataList, need reflection with the key characteristic of attribute, and then determine whether the key value combination repeat, repeat the pulls a list
Var repetitionList=uploadDataList. GroupBy (m=& gt; New {NCMP=m.N CMP, PINO=m.P INO}) Where (g=& gt; Right to mount () & gt; 1). Select (y=& gt; Y.K ey). ToList ();
  •  Tags:  
  • LINQ
  • Related