次の例があります。
public class Commands
{
public int ID { get; set; }
public List<string> Alias { get; set; }
}
public class UserAccess
{
public int AccessID { get; set; }
// other stuff not needed for the question
public List<Commands> AllowedCommands { get; set; }
}
ここで、リストにエイリアスが見つからなかった場合にコマンド ID または NULL を返す方法を UserAccess に実装したいと考えました。以下の汚い例を参照してください HasCommand。
public class UserAccess
{
public ID { get; set; }
// other stuff not needed for the question
public List<Commands> AllowedCommands { get; set; }
public Commands HasCommand(string cmd)
{
foreach (Commands item in this.AllowedCommands)
{
if (item.Alias.Find(x => string.Equals(x, cmd, StringComparison.OrdinalIgnoreCase)) != null)
return item;
}
return null;
}
}
私の質問は、 HasCommand メソッドを実行または実装する最も効率的な方法は何ですか?
または、それを UserAccess に実装するより良い方法はありますか?