public static void RemoveWhere(ICollection <TSource> collection, Func <TSource, bool> predicate) { if (collection != null) { var list = collection as IList <TSource>; if (list != null) { for (int i = list.Count - 1; i >= 0; i--) { if (predicate(list[i])) { list.RemoveAt(i); } } } else { var toRemove = SL.ToList(SL.Where(collection, predicate)); foreach (var item in toRemove) { collection.Remove(item); } } } }
private static void AddToList <T>(IList <T> storage, T item, Func <T, T, bool> filter) { if (Enumerable.Count(Processor.Where(storage, delegate(T i) { return(filter(i, item)); })) == 0) { storage.Add(item); } }
private void NotifySource2(ICollectionChangedNotificationResult <TSource> change, List <TSource> added, List <TSource> removed) { if (change.RemovedItems != null) { var uniqueRemoved = new HashSet <TSource>(sourceItems.Comparer); foreach (var item in change.RemovedItems) { if (RemoveItem(item)) { uniqueRemoved.Add(item); } } removed.AddRange(SL.Where(source, item => uniqueRemoved.Contains(item))); } if (change.AddedItems != null) { var uniqueAdded = new HashSet <TSource>(sourceItems.Comparer); foreach (var item in change.AddedItems) { if (AddItem(item)) { uniqueAdded.Add(item); } } added.AddRange(SL.Where(source, item => uniqueAdded.Contains(item))); } }
public override IEnumerator <T> GetEnumerator() { if (ObservableExtensions.KeepOrder) { return(SL.Where(source, item => { if (isValueType || item != null) { TaggedObservableValue <bool, ItemMultiplicity> node; if (lambdaInstances.TryGetValue(item, out node)) { return node.Value; } else { return false; } } else { return nullCheck != null && nullCheck.Value; } }).GetEnumerator()); } else { return(ItemsUnordered.GetEnumerator()); } }
public override string ToString() { var fields = Enumerable.Where(this.GetType() .GetFields(), field => CustomAttributeExtensions.IsDefined((MemberInfo)field, typeof(InjectFieldValueAttribute)) && ((field.FieldType == typeof(string)) || field.FieldType.IsPrimitive)); var objectStringRepresentation = new StringBuilder(capacity: 6000); objectStringRepresentation.AppendFormat("{0} {1}", this.GetType().Name, Environment.NewLine); foreach (var field in fields) { var fldValue = field.GetValue(this); if (field.FieldType.IsClass && (fldValue == null)) { objectStringRepresentation.AppendFormat("{0} --> {1}{2}", field.Name, "[Null]", Environment.NewLine); continue; } if ((field.FieldType == typeof(string)) && string.IsNullOrEmpty((string)fldValue)) { objectStringRepresentation.AppendFormat("{0} --> {1}{2}", field.Name, "[string.Empty]", Environment.NewLine); continue; } objectStringRepresentation.AppendFormat("{0} --> {1}{2}", field.Name, fldValue, Environment.NewLine); } return(objectStringRepresentation.ToString()); }
public override async Task SetOverdueNotificationsAsync(List <string> overdueNotifications) { CriteriaBuilder criteriaBuilder = new CriteriaBuilder(); _overdueNotifications = overdueNotifications; _followUps = await _followUpsController.GetManyByCriteria ( criteriaBuilder .Add("Id", _overdueNotifications.ToArray(), ConjunctionsEnum.And, Operators.In) ); List <Guid> followUpsToRemove = new List <Guid>(); for (int i = 0; i < _followUps.Count; i++) { if ((await ProspectWasConverted(_followUps[i]))) { followUpsToRemove.Add(_followUps[i].Id); } } if (followUpsToRemove.Count > 0) { _followUps = Enumerable.ToList(Enumerable.Where(_followUps, followup => !followUpsToRemove.Contains(followup.Id))); } if (_followUps.Count == 1 && _singleProspect == null) { _singleProspect = await new ProspectsController().GetByIdAsync(_followUps[0].ProspectId); _singleProspect.ReminderTime = _followUps[0].ReminderTime; } }
public void WhereTest() { int[] enumerable = new int[] { 0, 1, 2 }; EnumerableAssert.AreSequentialEqual( Enumerable.Where(enumerable, x => x > 0), IteratorPattern.Where(enumerable, x => x > 0)); enumerable = new int[] { }; EnumerableAssert.AreSequentialEqual( Enumerable.Where(enumerable, x => x > 0), IteratorPattern.Where(enumerable, x => x > 0)); }
public Scenario(string scenarioName, ImplementationType implementationType, int runs, int numberOfCores) { if (implementationType == ImplementationType.All) { foreach (var implementationName in Enumerable.Where(Enum.GetNames(typeof(ImplementationType)), s => s != "All")) { _implementations.Add(new Implementation(scenarioName, implementationName, runs, numberOfCores)); } } else { string implementationName = implementationType.ToString(); _implementations.Add(new Implementation(scenarioName, implementationName, runs, numberOfCores)); } }
private async Task <Dictionary <string, Cookie> > LoadFromCookiesTxtAsync(Cookie antiScrappingCookie, bool keepId) { var cookieCollection = new Dictionary <string, Cookie>(); var cookiesFile = "data/cookies.txt"; if (File.Exists(cookiesFile)) { var readAllText = Enumerable.Where( await File.ReadAllLinesAsync(cookiesFile), s => !s.TrimStart().StartsWith("#")); foreach (var line in readAllText) { var match = this.RegexCookiesTxt.Match(line); if (match.Success) { try { var name = match.Groups[6].Value; var value = match.Groups[7].Value; if (name == "myCookie") { value = "username=&userPsw="; } if (name != "SRVNAME" && (name != "uid" || keepId)) { cookieCollection.Add( name, new Cookie(name, value, match.Groups[3].Value, match.Groups[1].Value)); } } catch (Exception e) { Log.Warning(e.Message); } } } } if (antiScrappingCookie != null) { cookieCollection.Remove(antiScrappingCookie.Name); cookieCollection.Add(antiScrappingCookie.Name, antiScrappingCookie); } return(cookieCollection); }
//Note: currently the selected features are one select behind. //e.g on drawing the first region all the layers features are returned // on drawing the second region all the features matching the first region are returned etc.. private void AttributeQueryHandler_End(object sender, MapActionHandlerEventArgs e) { IFeatureLayer l = Enumerable.FirstOrDefault( Caster.Cast <IFeatureLayer>( Processor.Where(Map.SelectedLayers, delegate(ILayer o) { return(o as IFeatureLayer != null); }))); if (l != null) { FeatureDataView dv = new FeatureDataView(l.SelectedFeatures.Table); if (l.SelectedFeatures.AttributeFilter != null) { dv.AttributeFilter = (AttributeBinaryExpression) l.SelectedFeatures.AttributeFilter.Clone(); } if (l.SelectedFeatures.SpatialFilter != null) { dv.SpatialFilter = (SpatialBinaryExpression) l.SelectedFeatures.SpatialFilter.Clone(); } if (l.SelectedFeatures.OidFilter != null) { dv.OidFilter = (OidCollectionExpression) l.SelectedFeatures.OidFilter.Clone(); } if (l.SelectedFeatures.ViewDefinition != null) { dv.ViewDefinition = (FeatureQueryExpression) l.SelectedFeatures.ViewDefinition.Clone(); } QueryResultsTab tab = new QueryResultsTab(l.LayerName, dv); resultsTabControl.TabPages.Insert(0, tab); resultsTabControl.SelectedTab = tab; } }
public void WhereCount_long_Test() { using (var array = new NativeArray <long>(114514, Allocator.Temp)) { InitializeLongArray(array); sw.Start(); for (var i = 0; i < Count; i++) { array.Append(1000).Where(new DetectOdd()).Append(1000).Count(); } Debug.Log(sw.Stop().ToString()); sw.Start(); for (var i = 0; i < Count; i++) { LE.Count(LE.Append(LE.Where(LE.Append(array, 1000), x => (x & 1) == 1), 1000)); } Debug.Log(sw.Stop().ToString()); } }
private void Source2CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Move) { return; } if (e.Action == NotifyCollectionChangedAction.Reset) { var filtered = new List <TSource>(SL.Intersect(sourceItems.Keys, source)); sourceItems.Clear(); OnAddItems(filtered); } if (e.OldItems != null) { var removed = new HashSet <TSource>(sourceItems.Comparer); foreach (TSource item in e.OldItems) { if (RemoveItem(item)) { removed.Add(item); } } var changed = SL.Where(source, item => removed.Contains(item)); OnAddItems(changed); } if (e.NewItems != null) { var added = new HashSet <TSource>(sourceItems.Comparer); foreach (TSource item in e.NewItems) { if (AddItem(item)) { added.Add(item); } } var changed = SL.Where(source, item => added.Contains(item)); OnRemoveItems(changed); } }
public override IEnumerator <T> GetEnumerator() { return(SL.Where(Source, item => { if (isValueType || item != null) { TaggedObservableValue <bool, ItemMultiplicity> node; if (lambdas.TryGetValue(item, out node)) { return node.Value; } else { return false; } } else { return nullCheck != null && nullCheck.Value; } }).GetEnumerator()); }
public static System.Reflection.MemberInfo[] GetCachedFields(this System.Type type, System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic) { if (ReflectionHelper.fieldInfoCache.TryGetValue(type, out var fieldInfos) == false) { var fieldInfosArr = Enumerable.Cast <System.Reflection.MemberInfo>(Enumerable.Where(type.GetAllFields(flags), f => f.IsPublic == true || Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute)) == true)); fieldInfosArr = Enumerable.Union(fieldInfosArr, Enumerable.Where(type.GetAllProperties(flags), f => f.CanRead == true && f.CanWrite == true && Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute)) ) ); fieldInfos = Enumerable.ToArray(Enumerable.OrderBy(fieldInfosArr, x => x.Name)); ReflectionHelper.fieldInfoCache.Add(type, fieldInfos); } return(fieldInfos); }
public override IEnumerator <TSource> GetEnumerator() { return(SL.Where(source, item => sourceItems.ContainsKey(item)).GetEnumerator()); }