本文整理汇总了C#中List.Any方法的典型用法代码示例。如果您正苦于以下问题:C# List.Any方法的具体用法?C# List.Any怎么用?C# List.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Any方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignBatchActionResultsAsync
public async Task AssignBatchActionResultsAsync(IODataClient client,
ODataResponse batchResponse, IList<Func<IODataClient, Task>> actions, IList<int> responseIndexes)
{
var exceptions = new List<Exception>();
for (var actionIndex = 0; actionIndex < actions.Count && !exceptions.Any(); actionIndex++)
{
var responseIndex = responseIndexes[actionIndex];
if (responseIndex >= 0 && responseIndex < batchResponse.Batch.Count)
{
var actionResponse = batchResponse.Batch[responseIndex];
if (actionResponse.Exception != null)
{
exceptions.Add(actionResponse.Exception);
}
else if (actionResponse.StatusCode >= (int)HttpStatusCode.BadRequest)
{
exceptions.Add(WebRequestException.CreateFromStatusCode((HttpStatusCode)actionResponse.StatusCode));
}
else
{
await actions[actionIndex](new ODataClient(client as ODataClient, actionResponse));
}
}
}
if (exceptions.Any())
{
throw exceptions.First();
}
}
示例2: CreateWrapperFromType
private static BaseWrapper CreateWrapperFromType(Type type, Type itemType)
{
BaseWrapper retval = null;
if (type.IsArray)
{
retval = (BaseWrapper)Activator.CreateInstance(typeof(ArrayWrapper<>).MakeGenericType(itemType));
}
else
{
var types = new List<Type>(type.GetInterfaces()
.Select(h => h.IsGenericType ? h.GetGenericTypeDefinition() : h));
types.Insert(0, type.IsGenericType ? type.GetGenericTypeDefinition() : type);
if (types.Any(i => typeof(IList<>).IsAssignableFrom(i) || typeof(IList).IsAssignableFrom(i)))
{
retval = new ListWrapper();
}
else if (types.Any(y => typeof(ICollection<>).IsAssignableFrom(y)))
{
retval = (BaseWrapper)Activator.CreateInstance(typeof(CollectionWrapper<>).MakeGenericType(itemType));
}
else if (types.Any(i => typeof(IEnumerable<>).IsAssignableFrom(i) || typeof(IEnumerable).IsAssignableFrom(i)))
{
retval = new ListWrapper();
}
else if (retval == null)
{
//we gave it our best shot, but we couldn't figure out how to deserialize this badboy.
throw new MongoException(string.Format("Collection of type {0} cannot be deserialized.", type.FullName));
}
}
return retval;
}
示例3: ForbiddenWord
//method that finds word in text
static string ForbiddenWord(string text, List<string> forbiddenWords)
{
string[] array = text.Split(new char[] { ' ' });
StringBuilder sb = new StringBuilder();
foreach (var word in array)
{
if (forbiddenWords.Any(x => x == word))
{
sb.Append(new String('*', word.Length) + " ");
continue;
}
else if (forbiddenWords.Any(x => (x + ".") == word ))
{
sb.Append(new String('*', word.Length) + ".");
continue;
}
else
{
sb.Append(word + " ");
}
}
return sb.ToString();
}
示例4: AddActivitiesAndTransitions
private static void AddActivitiesAndTransitions(ProcessDefinition processDefinition, List<ActivityDefinition> activities, List<TransitionDefinition> transitions, TransitionDefinition startingTransition, List<string> finalActivities, int cutoffNestingLevel)
{
if (transitions.Any<TransitionDefinition>((TransitionDefinition t) => t.Name.Equals(startingTransition.Name, StringComparison.InvariantCulture)))
{
return;
}
ActivityDefinition to = startingTransition.To;
if (startingTransition.ForkType == TransitionForkType.ForkEnd)
{
int? nestingLevel = to.NestingLevel;
if ((nestingLevel.GetValueOrDefault() > cutoffNestingLevel ? false : nestingLevel.HasValue))
{
TransitionDefinition transitionDefinition = startingTransition.Clone() as TransitionDefinition;
transitionDefinition.IsFork = false;
transitions.Add(transitionDefinition);
if (!activities.Any<ActivityDefinition>((ActivityDefinition a) => a.Name.Equals(to.Name, StringComparison.InvariantCulture)))
{
ActivityDefinition activityDefinition = ActivityDefinition.Create(to.Name, to.State, false, true, false, false);
activities.Add(activityDefinition);
finalActivities.Add(to.Name);
}
return;
}
}
transitions.Add(startingTransition);
if (!activities.Any<ActivityDefinition>((ActivityDefinition a) => a.Name.Equals(to.Name, StringComparison.InvariantCulture)))
{
activities.Add(to.Clone() as ActivityDefinition);
}
foreach (TransitionDefinition possibleTransitionsForActivity in processDefinition.GetPossibleTransitionsForActivity(startingTransition.To, ForkTransitionSearchType.Both))
{
SubprocessUtils.AddActivitiesAndTransitions(processDefinition, activities, transitions, possibleTransitionsForActivity, finalActivities, cutoffNestingLevel);
}
}
示例5: AssetFile
public AssetFile(string file, string assetDir)
{
OriginalFile = file;
File = file.NormalizePath();
assetDir = assetDir.NormalizePath();
Name = File.Remove(0, assetDir.Length).NormalizePath();
int nameIndex = Name.LastIndexOf("/", System.StringComparison.Ordinal);
Path = nameIndex == -1 ? "" : Name.Substring(0, nameIndex);
Extensions = new List<string>();
foreach (string extension in Name.Split('.').Reverse())
{
if (!AssetPipeline.KnownExtensions.Any(i => i.NormalizePath() == extension))
break;
Extensions.Add(extension);
}
Extension = "." + string.Join(".", ((IEnumerable<string>)Extensions).Reverse());
if (Extension.Length > 1)
{
Name = Name.Remove(Name.Length - Extension.Length, Extension.Length);
}
if (Extensions.Any(i => AssetPipeline.JavascriptExtensions.Contains(i)))
{
Type = AssetType.Js;
}
else if (Extensions.Any(i => AssetPipeline.CssExtensions.Contains(i)))
{
Type = AssetType.Css;
}
}
示例6: CardsAreConsecutiveWithAce
private bool CardsAreConsecutiveWithAce(List<PokerCard> cards)
{
var aceHasPartner = cards.Any(c => c.CardFace.Value == Card.Face.Two) ||
cards.Any(c => c.CardFace.Value == Card.Face.King);
var cardsWithoutAce = cards.Where(c => c.CardFace.Value != Card.Face.Ace).ToList();
return aceHasPartner && CardsAreConsecutive(cardsWithoutAce);
}
示例7: PrintGeneration
public void PrintGeneration()
{
var orderedFirstGeneration =
new List<Cell>(_thisGeneration.OrderBy(criteria => criteria.Line).ThenBy(criteria => criteria.Column));
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
if (orderedFirstGeneration.Any(x => x.Line == i && x.Column == j && x.State == State.Head))
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("*");
}
else if (orderedFirstGeneration.Any(x => x.Line == i && x.Column == j && x.State == State.Tail))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("*");
}
else if (orderedFirstGeneration.Any(x => x.Line == i && x.Column == j && x.State == State.Conductor))
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("*");
}
else
Console.Write(" ");
}
Console.WriteLine();
}
}
示例8: MakeListOfFileTypesThatUseJustTheseTabs
private List<int> MakeListOfFileTypesThatUseJustTheseTabs(List<int> listOfTabTypesUsedInThisFile)
{
List<int> possibleFileTypes = new List<int>();
foreach (var tabType in listOfTabTypesUsedInThisFile)
{ // all of these tab types are real non zero types
var thisTabFileTypes = from x in db.WhichTabsInWhichFiles
where x.TabTypeID == tabType
select x.FileTypeID;
// now we have a list of the file types that use this tab type
if (possibleFileTypes.Any())
{ // we have started building a list
foreach (var fileType in possibleFileTypes)
{ // let's look at the list we have built of potential file types
if (!thisTabFileTypes.Contains(fileType)) possibleFileTypes.Remove(fileType);
// if the list of file types that matches the current tab type
// does not include the file type from our current list then remove
// that file type from our current list
if (!possibleFileTypes.Any()) return possibleFileTypes;
// if our current list is empty bail out
}
}
else
{ // this is the first time through
foreach (var fileType in thisTabFileTypes)
{ // let's add all of the results for this column to our comparison list
possibleFileTypes.Add(fileType);
}
}
}
return possibleFileTypes;
}
示例9: GetPlans
public static List<Plan> GetPlans()
{
if (LayoutUID == Guid.Empty)
{
return ClientManager.PlansConfiguration.AllPlans.Where(x => !x.IsNotShowPlan).ToList();
}
else
{
var plans = new List<Guid>();
var layout = ClientManager.LayoutsConfiguration.Layouts.FirstOrDefault(x => x.UID == LayoutUID);
if (layout != null)
{
foreach (var part in layout.Parts)
{
if (part.Properties != null && part.Properties is LayoutPartPlansProperties)
{
var layoutPartPlansProperties = part.Properties as LayoutPartPlansProperties;
if (layoutPartPlansProperties.Type == LayoutPartPlansType.All)
{
return ClientManager.PlansConfiguration.AllPlans.Where(x=> !x.IsNotShowPlan).ToList();
}
foreach (var planUID in layoutPartPlansProperties.Plans)
{
if (!plans.Any(x => x == planUID))
{
plans.Add(planUID);
}
}
}
}
}
return ClientManager.PlansConfiguration.AllPlans.Where(x => plans.Any(w => w == x.UID)).ToList();
}
}
示例10: btnBuscar_Click
protected void btnBuscar_Click(object sender, EventArgs e)
{
List<string> lista = new List<string>();
if (string.IsNullOrEmpty(txtDataDe.Text))
lista.Add("<b>Data Inicial</b> precisa ser preenchida");
if (string.IsNullOrEmpty(txtDataDe.Text))
lista.Add("<b>Data Final</b> precisa ser preenchida");
if (!lista.Any())
{
try
{
if (Convert.ToDateTime(txtDataDe.Text) > Convert.ToDateTime(txtDataAte.Text))
lista.Add("<b>Data Inicial</b> deve ser menor que <b>Data Final</b>");
}
catch
{
lista.Add("Data deve estar incorreta");
}
}
if (lista.Any())
CRB.BOSS.UI.Controle.Popup.Mensagem.Alerta(lista);
else
Buscar();
}
示例11: CodeCheck
public IEnumerable<QuickFix> CodeCheck(Request request)
{
var errors = new List<QuickFix>();
var syntaxErrors =
_syntaxErrorsHandler.FindSyntaxErrors(request)
.Errors.Select(
x => new QuickFix {Column = x.Column, FileName = x.FileName, Line = x.Line, Text = x.Message, LogLevel = "Error"});
errors.AddRange(syntaxErrors);
if (errors.Any())
{
return errors;
}
var semanticErrors =
_semanticErrorsHandler.FindSemanticErrors(request)
.Errors.Select(
x => new QuickFix {Column = x.Column, FileName = x.FileName, Line = x.Line, Text = x.Message , LogLevel = "Error"});
errors.AddRange(semanticErrors);
if (errors.Any())
{
return errors;
}
var codeErrors = _codeIssuesHandler.GetCodeIssues(request).QuickFixes;
errors.AddRange(codeErrors);
return errors;
}
示例12: TrySeveralTimesIfException
public static void TrySeveralTimesIfException(uint numTries, int timeSleepInMs, Action<int> action,
List<Type> ignoredExceptions = null)
{
bool ignoreAll = ignoredExceptions == null || ignoredExceptions.Count == 0;
if (!ignoreAll && ignoredExceptions.Any(type => !type.IsSubclassOf(typeof(Exception))))
throw new ArgumentException("Elements must be subclass of 'Exception'", nameof(ignoredExceptions));
if (action == null) throw new ArgumentNullException(nameof(action));
int tries = 0;
while (true)
{
try
{
++tries;
action(tries);
break;
}
catch (Exception e)
{
if (ignoreAll || ignoredExceptions.Any(ignored => e.GetType() == ignored))
{
if (tries > numTries) throw;
// Wait and retry
Thread.Sleep(timeSleepInMs);
}
else throw;
}
}
}
示例13: GenerateCbr
public Cbr GenerateCbr(List<KeyInfo> keys, bool isExport = false, KeyStoreContext context = null)
{
if (keys.Count == 0 || keys.Count > Constants.BatchLimit)
throw new ArgumentOutOfRangeException("Keys are invalid to generate CBR.");
string soldTo = keys.First().SoldToCustomerId;
if (keys.Any(k => k.SoldToCustomerId != soldTo))
throw new ApplicationException("Keys are not sold to the same customer.");
string shipTo = keys.First().ShipToCustomerId;
if (keys.Any(k => k.ShipToCustomerId != shipTo))
throw new ApplicationException("Keys are not shipped to the same customer.");
Guid customerReportId = Guid.NewGuid();
Cbr cbr = new Cbr()
{
CbrUniqueId = customerReportId,
CbrStatus = (isExport ? CbrStatus.Reported : CbrStatus.Generated),
SoldToCustomerId = soldTo,
ReceivedFromCustomerId = shipTo,
CbrKeys = keys.Select(k => new CbrKey()
{
CustomerReportUniqueId = customerReportId,
KeyId = k.KeyId,
HardwareHash = k.HardwareHash,
OemOptionalInfo = k.OemOptionalInfo.ToString(),
}).ToList()
};
cbrRepository.InsertCbrAndCbrKeys(cbr, context = null);
return cbr;
}
示例14: Send
public SendGridMessage Send(string from, IList<string> to, string subject, string body)
{
var message = SendGrid.GenerateInstance();
var errors = new List<string>();
if (to.Count > 0)
{
foreach(var recipient in to)
message.AddTo(recipient);
}
else
errors.Add("Please add at least one recipient to the email.");
message.From = new MailAddress(from);
message.Subject = subject;
message.Html = body;
try
{
if (!errors.Any())
{
var transportInstance = SMTP.GenerateInstance(new NetworkCredential(_username, _password));
transportInstance.Deliver(message);
}
}
catch(Exception ex)
{
throw ex;
}
return new SendGridMessage { Success = !errors.Any(), ErrorMessages = errors };
}
示例15: AdditionalVerify
protected override bool? AdditionalVerify(Player source, List<Card> cards, List<Player> players)
{
if (source[DuWuUsed] != 0) return false;
if ((players == null || players.Count == 0) && (cards != null && cards.Count > 0)) return false;
if (players == null || players.Count == 0) return null;
int req = players[0].Health;
if (players.Any(p => Game.CurrentGame.DistanceTo(source, p) > source[Player.AttackRange] + 1))
{
return false;
}
if (req > 0 && (cards == null || cards.Count < req)) return null;
if (req > 0 && (cards != null && cards.Count > req)) return false;
if (req > 0 && cards != null && cards.Count > 0)
{
var temp = new Sha();
temp.HoldInTemp(cards);
if (players.Any(p => Game.CurrentGame.DistanceTo(source, p) > source[Player.AttackRange] + 1))
{
temp.ReleaseHoldInTemp();
return false;
}
temp.ReleaseHoldInTemp();
}
return true;
}