本文整理汇总了C#中ICollection.Select方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Select方法的具体用法?C# ICollection.Select怎么用?C# ICollection.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CombineSelectors
private static IEnumerable<string> CombineSelectors(ICollection<string> parents, string child)
{
if (!child.Contains("&"))
return parents.Select(p => p + " " + child);
return parents.Select(p => child.Replace("&", p));
}
示例2: WriteToStream
public override void WriteToStream(ICollection<TableDefinition> tables, System.IO.StreamWriter output)
{
int tableCount = tables.Count;
int columnCount = tables.Select(t => t.Columns.Count).Sum();
int indexCount = tables.Select(t => t.Indexes.Count).Sum();
int keyCount = tables.Select(t => t.ForeignKeys.Count).Sum();
output.Write(GetMessage(tableCount, columnCount, indexCount, keyCount));
}
示例3: ConstructProvider
private static Object ConstructProvider(Type providerType, ICollection<ConstructorArgumentElement> arguments)
{
foreach (var constructor in providerType.GetConstructors())
{
var parameters = constructor.GetParameters().ToArray();
// not all arguments can be specified
if (parameters.Select(param => param.Name).Intersect(arguments.Select(a => a.Name)).Count() != arguments.Count)
continue;
// not enough arguments to call constructor
if (parameters.Any(param => !(param.IsOptional || param.DefaultValue != null || arguments.Any(arg => arg.Name == param.Name))))
continue;
// get correct arguments
var invocationArguments = parameters
.OrderBy(param => param.Position)
.Select(p => new { Parameter = p, Argument = arguments.SingleOrDefault(a => a.Name == p.Name) })
.Select(pair => pair.Argument == null ? pair.Parameter.DefaultValue : pair.Argument.Value)
.ToArray();
// invoke constructor
return constructor.Invoke(invocationArguments);
}
return null;
}
示例4: Tags
public static MvcHtmlString Tags(this HtmlHelper html, ICollection<Tag> tags, Func<string, MvcHtmlString> tagUrl)
{
var htmlTags = tags.Select(t => tagUrl(t.Name).ToHtmlString()).ToArray();
var tagsStr = string.Join(", ", htmlTags);
return MvcHtmlString.Create(tagsStr);
}
示例5: CreatePersistenceModel
public static AutoPersistenceModel CreatePersistenceModel(ICollection<RecordBlueprint> recordDescriptors)
{
if (recordDescriptors == null)
{
throw new ArgumentNullException("recordDescriptors");
}
return AutoMap.Source(new TypeSource(recordDescriptors))
// Ensure that namespaces of types are never auto-imported, so that
// identical type names from different namespaces can be mapped without ambiguity
.Conventions.Setup(x => x.Add(AutoImport.Never()))
//此处覆写Table("name"); 本来为统一处理表名(如增加前缀等),现由各个模块自己配置表名
//.Conventions.Add(new RecordTableNameConvention(recordDescriptors))
.Conventions.Add(new CacheConventions(recordDescriptors))
.Alterations(alt =>
{
foreach (var recordAssembly in recordDescriptors.Select(x => x.Type.Assembly).Distinct())
{
alt.Add(new AutoMappingOverrideAlteration(recordAssembly));
}
alt.AddFromAssemblyOf<DataModule>();
//alt.Add(new ContentItemAlteration(recordDescriptors));
})
.Conventions.AddFromAssemblyOf<DataModule>();
}
示例6: TryGetSubscribers
public bool TryGetSubscribers(ICollection<Type> contracts, out ICollection<Address> subscribers)
{
Mandate.ParameterNotNull(contracts, "contracts");
locker.EnterReadLock();
var allSubscriptions = new List<Address>();
subscribers = allSubscriptions;
try
{
foreach (var subscriptions in contracts.Select(GetSubscribers))
{
if (subscriptions == null)
continue;
allSubscriptions.AddRange(subscriptions);
}
return allSubscriptions.Any();
}
finally
{
locker.ExitReadLock();
}
}
示例7: BuildAsync
public Task<bool> BuildAsync(ICollection<Project> projects)
{
var projectHierarchy = projects.Select(project => project.GetHierarchy()).ToArray();
var buildUpdateFlags = Enumerable.Repeat((uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD, projectHierarchy.Length).ToArray();
// Launches an asynchronous build operation and returns S_OK immediately if the build begins.
// The result does not indicate completion or success of the build
var updateErrorCode = _buildManager.StartUpdateSpecificProjectConfigurations(
(uint)projects.Count,
projectHierarchy,
null,
null,
buildUpdateFlags,
null,
(uint)VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD,
0);
var tcs = new TaskCompletionSource<bool>();
if (updateErrorCode == S_OK)
{
var builder = new ProjectAsyncBuilder(_buildManager, tcs);
_buildManager.AdviseUpdateSolutionEvents(builder, out builder.UpdateSolutionEventsCookie);
}
else
{
tcs.SetResult(false);
}
return tcs.Task;
}
示例8: CreateBills
public static Document CreateBills(ICollection<WordStatementInfo> statements, IProgressReporter progress, bool duplexMode)
{
if (statements == null) throw new ArgumentNullException("statements");
progress = progress ?? new EmptyProgressReporter();
progress.Caption = "Creating document";
Dictionary<StatementKind, Range> sourceRanges = new Dictionary<StatementKind, Range>();
try {
foreach (var kind in statements.Select(s => s.Kind).Distinct()) {
var sd = Word.Documents.Open(
FileName: Path.Combine(WordExport.TemplateFolder, kind.ToString() + ".docx"),
ReadOnly: true,
AddToRecentFiles: false
);
// Fix Word 2013 bug
// http://blogs.msmvps.com/wordmeister/2013/02/22/word2013bug-not-available-for-reading/
sd.ActiveWindow.View.Type = WdViewType.wdPrintView;
sourceRanges.Add(kind, sd.Range());
}
Document doc = Word.Documents.Add();
doc.ShowGrammaticalErrors = doc.ShowSpellingErrors = false;
Range range = doc.Range();
bool firstPage = true;
using (new ClipboardScope()) {
var populator = new StatementPopulator();
progress.Maximum = statements.Count;
int i = 0;
foreach (var info in statements) {
if (progress.WasCanceled) return null;
progress.Progress = i;
progress.Caption = "Creating " + info.Kind.ToString().ToLower(Culture) + " for " + info.Person.VeryFullName;
if (firstPage)
firstPage = false;
else
range.BreakPage(forceOddPage: duplexMode);
sourceRanges[info.Kind].Copy();
range.Paste();
populator.Populate(range, info);
foreach (Shape shape in range.ShapeRange)
populator.Populate(shape.TextFrame.TextRange, info);
i++;
}
}
Word.Activate();
doc.Activate();
return doc;
} finally {
foreach (var sd in sourceRanges.Values) sd.Document.CloseDoc();
}
}
示例9: PackAsync
public async Task<byte[]> PackAsync(ICollection<ClientFile> files)
{
if (files == null) throw new ArgumentNullException("files");
if (files.Count == 0) throw new ArgumentOutOfRangeException("files");
var header = new StringBuilder();
var totalBuffer = new byte[files.Select(f => f.Data.Length).Sum()];
using (var output = new MemoryStream(totalBuffer))
{
foreach (var f in files)
{
var data = f.Data;
await output.WriteAsync(data, 0, data.Length);
if (header.Length > 0)
{
header.Append(FileSeparator);
}
header.Append(f.Name);
header.Append(SizeSeparator);
header.Append(data.Length);
}
var headerData = Encoding.Unicode.GetBytes(header.ToString());
var headerSize = BitConverter.GetBytes(headerData.Length);
return Utilities.Concat(headerSize, headerData, totalBuffer);
}
}
示例10: WhichAuntSueSentTheGift
/// <summary>
/// Returns the number of the Aunt Sue that sent the gift from the specified Aunt Sue metadata.
/// </summary>
/// <param name="metadata">The metadata about all the Aunt Sues.</param>
/// <param name="compensateForRetroEncabulator">Whether to compensate for the Retro Encabulator.</param>
/// <returns>
/// The number of the Aunt Sue which sent the gift based on forensic analysis of <paramref name="metadata"/>.
/// </returns>
internal static int WhichAuntSueSentTheGift(ICollection<string> metadata, bool compensateForRetroEncabulator = false)
{
var parsed = metadata.Select(AuntSue.Parse);
foreach (var item in ForensicAnalysis)
{
if (compensateForRetroEncabulator && item.Value.Item2 != 0)
{
if (item.Value.Item2 == 1)
{
parsed = parsed.Where((p) => !p.Metadata.ContainsKey(item.Key) || p.Metadata[item.Key] > item.Value.Item1);
}
else
{
parsed = parsed.Where((p) => !p.Metadata.ContainsKey(item.Key) || p.Metadata[item.Key] < item.Value.Item1);
}
}
else
{
parsed = parsed.Where((p) => !p.Metadata.ContainsKey(item.Key) || p.Metadata[item.Key] == item.Value.Item1);
}
}
return parsed.Single().Number;
}
示例11: UpdateMenuLinkLists
private void UpdateMenuLinkLists(ICollection<webModels.MenuLinkList> linkLIsts)
{
foreach (var item in linkLIsts.Select(x => x.ToCoreModel()))
{
_menuService.Update(item);
}
}
示例12: GetMaximumTotalChangeInHappiness
/// <summary>
/// Gets the maximum total change in happiness for the specified potential happiness of the guests.
/// </summary>
/// <param name="potentialHappiness">A collection of potential guess happinesses.</param>
/// <returns>The optional total change in happiness for the specified potentials.</returns>
internal static int GetMaximumTotalChangeInHappiness(ICollection<string> potentialHappiness)
{
// Parse the input data
IList<Potential> potentials = potentialHappiness
.Select(ParsePotentialHappiness)
.ToList();
// Determine all of the possible seating arrangements
List<string> names = potentials
.Select((p) => p.Name)
.Distinct()
.ToList();
// TODO Remove all permutations which are equal when considering the table is circular
IList<IList<string>> permutations = Maths.GetPermutations(names)
.Select((p) => new List<string>(p) as IList<string>)
.ToList();
// Key the happiness for each person for the people they could sit next to
IDictionary<string, Dictionary<string, int>> happinesses = names.ToDictionary(
(p) => p,
(p) => potentials.Where((r) => r.Name == p).ToDictionary((r) => r.AdjacentName, (r) => r.Happiness));
// Get the maximum potential happiness from all the seating arrangements
return permutations
.Select((p) => GetHappiness(p, happinesses))
.Max();
}
示例13: ImportClients
public void ImportClients(ICollection<MongoDb.Data.Models.Client> mongoClients)
{
var clients = mongoClients.Select(c => new Model.Client()
{
Address = c.Address,
Contact = c.Contact,
Email = c.Email,
Mobile = c.Mobile,
Name = c.Name
});
var counter = 0;
foreach (var client in clients)
{
this.dbContext.Clients.Add(client);
counter++;
if (counter % 50 == 0)
{
this.dbContext.SaveChanges();
this.dbContext.Dispose();
this.dbContext = new FurnitureFactoryDbContext();
}
}
this.dbContext.SaveChanges();
}
示例14: InstanceProxyException
/// <summary>
/// Initializes a new instance of the <see cref="InstanceProxyException"/> class containing specified types which were problematic.
/// </summary>
/// <param name="types">The problematic types.</param>
public InstanceProxyException(ICollection<IType> types)
{
Contract.Requires(types != null);
Contract.Requires(types.Count > 0);
this.namesOfTypes = types.Select(t => t.FullName).ToList();
}
示例15: MailboxModel
protected MailboxModel(int id, int tenant, IMailAddress address, IMailAccount account,
ICollection<IMailAddress> aliases, MailServerBase server)
: base(new MailAccountBase(account), new MailAddressBase(address), (aliases.Select(a => new MailAddressBase(a)).ToList()))
{
if (id < 0)
throw new ArgumentException("Invalid domain id", "id");
if (tenant < 0)
throw new ArgumentException("Invalid tenant id", "tenant");
if (account == null)
throw new ArgumentException("Invalid account", "account");
if (address == null)
throw new ArgumentException("Invalid address", "address");
if (aliases == null)
throw new ArgumentException("Invalid aliases", "aliases");
if (server == null)
throw new ArgumentException("Invalid server", "server");
Id = id;
Tenant = tenant;
Account = account;
Address = address;
Aliases = aliases;
Server = server;
}