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 "); } } }