public void Returns_the_bits_of_the_bytes() { byte b = 0b11001010; var bits = EnumerableHelpers.ToArray( this.translator.GetBits( new[] { b })); Assert.True( bits[0]); Assert.True( bits[1]); Assert.False( bits[2]); Assert.False( bits[3]); Assert.True( bits[4]); Assert.False( bits[5]); Assert.True( bits[6]); Assert.False( bits[7]); }
public TResult[] ToArray() { var builder = new SparseArrayBuilder <TResult>(initialize: true); ArrayBuilder <IEnumerable <TResult> > deferredCopies = default; foreach (TSource element in _source) { IEnumerable <TResult> enumerable = _selector(element); if (builder.ReserveOrAdd(enumerable)) { deferredCopies.Add(enumerable); } } TResult[] array = builder.ToArray(); ArrayBuilder <Marker> markers = builder.Markers; for (int i = 0; i < markers.Count; i++) { Marker marker = markers[i]; IEnumerable <TResult> enumerable = deferredCopies[i]; EnumerableHelpers.Copy(enumerable, array, marker.Index, marker.Count); } return(array); }
public virtual XTuple <string, string, string> Convert( LogEntry entry, string name) { if (entry == null) { return(XTuple.Create <string, string, string>( null, null, null)); } var r = this.runner; string format = null; r?.Run <SettingsHolder>(settings => { format = settings.TimestampFormat; }, name); return(XTuple.Create( entry.Timestamp.ToString( format, CultureInfo.CurrentCulture), entry.Type, string.Join( Environment.NewLine, EnumerableHelpers.ToArray( entry.Content)))); }
public override TSource[] ToArray() { int count = GetCount(onlyIfCheap: true); if (count == -1) { return(LazyToArray()); } TSource[] array = new TSource[count]; int index; if (_appending) { index = 0; } else { array[0] = _item; index = 1; } EnumerableHelpers.Copy(_source, array, index, count - 1); if (_appending) { array[array.Length - 1] = _item; } return(array); }
public virtual Lot <string> WebNames() { return(new LinkedListLot <string>( EH.Select( this.webs, webHolder => webHolder?.Name))); }
public IEnumerator <T> GetEnumerator() { return(this.collection?.GetEnumerator() ?? EnumerableHelpers .Empty <T>() .GetEnumerator()); }
public virtual void ComputeRange( DateTime startDate, DateTime endDate) { var r = this.runner; r.Run <Log, Lotter>((l, lotter) => { var matches = lotter.Materialize( EnumerableHelpers.Where( EnumerableHelpers.Where( l.ReadEntries(), e => { var ts = e.Timestamp; return(ts >= startDate && ts < endDate.AddDays(1)); }), this.passesFilters)); this.computeTotal(matches); this.computeAvgPerDay( matches.Count, startDate, endDate); this.computeOldestTimestamp(matches); this.computeNewestTimestamp(matches); this.computeEarliestTimestamp(matches); this.computeLatestTimestamp(matches); }, this.LogDependencyName, Framework.Log.DependencyNames.Lotter); }
public virtual T[] Sort <T>( IEnumerable <T> finiteSource) where T : IComparable { if (finiteSource == null) { return(new T[zero]); } if (finiteSource is T[] array) { this.Sort( array, zero, array.Length - one); return(array); } var sourceArray = EnumerableHelpers.ToArray( finiteSource); this.Sort( sourceArray, zero, sourceArray.Length - one); return(sourceArray); }
public EnumerableHelpersTests() { _array = new[] { new A { X = 100, B = new B { Num = 1, Field = "f" } }, new A { X = 200, B = null }, null }; _contextMock = new Mock <IHandlebars>(); _sut = new EnumerableHelpers(_contextMock.Object); }
IEnumerator <T> IEnumerable <T> .GetEnumerator() { return(this.linkedList?.GetEnumerator() ?? EnumerableHelpers .Empty <T>() .GetEnumerator()); }
/// <summary> /// Uninstalls target-specific objects from current system. /// </summary> /// <param name="installationContext">The installation context.</param> /// <remarks> /// Uninstallation typically runs with administrative permissions. /// </remarks> public void Uninstall(InstallationContext installationContext) { if (installationContext == null) { throw new ArgumentNullException("installationContext"); } this.InitializeAll(); foreach (IInstallable installable in EnumerableHelpers.OfType <IInstallable>(this.configItems)) { installationContext.Info("Uninstalling '{0}'", installable); try { installable.Uninstall(installationContext); installationContext.Info("Finished uninstalling '{0}'.", installable); } catch (Exception exception) { if (exception.MustBeRethrown()) { throw; } installationContext.Error("Uninstallation of '{0}' failed: {1}.", installable, exception); } } }
public void OutputIndex(IndexOutputRequest indexOutputRequest) { IndexParameter indexParameter = IndexParameterParser.ParseIndexParameter(); DictionaryParameter dictionaryParameter = DictionaryParameterParser.ParseDictionaryParameter(); if (indexParameter.IsPresent) { List <string> dictionaryWords = DictionaryFileLoader.ReadWords(); int unknwonWordsCount = EnumerableHelpers.CountUnknownWords( distinctWords: indexOutputRequest.DistinctWords, dictionaryWords: dictionaryWords); if (dictionaryParameter.IsPresent) { DisplayOutput.WriteResourceLine( resourceIdent: "INDEX_WITH_UNKNOWN", placeholderValues: unknwonWordsCount); } else { DisplayOutput.WriteResourceLine( resourceIdent: "INDEX"); } DisplayWords( distinctWords: indexOutputRequest.DistinctWords, dictionaryWords: dictionaryWords); } }
Lot <T> Lotter.Materialize <T>( IEnumerable <T> source) { return(new ArrayLot <T>( EnumerableHelpers.ToArray( source))); }
public virtual bool Unregister <T>( string name = null) { var ds = this.dependencies; var unregistered = falsity; lock (this.locker) { foreach (var d in ds ?? EH.Empty <Dependency>()) { if (this.tryGet( d.Content, d.Name, name, out T _)) { unregistered = ds?.Remove(d) ?? falsity; break; } } } return(unregistered); }
public override int GetCount(bool onlyIfCheap) { int firstCount, secondCount; if (!EnumerableHelpers.TryGetCount(_first, out firstCount)) { if (onlyIfCheap) { return(-1); } firstCount = _first.Count(); } if (!EnumerableHelpers.TryGetCount(_second, out secondCount)) { if (onlyIfCheap) { return(-1); } secondCount = _second.Count(); } return(checked (firstCount + secondCount)); }
IEnumerator <T> IEnumerable <T> .GetEnumerator() { return(this.stack?.GetEnumerator() ?? EnumerableHelpers .Empty <T>() .GetEnumerator()); }
public static ReadOnlyCollection <T> ToReadOnly <T>(this IEnumerable <T> enumerable) { if (enumerable == null) { return(EmptyReadOnlyCollection <T> .Instance); } var troc = enumerable as TrueReadOnlyCollection <T>; if (troc != null) { return(troc); } var builder = enumerable as ReadOnlyCollectionBuilder <T>; if (builder != null) { return(builder.ToReadOnlyCollection()); } T[] array = EnumerableHelpers.ToArray(enumerable); return(array.Length == 0 ? EmptyReadOnlyCollection <T> .Instance : new TrueReadOnlyCollection <T>(array)); }
public void CountUnknownWordsTests_IEnumerables_null_Expect_0() { int actual = EnumerableHelpers.CountUnknownWords( distinctWords: null, dictionaryWords: null); Assert.Equal(expected: 0, actual: actual); }
public virtual MethodWebManager Shuffle() { var matchingManagers = this.shuffleManagers(); return(EH.FirstOrDefault( matchingManagers)?. Manager); }
public virtual string ReadString( IEnumerable <bool> bits, Encoding encoding) { return(encoding?.GetString( EnumerableHelpers.ToArray( this.GetBytes(bits)))); }
public virtual MethodWeb Shuffle() { var matchingWebs = this.shuffleWebs(); return(EnumerableHelpers.FirstOrDefault( matchingWebs)?. Web); }
public virtual long ReadNumber( IEnumerable <bool> bits) { var bytes = EnumerableHelpers.ToArray( this.GetBytes(bits)); return(BitConverter.ToInt64(bytes, 0)); }
public IEnumerable <ISolutionExplorerProject> EnumerateProjects() { if (project == null) { throw new InvalidOperationException("No project has been loaded yet."); } return(EnumerableHelpers.EnumerableOf(project)); }
// Returns an array of Directories in the current DirectoryInfo matching the // given search criteria (i.e. "System*" could match the System & System32 // directories). private DirectoryInfo[] InternalGetDirectories(String searchPattern, SearchOption searchOption) { Debug.Assert(searchPattern != null); Debug.Assert(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly); IEnumerable <DirectoryInfo> enumerable = (IEnumerable <DirectoryInfo>)FileSystem.Current.EnumerateFileSystemInfos(FullPath, searchPattern, searchOption, SearchTarget.Directories); return(EnumerableHelpers.ToArray(enumerable)); }
IEnumerator IEnumerable.GetEnumerator() { IEnumerable <T> source = this; return(source?.GetEnumerator() ?? EnumerableHelpers .Empty <T>() .GetEnumerator());; }
// Returns an array of strongly typed FileSystemInfo entries in the path with the // given search criteria (ie, "*.txt"). private FileSystemInfo[] InternalGetFileSystemInfos(String searchPattern, SearchOption searchOption) { Contract.Requires(searchPattern != null); Contract.Requires(searchOption == SearchOption.AllDirectories || searchOption == SearchOption.TopDirectoryOnly); IEnumerable <FileSystemInfo> enumerable = FileSystem.Current.EnumerateFileSystemInfos(FullPath, searchPattern, searchOption, SearchTarget.Both); return(EnumerableHelpers.ToArray(enumerable)); }
public ActionLot( IEnumerable <Action <T> > source, Lot <T> items) { this.actionSource = source ?? EnumerableHelpers.Empty <Action <T> >(); this.items = items ?? Lot.Empty <T>(); }
protected virtual ICollection <DateTime> readAllTimestamps() { ICollection <DateTime> collection = new XLinkedList <DateTime>(); var md = this.mainDirectory; try { if (!Directory.Exists(md)) { Directory.CreateDirectory(md); } } catch { return(collection); } string[] allDataFiles; try { allDataFiles = Directory.GetFiles(md); } catch { return(collection); } foreach (var filePath in allDataFiles) { IEnumerable <string> lines; try { lines = File.ReadAllLines(filePath); } catch { continue; } foreach (var line in lines) { if (!long.TryParse(line, out var ticks)) { continue; } collection.Add(new DateTime(ticks)); } } collection = EnumerableHelpers.OrderBy( collection, timestamp => timestamp); return(collection); }
public static TSource[] ToArray <TSource>(this IEnumerable <TSource> source) { if (source == null) { throw Error.ArgumentNull("source"); } IIListProvider <TSource> arrayProvider = source as IIListProvider <TSource>; return(arrayProvider != null?arrayProvider.ToArray() : EnumerableHelpers.ToArray(source)); }
protected virtual ICollection <DateTime> allTimes() { var r = this.runner; return(XLinkedList <DateTime> .Create( EnumerableHelpers.OrderBy( r?.Run <TimestampReader>() ?.ReadAll(), ts => ts))); }