本文整理汇总了C#中HashSet.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.ForEach方法的具体用法?C# HashSet.ForEach怎么用?C# HashSet.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.ForEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AlbumsFromCommaSeparatedValuesAndUserId
public async Task<IEnumerable<Album>> AlbumsFromCommaSeparatedValuesAndUserId(string albumsAsCommaSeparatedValues, string userId)
{
if (string.IsNullOrWhiteSpace(albumsAsCommaSeparatedValues))
{
return Enumerable.Empty<Album>();
}
var albumsValues = new HashSet<string>();
albumsAsCommaSeparatedValues.Split(new[] { GlobalConstants.CommaSeparatedCollectionSeparator }, StringSplitOptions.RemoveEmptyEntries)
.ToList()
.ForEach(val =>
{
albumsValues.Add(val.Trim());
});
var resultAlbum = await this.albums
.All()
.Where(a => (albumsValues.Contains(a.Name.ToLower()) ||
albumsValues.Contains(a.Id.ToString())) &&
a.Creator.Id == userId)
.ToListAsync();
(await this.albums
.All()
.Where(a => (albumsValues.Contains(a.Name.ToLower()) ||
albumsValues.Contains(a.Id.ToString())) &&
a.Creator.Id == userId)
.Select(a => a.Name.ToLower())
.ToListAsync())
.ForEach(a => albumsValues.Remove(a));
var idValues = new List<string>();
albumsValues.ForEach(v =>
{
int id;
var isId = int.TryParse(v, out id);
if (isId)
{
idValues.Add(v);
}
});
idValues.ForEach(a => albumsValues.Remove(a));
albumsValues.ForEach(tagName => resultAlbum.Add(new Album() { Name = tagName }));
return resultAlbum;
}
示例2: SavePathList
/// <summary>
/// 正しく読み込めた棋譜のリストを保存します。
/// </summary>
public static void SavePathList(string filepath, HashSet<string> pathList)
{
using (var writer = new StreamWriter(filepath, false, Encoding.UTF8))
{
pathList.ForEach(_ => writer.WriteLine(_));
}
}
示例3: TagsFromCommaSeparatedValues
public async Task<IEnumerable<Tag>> TagsFromCommaSeparatedValues(string tagsAsCommaSeparatedValues)
{
if (string.IsNullOrWhiteSpace(tagsAsCommaSeparatedValues))
{
return Enumerable.Empty<Tag>();
}
var tagNames = new HashSet<string>();
tagsAsCommaSeparatedValues.Split(new[] { GlobalConstants.CommaSeparatedCollectionSeparator }, StringSplitOptions.RemoveEmptyEntries)
.ToList()
.ForEach(tag =>
{
tagNames.Add(tag.ToLower().Trim());
});
var resultTags = await this.tags
.All()
.Where(t => tagNames.Contains(t.Name))
.ToListAsync();
(await this.tags
.All()
.Where(t => tagNames.Contains(t.Name.ToLower()))
.Select(t => t.Name.ToLower())
.ToListAsync())
.ForEach(t => tagNames.Remove(t));
tagNames.ForEach(tagName => resultTags.Add(new Tag { Name = tagName }));
return resultTags;
}
示例4: OnServerTestingFinished
private void OnServerTestingFinished(object sender, EventArgs e)
{
var hashset = new HashSet<MissingProduct>();
this.manager.Cache.MissingProductsPerServer.Values.ForEach(hashset.UnionWith);
this.MissingProducts.Clear();
hashset.ForEach(this.MissingProducts.Add);
}
示例5: RelationshipDiscoverer
/**
* RelationshipDiscoverer Constructor
*/
public RelationshipDiscoverer(HashSet<Type> Models)
{
this.Discovered = new List<Relation>();
// Loop through all models in the context.
Models.ForEach(model =>
{
// Loop through all mapped props of the model
Model.Dynamic(model).MappedProps.ForEach(prop =>
{
// Ignore primative types.
if (TypeMapper.IsClrType(prop.PropertyType))
{
return;
}
// Get the relationship discriptor.
Relation? relation;
if (TypeMapper.IsListOfEntities(prop))
{
if ((relation = this.IsManyToMany(prop)) == null)
{
if ((relation = this.IsManyToOne(prop)) == null)
{
throw new UnknownRelationshipException(prop);
}
}
}
else
{
// Make sure the type is a Graceful Model.
// If this exception throws, it probably means the
// TypeMapper has failed us.
if (!prop.PropertyType.IsSubclassOf(typeof(Model)))
{
throw new UnknownRelationshipException(prop);
}
if ((relation = this.IsOneToMany(prop)) == null)
{
if ((relation = this.IsOneToOne(prop)) == null)
{
throw new UnknownRelationshipException(prop);
}
}
}
// Add it to our discovered list.
this.Discovered.Add((Relation)relation);
});
});
}
示例6: InitializeCategories
void InitializeCategories(ISession session)
{
var categories = new HashSet<Category>
{
new Category {Name = "Backpacks", Description = "Backpacks"},
new Category {Name = "Bikes", Description = "Bikes"},
new Category {Name = "Boots", Description = "Boots"},
new Category {Name = "Hats & Helmets", Description = "Hats & Helmets"},
new Category {Name = "Hiking Gear", Description = "Hiking Gear"},
new Category {Name = "Sunglasses", Description = "Sunglasses"}
};
categories.ForEach(category => session.Save(category));
_categories = categories;
}
示例7: AddHighlightings
private void AddHighlightings()
{
var variables = new HashSet<IVariableDeclaration>();
Graf.ReachableExits.ForEach(exit =>
{
var data = _elementDataStorage[exit.Source];
if (data != null)
{
data.Status.ForEach(kvp =>
{
if (kvp.Value == VariableDisposeStatus.NotDisposed || kvp.Value == VariableDisposeStatus.Both)
variables.Add(kvp.Key);
});
}
});
variables.ForEach(
variableDeclaration =>
_highlightings.Add(new HighlightingInfo(variableDeclaration.GetNameDocumentRange(),
new LocalVariableNotDisposed(variableDeclaration.DeclaredName))));
}
示例8: TagsFromCommaSeparatedValues
public async Task<IEnumerable<Tag>> TagsFromCommaSeparatedValues(string tagsAsCommaSeparatedValues)
{
if (string.IsNullOrWhiteSpace(tagsAsCommaSeparatedValues))
{
return Enumerable.Empty<Tag>();
}
var existingTagIds = new HashSet<int>();
var tagNames = new HashSet<string>();
tagsAsCommaSeparatedValues.Split(new[] { TagSeparator }, StringSplitOptions.RemoveEmptyEntries)
.ToList()
.ForEach(tag =>
{
int tagId;
if (int.TryParse(tag, out tagId))
{
existingTagIds.Add(tagId);
}
else
{
tagNames.Add(tag.ToLower());
}
});
var resultTags = await this.tags
.All()
.Where(t => existingTagIds.Contains(t.Id) || tagNames.Contains(t.Name))
.ToListAsync();
(await this.tags
.All()
.Where(t => tagNames.Contains(t.Name.ToLower()))
.Select(t => t.Name.ToLower())
.ToListAsync())
.ForEach(t => tagNames.Remove(t));
tagNames.ForEach(tagName => resultTags.Add(new Tag { Name = tagName, Type = TagType.UserSubmitted }));
return resultTags;
}
示例9: Main
static void Main(string[] args)
{
var inputs = new List<CryptoHashInput>();
var algorithms = new HashSet<CryptoHashAlgorithm>();
var optionSet = new OptionSet
{
{ "h|?|help", s => PrintUsageAndExit() },
{ "V|verbose", s => _verbose = true },
{ "json", s => _json = true },
{ "map", s => _map = true },
{ "lower", s => _upper = false },
{ "md5", s => algorithms.Add(new MD5Algorithm()) },
{ "sha1", s => algorithms.Add(new SHA1Algorithm()) },
{ "sha256", s => algorithms.Add(new SHA256Algorithm()) },
{ "sha512", s => algorithms.Add(new SHA512Algorithm()) },
};
var paths = optionSet.Parse(args);
if (!algorithms.Any())
{
algorithms.Add(new MD5Algorithm());
algorithms.Add(new SHA1Algorithm());
algorithms.Add(new SHA256Algorithm());
algorithms.Add(new SHA512Algorithm());
}
algorithms.ForEach(algorithm => algorithm.UpperCase = _upper);
var stdin = StdIn;
if (stdin != null)
{
inputs.Add(new CryptoHashInput("stdin", stdin, algorithms));
}
inputs.AddRange(paths.Select(path => new CryptoHashInput(path, algorithms)));
Print(inputs);
}
示例10: InitializeProducts
void InitializeProducts(ISession session)
{
var products = new HashSet<Product>
{
new Product{Name = "Hiking Backpack", ProductCode = "Backpack1_1", Category = _categories.First(x => x.Name == "Backpacks"), Price = 50},
new Product{Name = "Wide-base Backpack", ProductCode = "Backpack2_1", Category = _categories.First(x => x.Name == "Backpacks"), Price = 50},
new Product{Name = "Short Backpack", ProductCode = "Backpack3_1", Category = _categories.First(x => x.Name == "Backpacks"), Price = 40},
new Product{Name = "Mountaineering Backpack", ProductCode = "Backpack4_1", Category = _categories.First(x => x.Name == "Backpacks"), Price = 130},
new Product{Name = "Sprint 500 Bike", ProductCode = "Bike1_1", Category = _categories.First(x => x.Name == "Bikes"), Price = 460},
new Product{Name = "Escape 3.0 Bike", ProductCode = "Bike2_1", Category = _categories.First(x => x.Name == "Bikes"), Price = 680},
new Product{Name = "Scoop Cruiser", ProductCode = "Bike3_1", Category = _categories.First(x => x.Name == "Bikes"), Price = 380},
new Product{Name = "Sierra Leather Hiking Boots", ProductCode = "Boots1_1", Category = _categories.First(x => x.Name == "Boots"), Price = 90},
new Product{Name = "Rainier Leather Hiking Boots", ProductCode = "Boots2_1", Category = _categories.First(x => x.Name == "Boots"), Price = 110},
new Product{Name = "Cascade Fur-Lined Hiking Boots", ProductCode = "Boots3_1", Category = _categories.First(x => x.Name == "Boots"), Price = 130},
new Product{Name = "Adirondak Fur-Lined Hiking Boots", ProductCode = "Boots4_1", Category = _categories.First(x => x.Name == "Boots"), Price = 60},
new Product{Name = "Olympic Hiking Boots", ProductCode = "Boots5_1", Category = _categories.First(x => x.Name == "Boots"), Price = 90},
new Product{Name = "Weathered Lether Baseball Cap", ProductCode = "Hat1_1", Category = _categories.First(x => x.Name == "Hats & Helmets"), Price = 13},
new Product{Name = "Colorful Straw hat", ProductCode = "Hat2_1", Category = _categories.First(x => x.Name == "Hats & Helmets"), Price = 10},
new Product{Name = "Summertime Straw Hat", ProductCode = "Hat3_1", Category = _categories.First(x => x.Name == "Hats & Helmets"), Price = 23},
new Product{Name = "Bicycle Safety Helmet", ProductCode = "Helmet1_1", Category = _categories.First(x => x.Name == "Hats & Helmets"), Price = 80},
new Product{Name = "Fusion Helmet", ProductCode = "Helmet2_1", Category = _categories.First(x => x.Name == "Hats & Helmets"), Price = 150},
new Product{Name = "Fire Helmet", ProductCode = "Helmet3_1", Category = _categories.First(x => x.Name == "Hats & Helmets"), Price = 125},
new Product{Name = "Bicycle Safety Helmet", ProductCode = "Helmet1_1", Category = _categories.First(x => x.Name == "Hats & Helmets"), Price = 80},
new Product{Name = "Sentinel Locking Carbiner", ProductCode = "Carbiner1_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 16},
new Product{Name = "Guardian Locking Carbiner", ProductCode = "Carbiner2_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 6},
new Product{Name = "Trailhead Locking Carbiner", ProductCode = "Carbiner3_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 80},
new Product{Name = "Traiguide Compass", ProductCode = "Compass1_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 30},
new Product{Name = "Northstar Compass", ProductCode = "Compass2_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 18},
new Product{Name = "Sundial Compass", ProductCode = "Compass3_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 12},
new Product{Name = "Polar Start Compass", ProductCode = "Compass4_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 15},
new Product{Name = "Compass Necklace", ProductCode = "Compass5_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 16},
new Product{Name = "Battery Operated Flashlight", ProductCode = "Flashlight1_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 8},
new Product{Name = "Heavy-Duty Flashlight", ProductCode = "Flashlight2_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 13},
new Product{Name = "Retro Flashlight", ProductCode = "Flashlight3_1", Category = _categories.First(x => x.Name == "Hiking Gear"), Price = 24},
new Product{Name = "Northwind Traders Arizona Sunglasses", ProductCode = "Sunglasses1_1", Category = _categories.First(x => x.Name == "Sunglasses"), Price = 35},
new Product{Name = "Northwind Traders Eclipse Sunglasses", ProductCode = "Sunglasses2_1", Category = _categories.First(x => x.Name == "Sunglasses"), Price = 55},
};
products.ForEach(product => session.Save(product));
}
示例11: Convert
/// <summary>
/// Convert calls to methods marked with InlineAttribute.
/// </summary>
public void Convert(ReachableContext reachableContext)
{
this.reachableContext = reachableContext;
// Collect all names
var methodsWithBody = reachableContext.ReachableTypes.SelectMany(x => x.Methods).Where(m => m.HasBody).ToList();
if (methodsWithBody.Count == 0)
return;
// Find all methods marked with InlineAttribute
var inlineMethods = new HashSet<MethodDefinition>(methodsWithBody.Where(x =>x.HasCustomAttributes &&
x.CustomAttributes.Any(c => (c.AttributeType.Name == AttributeConstants.InlineAttributeName) &&
(c.AttributeType.Namespace == AttributeConstants.Dot42AttributeNamespace))));
if (inlineMethods.Count == 0)
return;
// Prepare inline methods
inlineMethods.ForEach(x => x.Body.SimplifyMacros());
// Now inline all applicable calls
var notAlwaysConverted = new HashSet<MethodDefinition>();
foreach (var method in methodsWithBody)
{
if (!inlineMethods.Contains(method))
{
Convert(method.Body, inlineMethods, notAlwaysConverted);
}
}
// Mark all methods that have been inlined in all calls not reachable.
/*foreach (var method in inlineMethods)
{
if (!notAlwaysConverted.Contains(method))
{
//method.SetNotReachable();
}
}*/
}
示例12: RemoteRouter_must_deploy_its_children_on_remote_host_driven_by_programmatic_definition
public void RemoteRouter_must_deploy_its_children_on_remote_host_driven_by_programmatic_definition()
{
var probe = CreateTestProbe(masterSystem);
var router = masterSystem.ActorOf(new RemoteRouterConfig(
new RoundRobinPool(2),
new[] { new Address("akka.tcp", sysName, "127.0.0.1", port) })
.Props(EchoActorProps), "blub2");
var replies = CollectRouteePaths(probe, router, 5);
var childred = new HashSet<ActorPath>(replies);
childred.Should().HaveCount(2);
childred.Select(x => x.Parent).Distinct().Should().HaveCount(1);
childred.ForEach(x => x.Address.Should().Be(intendedRemoteAddress));
masterSystem.Stop(router);
}
示例13: GenerateDot
//private DependencyGraph Sample(DependencyGraph aGraph, List<OutputEntry> aWarnings, int percent)
//{
// var rand = new Random();
// var selected = new HashSet<Library>(aWarnings.SelectMany(w => w.Projects)
// .Concat(aGraph.Vertices.Where(v => rand.Next(100) < percent)));
// var result = new DependencyGraph();
// result.AddVertexRange(selected);
// result.AddEdgeRange(aGraph.Edges.Where(e => selected.Contains(e.Source) && selected.Contains(e.Target)));
// return result;
//}
private string GenerateDot()
{
var result = new DotStringBuilder("Dependencies");
result.AppendConfig("concentrate", "true");
int clusterIndex = 1;
foreach (var group in graph.Vertices.Where(a => a.GroupElement != null)
.GroupBy(a => a.GroupElement.Name))
{
var groupName = @group.Key;
var clusterName = "cluster" + clusterIndex++;
var groupInfo = new GroupInfo(clusterName + "_top", clusterName + "_bottom");
groupInfos.Add(groupName, groupInfo);
result.StartSubgraph(clusterName);
result.AppendConfig("label", groupName);
result.AppendConfig("color", "lightgray");
result.AppendConfig("style", "filled");
result.AppendConfig("fontsize", "20");
result.AppendSpace();
AppendGroupNode(result, "min", groupInfo.TopNode);
result.AppendSpace();
var projs = new HashSet<Library>(group);
projs.ForEach(a => AppendProject(result, a));
result.AppendSpace();
graph.Edges.Where(e => projs.Contains(e.Source) && projs.Contains(e.Target))
.ForEach(d => AppendDependency(result, d));
result.AppendSpace();
AppendGroupNode(result, "max", groupInfo.BottomNode);
result.EndSubgraph();
result.AppendSpace();
}
graph.Vertices.Where(a => a.GroupElement == null)
.ForEach(a => AppendProject(result, a));
result.AppendSpace();
graph.Edges.Where(e => AreFromDifferentGroups(e.Source, e.Target))
.ForEach(d => AppendDependency(result, d));
result.AppendSpace();
AddDependenciesBetweenGroups(result);
return result.ToString();
}
示例14: ProcessBeams
/// <summary>
/// Process the remainder of the beams
/// </summary>
/// <param name="Beams">The full list of beams to process</param>
/// <param name="Members">The empty list of members</param>
private void ProcessBeams(HashSet<Beam> Beams, HashSet<Member> Members)
{
int memberCount = Members.Count;
double totalBeams = Beams.Count;
// Process the remaining beams
while (Beams.Any())
{
Beam currentBeam = Beams.First();
Member newMember;
List<Beam> beams;
beams = GatherMemberBeams(currentBeam, false);
beams.AddRange(GatherMemberBeams(currentBeam, true));
beams = new HashSet<Beam>(beams).ToList();
// Generate new member. This needs to be generated with the model beams and not with the cloned list!
newMember = this.GenerateNewMember(++memberCount, this.StaadModel.Beams.Where(o => beams.Contains(o)).ToList());
Members.Add(newMember);
// Remove processed beam and node. This needs to be removed from the cloned list and not the model!
beams.ForEach(b => Beams.Remove(b));
// Fire status update event
this.OnStatusUpdate(new MemberGeneratorStatusUpdateEventArgs("Generating members...", 1 - (Beams.Count / totalBeams), newMember));
// Select the latest member if required
if (SelectIndividualMembersDuringCreation)
this.StaadModel.Staad.Geometry.SelectMultipleBeams(newMember.Beams.Select(o => o.ID).ToArray());
}
}
示例15: UpdateInstructorCourses
private void UpdateInstructorCourses(string[] selectedCourses, Instructor instructor)
{
if (selectedCourses == null)
{
var condition = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };
condition.Predicates.Add(Predicates.Field<CourseInstructor>(s => s.InstructorId, Operator.Eq, instructor.InstructorId));
instructor.Courses.ForEach(c =>
{
condition.Predicates.Add(Predicates.Field<CourseInstructor>(s => s.CourseId, Operator.Eq, c.CourseId));
});
_connection.Delete<CourseInstructor>(condition);
}
else
{
var selectedCourseHs = new HashSet<string>(selectedCourses);
var instructorCourses = new HashSet<int>(
instructor.Courses.Select(s => s.CourseId));
var courseLst = new List<int>();
selectedCourses.ToList().ForEach(s =>
{
courseLst.Add(Convert.ToInt32(s));
});
instructorCourses.ForEach(s =>
{
courseLst.Add(s);
});
foreach (var course in courseLst)
{
if (selectedCourseHs.Contains(course.ToString()))
{
if (!instructorCourses.Contains(course))
{
var courseInstructor = new CourseInstructor
{
InstructorId = instructor.InstructorId,
CourseId = course
};
_connection.Insert(courseInstructor);
}
}
else
{
if (instructorCourses.Contains(course))
{
var condition = new PredicateGroup { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };
condition.Predicates.Add(Predicates.Field<CourseInstructor>(f => f.InstructorId, Operator.Eq, instructor.InstructorId));
condition.Predicates.Add(Predicates.Field<CourseInstructor>(f => f.CourseId, Operator.Eq, course));
_connection.Delete<CourseInstructor>(condition);
}
}
}
}
}