本文整理汇总了C#中ICollection.All方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.All方法的具体用法?C# ICollection.All怎么用?C# ICollection.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.All方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateRooms
public static IEnumerable<Room> GenerateRooms(Random _random, Rct _rct, ICollection<Point> _objects, Point _blockId)
{
var ableVert = _rct.Width - MIN_ROOM_SIZE*2;
var ableHor = _rct.Height - MIN_ROOM_SIZE*2;
if ((ableHor > 1 || ableVert > 1) && (_rct.Width*_rct.Height < MIN_ROOM_SQUARE || _rct.Width > MAX_DIV_SIZE || _rct.Height > MAX_DIV_SIZE || _random.Next(_rct.Width + _rct.Height) > MIN_ROOM_SIZE))
{
var divVert = 0;
var divHor = 0;
while (divVert == divHor)
{
divVert = ableVert > 0 ? _random.Next(ableVert + 1) : 0;
divHor = ableHor > 0 ? _random.Next(ableHor + 1) : 0;
}
var rects = new List<Rct>();
if (divVert > divHor)
{
int vert;
do
{
vert = MIN_ROOM_SIZE + _random.Next(ableVert);
var val = vert;
if (_objects.All(_point => _point.X != (_rct.Left + val))) break;
} while (true);
rects.Add(new Rct(_rct.Left, _rct.Top, vert, _rct.Height));
rects.Add(new Rct(_rct.Left + vert + 1, _rct.Top, _rct.Width - (vert + 1), _rct.Height));
}
else
{
int hor;
do
{
hor = MIN_ROOM_SIZE + _random.Next(ableHor);
var val = hor;
if (_objects.All(_point => _point.Y != (_rct.Top + val))) break;
} while (true);
rects.Add(new Rct(_rct.Left, _rct.Top, _rct.Width, hor));
rects.Add(new Rct(_rct.Left, _rct.Top + hor + 1, _rct.Width, _rct.Height - (hor + 1)));
}
foreach (var rct in rects)
{
if (rct.Width > _rct.Width || rct.Height > _rct.Height)
{
throw new ApplicationException("Доля больше чем место под нее");
}
foreach (var room in GenerateRooms(_random, rct, _objects, _blockId))
{
yield return room;
}
}
yield break;
}
yield return MakeRoom(_rct, _random, _objects, _blockId);
}
示例2: AddIfPrime
private static void AddIfPrime(ICollection<long> primes, int i)
{
if (primes.All(x => i % x != 0))
{
primes.Add(i);
}
}
示例3: GetUniqueName
public static string GetUniqueName(ICollection<Property> props)
{
foreach (var suffix in Suffixes)
{
var unique = suffix;
if (props.All(p => p.Name != unique))
return unique;
}
for (var i = 0; i < 100; i++)
{
var unique = "A" + i;
if (props.All(p => p.Name != unique))
return unique;
}
throw new InvalidOperationException("Could not find a unique name for property");
}
示例4: VerifySeedAcceptedNodes
private void VerifySeedAcceptedNodes(
IEnumerable<CstNode> seedCsts, ICollection<CstNode> uppermostSeedAcceptedNodes,
LearningExperiment oracle) {
var anotherUppermostSeedAcceptedNodes = seedCsts
.SelectMany(cst => LearningExperimentUtil
.GetUppermostNodesByNames(cst, SelectedNodeNames))
.Where(oracle.ProtectedIsAcceptedUsingOracle)
.ToList();
var b1 = !uppermostSeedAcceptedNodes.All(oracle.IsAcceptedUsingOracle);
var b2 = anotherUppermostSeedAcceptedNodes
.Select(node => node.AncestorWithSingleChild())
.Any(e => !uppermostSeedAcceptedNodes.Contains(e));
var b3 = uppermostSeedAcceptedNodes.Count != anotherUppermostSeedAcceptedNodes.Count;
Console.WriteLine("Initial: " + string.Join(", ", oracle.OracleNames));
Console.WriteLine("Learned: " + string.Join(", ", SelectedNodeNames));
if (b1 || b2 || b3) {
Console.WriteLine("--------------------------------------------------");
foreach (var e in uppermostSeedAcceptedNodes) {
Console.WriteLine(e);
}
Console.WriteLine("--------------------------------------------------");
foreach (var e in anotherUppermostSeedAcceptedNodes) {
Console.WriteLine(e);
}
throw new Exception("Wrong Oracle.");
}
}
示例5: ValidateAll
public void ValidateAll(ICollection<object> objectsToValidate)
{
var canValidateAll = objectsToValidate
.All(obj => _validator
.CanValidateInstancesOfType(obj.GetType()));
if (!canValidateAll)
throw new ArgumentException(
$"Not all objects can be validated by {_validator.GetType().Name}");
var errors = new List<string>();
foreach (var obj in objectsToValidate)
{
var result = _validator.Validate(obj);
if (!result.IsValid)
{
errors.AddRange(
result
.Errors
.Select(Mapping.FailureTransformerFunc));
}
}
if (errors.Any())
{
throw new ValidationException(
"Error validating collection of objects",
errors);
}
}
示例6: Compute
private void Compute(string expression, string key, ICollection<IGrouping<string, ParentChildCategory>> grouping, ICollection<string> categoryList)
{
if (grouping.All(g => g.Key != key) && expression.StartsWith(Separator))
categoryList.Add(expression.TrimStart(Separator.ToArray()));
else if(grouping.Any(g => g.Key == key))
grouping.Single(g => g.Key == key).ToList().ForEach(c => Compute(expression + Separator + c.Child, c.Child, grouping, categoryList));
}
示例7: LoadMetaData
private void LoadMetaData(ICollection<IControllerMetaData> controllersMetaContainers, IEnumerable<Type> types, IEnumerable<Type> typesToIgnore)
{
foreach (var t in types.Where(t => typesToIgnore.All(x => x.FullName != t.FullName) &&
controllersMetaContainers.All(x => x.ControllerType != t)))
{
BuildControllerMetaData(controllersMetaContainers, t);
}
}
示例8: StraightFlushCheck
public static bool StraightFlushCheck(ICollection<Card> cardsinHand)
{
// Are all cards in hand of the same Rank?
var firstCard = cardsinHand.First();
if (cardsinHand.All(s => s.Rank == firstCard.Rank))
return true;
return false;
}
示例9: DetectNotification
/// <summary>
/// Checks for any new tracks entered airspace
/// track entered event raised if any new tracks exist
/// new event logged to the file
/// </summary>
/// <param name="oldTransponderDatas"></param>
/// <param name="newTransponderDatas"></param>
public override void DetectNotification(ICollection<IATMTransponderData> oldTransponderDatas, ICollection<IATMTransponderData> newTransponderDatas)
{
foreach (var item in newTransponderDatas.Where(item => oldTransponderDatas.All(t => t.Tag != item.Tag)))
{
const string logString = " TrackEnteredAirspace Notification ";
Notify(new NotificationEventArgs(item.Tag, "TrackEnteredAirspace", item.Timestamp));
_atmLog.Log(item.Timestamp + logString + item.Tag);
}
}
示例10: CreateAuthenticatedClaimsIdentity
/// <summary>
/// Creates new authenticated claims identity by using the provided claims and authentication type.
/// </summary>
/// <param name="claims">Collection of claims to add to the authenticated identity.</param>
/// <param name="authenticationType">Authentication type to use for the authenticated identity.</param>
/// <param name="nameType">Type of the username claim. Default is <see cref="ClaimTypes.Name"/>.</param>
/// <param name="roleType">Type of the role claim. Default is <see cref="ClaimTypes.Role"/>.</param>
/// <returns>Mocked <see cref="ClaimsIdentity"/>.</returns>
protected static ClaimsIdentity CreateAuthenticatedClaimsIdentity(
ICollection<Claim> claims = null,
string authenticationType = null,
string nameType = null,
string roleType = null)
{
claims = claims ?? new List<Claim>();
authenticationType = authenticationType ?? DefaultAuthenticationType;
nameType = nameType ?? DefaultNameType;
roleType = roleType ?? DefaultRoleType;
if (claims.All(c => c.Type != ClaimTypes.NameIdentifier))
{
claims.Add(new Claim(ClaimTypes.NameIdentifier, DefaultIdentifier));
}
if (claims.All(c => c.Type != nameType))
{
claims.Add(new Claim(nameType, DefaultUsername));
}
return new ClaimsIdentity(claims, authenticationType, nameType, roleType);
}
示例11: SetNewSolution
/// <summary>
/// Sets new solution of the problem.
/// </summary>
/// <param name="nodes">Collection of nodes representing new solution.</param>
public void SetNewSolution(ICollection<Node> nodes)
{
if (nodes == null) throw new ArgumentException(nameof(nodes));
if (!IsInitialized) return;
if (nodes.All(n => Graph.ContainsNode(n.Key) && Graph.Equals(n.Parent)))
{
lock (_currentCover)
{
_currentCover = new HashSet<Node>(nodes);
}
}
else
{
throw new ProblemException("Setting new solution", "Graph mismatch or node key not found");
}
}
示例12: GetAuthenticatedClaimsIdentity
private static ClaimsIdentity GetAuthenticatedClaimsIdentity(
ICollection<Claim> claims = null,
string authenticationType = DefaultAuthenticationType)
{
claims = claims ?? new List<Claim>();
if (claims.All(c => c.Type != ClaimTypes.NameIdentifier))
{
claims.Add(new Claim(ClaimTypes.NameIdentifier, DefaultIdentifier));
}
if (claims.All(c => c.Type != ClaimTypes.Name))
{
claims.Add(new Claim(ClaimTypes.Name, DefaultUsername));
}
return new ClaimsIdentity(claims, authenticationType);
}
示例13: ResolveHandlerPath
public static string ResolveHandlerPath(ICollection<Type> types)
{
var tenant = ASC.Core.CoreContext.TenantManager.GetCurrentTenant();
var version = "";
var resultPath = "";
var listHandlers = new List<ClientScript>();
foreach (var type in types)
{
if (!typeof(ClientScript).IsAssignableFrom(type))
{
throw new ArgumentException(string.Format("{0} is not assignable to ClientScriptHandler", type));
}
var instance = (ClientScript)Activator.CreateInstance(type);
version += instance.GetCacheHash();
resultPath = resultPath + type.FullName.ToLowerInvariant().Replace('.', '_');
listHandlers.Add(instance);
}
resultPath = HttpServerUtility.UrlTokenEncode(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(resultPath)));
if (!Hash.ContainsKey(resultPath))
{
Hash[resultPath] = new ClientScriptHandler {ClientScriptHandlers = listHandlers};
}
if (tenant != null && types.All(r => r.BaseType != typeof(ClientScriptLocalization)))
version = String.Join("_",
new[]
{
tenant.TenantId.ToString(CultureInfo.InvariantCulture),
tenant.Version.ToString(CultureInfo.InvariantCulture),
tenant.LastModified.Ticks.ToString(CultureInfo.InvariantCulture),
version
});
var versionHash = HttpServerUtility.UrlTokenEncode(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(version)));
return new Uri(VirtualPathUtility.ToAbsolute("~/clientscriptbundle/" + versionHash + "/" + resultPath + ClientSettings.ClientScriptExtension),
UriKind.Relative).ToString();
}
示例14: VillagesContextMenu
public VillagesContextMenu(Map map, ICollection<Village> villages, Action<VillageType> onVillageTypeChangeDelegate = null)
{
_villages = villages;
_map = map;
_onVillageTypeChangeDelegate = onVillageTypeChangeDelegate;
_menu = JanusContextMenu.Create();
// TODO: hehe, the ActiveVillageManipulator takes the first player and selects all his villages...
//if (map.Display.IsVisible(_villages))
//{
// _menu.AddCommand("Pinpoint", OnPinPoint);
//}
//_menu.AddCommand("Pinpoint && Center", OnPinpointAndCenter, Properties.Resources.TeleportIcon);
//_menu.AddSeparator();
_menu.AddSetVillageTypeCommand(OnVillageTypeChange, null);
_menu.AddCommand("Remove purpose", OnRemovePurpose);
if (World.Default.Settings.Church)
{
VillageContextMenu.AddChurchCommands(_menu, null, ChurchChange_Click);
}
_menu.AddSeparator();
if (!World.Default.You.Empty && villages.All(x => x.Player == World.Default.You))
{
_menu.AddCommand("Defend these villages", OnAddTargets, Properties.Resources.swordsman);
AttackersPoolContextMenuCommandCreator.Add(_menu, _villages);
}
else
{
_menu.AddCommand("Attack these villages", OnAddTargets, Properties.Resources.barracks);
}
_menu.AddSeparator();
_menu.AddCommand("BBCode", OnBbCode, Properties.Resources.clipboard);
}
示例15: GeneticAlgorithm
/// <summary>
/// Creates instance of genetic algorithm
/// </summary>
/// <param name="graph">Graph on which algorithm will operate</param>
/// <param name="problem">Problem for which algorithm will attempt to find solution</param>
/// <param name="geneticOperators">Genetic operators used for breeding new generations</param>
/// <param name="settings">General settings for solution finding process</param>
/// <param name="startingPopulation">Starting population for algorithm</param>
//TODO: Introduce SavedState complex type
public GeneticAlgorithm(Graph graph, IProblem problem, GeneticOperators geneticOperators,
GeneticAlgorithmSettings settings, ICollection<Individual> startingPopulation = null,
uint currentGeneration = 0, Guid? id = null)
: base(graph, problem, id)
{
if (geneticOperators == null)
throw new ArgumentNullException(nameof(geneticOperators));
if (!geneticOperators.IsValid())
throw new ArgumentException("Genetic operators are not valid", nameof(geneticOperators));
if (settings == null)
throw new ArgumentNullException(nameof(settings));
GeneticOperators = geneticOperators;
Settings = settings;
if (startingPopulation == null || startingPopulation.Count == 0 || !startingPopulation.All(IsIndividualValid))
GenerateInitialPopulation();
else
{
CurrentPopulation = new SortedSet<Individual>();
foreach (var element in startingPopulation)
CurrentPopulation.Add(element);
}
CurrentGeneration = currentGeneration;
}