本文整理汇总了C#中IEnumerable类的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable类的具体用法?C# IEnumerable怎么用?C# IEnumerable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IEnumerable类属于命名空间,在下文中一共展示了IEnumerable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public string Build(BundleType type, IEnumerable<string> files)
{
if (files == null || !files.Any())
return string.Empty;
string bundleVirtualPath = this.GetBundleVirtualPath(type, files);
var bundleFor = BundleTable.Bundles.GetBundleFor(bundleVirtualPath);
if (bundleFor == null)
{
lock (s_lock)
{
bundleFor = BundleTable.Bundles.GetBundleFor(bundleVirtualPath);
if (bundleFor == null)
{
var nullOrderer = new NullOrderer();
Bundle bundle = (type == BundleType.Script) ?
new CustomScriptBundle(bundleVirtualPath) as Bundle :
new SmartStyleBundle(bundleVirtualPath) as Bundle;
bundle.Orderer = nullOrderer;
bundle.Include(files.ToArray());
BundleTable.Bundles.Add(bundle);
}
}
}
if (type == BundleType.Script)
return Scripts.Render(bundleVirtualPath).ToString();
return Styles.Render(bundleVirtualPath).ToString();
}
示例2: Applies
public bool Applies(ShoppingCartQuantityProduct quantityProduct, IEnumerable<ShoppingCartQuantityProduct> cartProducts) {
if (DiscountPart == null) return false;
var now = _clock.UtcNow;
if (DiscountPart.StartDate != null && DiscountPart.StartDate > now) return false;
if (DiscountPart.EndDate != null && DiscountPart.EndDate < now) return false;
if (DiscountPart.StartQuantity != null &&
DiscountPart.StartQuantity > quantityProduct.Quantity)
return false;
if (DiscountPart.EndQuantity != null &&
DiscountPart.EndQuantity < quantityProduct.Quantity)
return false;
if (!string.IsNullOrWhiteSpace(DiscountPart.Pattern)) {
string path;
if (DiscountPart.DisplayUrlResolver != null) {
path = DiscountPart.DisplayUrlResolver(quantityProduct.Product);
}
else {
var urlHelper = new UrlHelper(_wca.GetContext().HttpContext.Request.RequestContext);
path = urlHelper.ItemDisplayUrl(quantityProduct.Product);
}
if (!path.StartsWith(DiscountPart.Pattern, StringComparison.OrdinalIgnoreCase))
return false;
}
if (DiscountPart.Roles.Any()) {
var user = _wca.GetContext().CurrentUser;
if (user.Has<UserRolesPart>()) {
var roles = user.As<UserRolesPart>().Roles;
if (!roles.Any(r => DiscountPart.Roles.Contains(r))) return false;
}
}
return true;
}
示例3: Generate
public Dictionary<string, string> Generate(List<NameNode> idNameNodes, IEnumerable<string> excludedNames)
{
Generator.Reset();
int varCount = idNameNodes.Count;
string[] newNames = new string[varCount];
var newSubstitution = new Dictionary<string, string>();
for (int i = 0; i < varCount; i++)
{
string newName;
do
{
newName = Generator.Next();
}
while (excludedNames.Contains(newName) || NamesGenerator.CSharpKeywords.Contains(newName));
newNames[i] = newName;
}
int ind = 0;
foreach (NameNode v in idNameNodes)
if (!newSubstitution.ContainsKey(v.Name))
newSubstitution.Add(v.Name, newNames[ind++]);
return newSubstitution;
}
示例4: Execute
/// <summary>
/// Executes this operation
/// </summary>
/// <param name="rows">The rows.</param>
/// <returns></returns>
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
using (IDbConnection connection = Use.Connection(ConnectionStringName))
using (IDbTransaction transaction = connection.BeginTransaction())
{
foreach (Row row in new SingleRowEventRaisingEnumerator(this, rows))
{
using (IDbCommand cmd = connection.CreateCommand())
{
currentCommand = cmd;
currentCommand.Transaction = transaction;
PrepareCommand(currentCommand, row);
currentCommand.ExecuteNonQuery();
}
}
if (PipelineExecuter.HasErrors)
{
Warn("Rolling back transaction in {0}", Name);
transaction.Rollback();
Warn("Rolled back transaction in {0}", Name);
}
else
{
Debug("Committing {0}", Name);
transaction.Commit();
Debug("Committed {0}", Name);
}
}
yield break;
}
示例5: BuildScriptTags
public IEnumerable<HtmlTag> BuildScriptTags(IEnumerable<string> scripts)
{
Func<string, string> toFullUrl = url => _request.ToFullUrl(url);
while (_queuedScripts.Any())
{
var asset = _queuedScripts.Dequeue();
if (_writtenScripts.Contains(asset)) continue;
_writtenScripts.Add(asset);
yield return new ScriptTag(toFullUrl, asset);
}
foreach (var x in scripts)
{
var asset = _finder.FindAsset(x);
if (asset == null)
{
yield return new ScriptTag(toFullUrl, null, x);
}
else if (!_writtenScripts.Contains(asset))
{
_writtenScripts.Add(asset);
yield return new ScriptTag(toFullUrl, asset, x);
}
}
}
示例6: SetUnmodifiedCommand
public SetUnmodifiedCommand(string sitePath, IEnumerable<DocumentFile> documents, IEnumerable<StaticFile> files, IEnumerable<LastRunDocument> lastRunState)
{
this.Documents = documents;
this.Files = files;
this.LastRunState = lastRunState;
this.SitePath = sitePath;
}
示例7: AddRoleClaims
public static void AddRoleClaims(IEnumerable<string> roles, IList<Claim> claims)
{
foreach (string role in roles)
{
claims.Add(new Claim(RoleClaimType, role, ClaimsIssuer));
}
}
示例8: RemoveAllRenameAnnotationsAsync
internal async Task RemoveAllRenameAnnotationsAsync(IEnumerable<DocumentId> documentWithRenameAnnotations, AnnotationTable<RenameAnnotation> annotationSet, CancellationToken cancellationToken)
{
foreach (var documentId in documentWithRenameAnnotations)
{
if (_renamedSpansTracker.IsDocumentChanged(documentId))
{
var document = _newSolution.GetDocument(documentId);
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
// For the computeReplacementToken and computeReplacementNode functions, use
// the "updated" node to maintain any annotation removals from descendants.
var newRoot = root.ReplaceSyntax(
nodes: annotationSet.GetAnnotatedNodes(root),
computeReplacementNode: (original, updated) => annotationSet.WithoutAnnotations(updated, annotationSet.GetAnnotations(updated).ToArray()),
tokens: annotationSet.GetAnnotatedTokens(root),
computeReplacementToken: (original, updated) => annotationSet.WithoutAnnotations(updated, annotationSet.GetAnnotations(updated).ToArray()),
trivia: SpecializedCollections.EmptyEnumerable<SyntaxTrivia>(),
computeReplacementTrivia: null);
_intermediateSolutionContainingOnlyModifiedDocuments = _intermediateSolutionContainingOnlyModifiedDocuments.WithDocumentSyntaxRoot(documentId, newRoot, PreservationMode.PreserveIdentity);
}
}
_newSolution = _intermediateSolutionContainingOnlyModifiedDocuments;
}
示例9: CreateEvents
public Dictionary<string, List<Event>> CreateEvents(string calendarId, IEnumerable<CalendarItem> eventsToCreate)
{
var service = _GetCalendarService();
var eventsToBeCreated = eventsToCreate.Select(eventFromCalendarItem);
var created = new List<Event>();
var errored = new List<Event>();
foreach (var eventToBeCreated in eventsToBeCreated)
{
try {
Console.WriteLine(string.Format(" -- Creating EVENT [{0}] for dates [{1}]"
,eventToBeCreated.Summary, eventToBeCreated.Start.DateTime.Value));
var result = service.Events.Insert(eventToBeCreated, calendarId).Execute();
if (result.Id != null && result.Id != "")
{
created.Add(result);
}
}catch(Exception ex)
{
Console.WriteLine(ex);
errored.Add(eventToBeCreated);
}
}
return new Dictionary<string, List<Event>>()
{
{ "created", created },
{ "errored", errored}
};
}
示例10: Announcement
public Announcement(string description, string type, string operatorName, DateTime? startDate, DateTime? endDate, Coordinate location, IEnumerable<string> modes)
{
this.OperatorName = operatorName;
this.Description = description;
this.StartDate = startDate;
this.EndDate = endDate;
this.Location = location;
this.Type = type;
this.Modes.AddRange(modes);
this.RelativeDateString = TimeConverter.ToRelativeDateString(StartDate, true);
if (modes != null)
{
if (modes.Select(x => x.ToLower()).Contains("bus"))
this.ModeImages.Add("/Images/64/W/ModeBus.png");
if (modes.Select(x => x.ToLower()).Contains("rail"))
this.ModeImages.Add("/Images/64/W/ModeRail.png");
if (modes.Select(x => x.ToLower()).Contains("taxi"))
this.ModeImages.Add("/Images/64/W/ModeTaxi.png");
if (modes.Select(x => x.ToLower()).Contains("boat"))
this.ModeImages.Add("/Images/64/W/ModeBoat.png");
if (!this.ModeImages.Any())
this.ModeImages.Add("/Images/64/W/ModeBus.png");
}
else
{
this.Modes.Add("bus");
this.ModeImages.Add("/Images/64/W/ModeBus.png");
}
}
示例11: Calculate
static IEnumerable<FileRiskFactor> Calculate(IEnumerable<FileModificationStatistics> statistics)
{
var riskFactors = new List<FileRiskFactor>();
foreach (var statistic in statistics)
{
var fileRiskFactor = new FileRiskFactor
{
CreatedAt = DateTime.Now,
FileName = statistic.FileName,
Statistics = statistic
};
var existingDuration = GetDaysDuration(statistic.FirstCommit.ModifiedAt, DateTime.Now);
var localStatistic = statistic;
foreach (var duration in statistic.OtherCommits.Select(commit => GetDaysDuration(localStatistic.FirstCommit.ModifiedAt, commit.ModifiedAt)))
{
fileRiskFactor.Score += Score(duration, existingDuration);
}
riskFactors.Add(fileRiskFactor);
}
return riskFactors;
}
示例12: GenerateTestFixture
public string GenerateTestFixture(IEnumerable<Test> tests, string fileName)
{
var generator = new CodeGenerator(TemplateEnum.MbUnitTestFixture, TestText, MethodText, PropertyText, TypeText,
AssertText);
var code = generator.GenerateTestFixture(tests.ToList(), fileName);
return code;
}
示例13: DecorateEnumerableForExecution
/// <summary>
/// Add a decorator to the enumerable for additional processing
/// </summary>
/// <param name="operation">The operation.</param>
/// <param name="enumerator">The enumerator.</param>
protected override IEnumerable<Row> DecorateEnumerableForExecution(IOperation operation, IEnumerable<Row> enumerator)
{
foreach (Row row in new EventRaisingEnumerator(operation, enumerator))
{
yield return row;
}
}
示例14: PerformanceCounterInfo
public PerformanceCounterInfo(string name, PerformanceCounter performanceCounters, string alias, IEnumerable<ITag> tags)
{
_name = name;
_performanceCounters = performanceCounters;
_alias = alias;
_tags = (tags ?? new List<ITag>()).ToList();
}
示例15: AppUpdateControl
public AppUpdateControl(IEnumerable<IAppVersion> appVersions, Action<IAppVersion> updateAction)
{
this.NewestVersion = appVersions.First();
InitializeComponent();
this.AppIconImage.ImageFailed += (sender, e) => { this.AppIconImage.Source = new BitmapImage(new Uri("/Assets/windows_phone.png", UriKind.RelativeOrAbsolute)); };
this.AppIconImage.Source = new BitmapImage(new Uri(HockeyClient.Current.AsInternal().ApiBaseVersion2 + "apps/" + NewestVersion.PublicIdentifier + ".png"));
this.ReleaseNotesBrowser.Opacity = 0;
this.ReleaseNotesBrowser.Navigated += (sender, e) => { (this.ReleaseNotesBrowser.Resources["fadeIn"] as Storyboard).Begin(); };
this.ReleaseNotesBrowser.NavigateToString(WebBrowserHelper.WrapContent(NewestVersion.Notes));
this.ReleaseNotesBrowser.Navigating += (sender, e) =>
{
e.Cancel = true;
WebBrowserTask browserTask = new WebBrowserTask();
browserTask.Uri = e.Uri;
browserTask.Show();
};
this.InstallAETX.Click += (sender, e) =>
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri(HockeyClient.Current.AsInternal().ApiBaseVersion2 + "apps/" + NewestVersion.PublicIdentifier + ".aetx", UriKind.Absolute);
webBrowserTask.Show();
};
this.InstallOverApi.Click += (sender, e) => {
this.Overlay.Visibility = Visibility.Visible;
updateAction.Invoke(NewestVersion);
};
}