public static StringBuilder Concat(this StringBuilder stringBuilder, int value, uint pad, char padChar, uint baseValue) { if (value < 0) // Deal with negative numbers { stringBuilder.Append('-'); uint num = uint.MaxValue - ((uint)value) + 1; //< This is to deal with Int32.MinValue stringBuilder.Concat(num, pad, padChar, baseValue); } else stringBuilder.Concat((uint)value, pad, padChar, baseValue); return stringBuilder; }
public static IList<string> GetValidMongoObjectIds(this IList<string> ids, IList<string> existentIds = null) { if (ids == null && existentIds == null) return null; if (ids != null && existentIds != null) return ids.Concat(existentIds).ToList(); if (ids == null) ids = existentIds; if (!ids.Any()) return ids; IList<string> result = new List<string>(); foreach (var id in ids) { if (id == null) continue; if (!id.IsValidMongoObjectId()) continue; result.Add(id); } return result; }
public static IEnumerable<Point> Glue( this IEnumerable<Point> first, IEnumerable<Point> second) { return first.Concat(second) .RemoveSequentialRepeats(); }
public static IEnumerable<string> AddMoveMatches(this IEnumerable<string> assetPaths, IVersionControlCommands vcc) { List<string> moveMatches = new List<string>(); var allDeleted = vcc.GetFilteredAssets(status => status.fileStatus == VCFileStatus.Deleted); var allAdded = vcc.GetFilteredAssets(status => status.fileStatus == VCFileStatus.Added); var commitDeleted = assetPaths.Where(a => vcc.GetAssetStatus(a).fileStatus == VCFileStatus.Deleted); var commitAdded = assetPaths.Where(a => vcc.GetAssetStatus(a).fileStatus == VCFileStatus.Added); foreach (var deleted in allDeleted) { var deletedPath = deleted.assetPath.Compose(); if (commitAdded.Count(added => added.EndsWith(Path.GetFileName(deletedPath))) > 0) { moveMatches.Add(deletedPath); } if (commitAdded.Count(added => added.StartsWith(Path.GetDirectoryName(deletedPath)) && Path.GetExtension(deletedPath) == Path.GetExtension(added)) > 0) { moveMatches.Add(deletedPath); } } foreach (var added in allAdded) { var addedPath = added.assetPath.Compose(); if (commitDeleted.Count(deleted => deleted.EndsWith(Path.GetFileName(addedPath))) > 0) { moveMatches.Add(addedPath); } if (commitDeleted.Count(deleted => deleted.StartsWith(Path.GetDirectoryName(addedPath)) && Path.GetExtension(addedPath) == Path.GetExtension(deleted)) > 0) { moveMatches.Add(addedPath); } } return assetPaths.Concat(moveMatches).ToArray(); }
public static MyData[] ConcatDistinct(this MyData[] source, MyData e) { if (source.Contains(e.Name)) return source; return source.Concat(e); }
public static IEnumerable<string> AddDeletedInFolders(this IEnumerable<string> assetPaths, IVersionControlCommands vcc) { var deletedInFolders = assetPaths .SelectMany(d => vcc.GetFilteredAssets(status => (status.fileStatus == VCFileStatus.Deleted || status.fileStatus == VCFileStatus.Missing) && status.assetPath.StartsWith(new ComposedString(d)))) .Select(status => status.assetPath.Compose()) .ToArray(); return assetPaths.Concat(deletedInFolders).ToArray(); }
public static IEnumerable<double> NormalizedHammingConvolve(this IEnumerable<byte> source) { int offset = 0; foreach (var b in source) { var padding = Enumerable.Repeat((byte)0, offset); yield return Hamming(padding.Concat(source), source.Concat(padding))/(double)offset; offset++; } }
public static IHtml ToInline( this IEnumerable<string> lines, IEnumerable<Type> types = null) { return "script" .Attr("type", "text/javascript") .Add(string.Join("\n", lines.Concat(types.ToRenderables().Select(r => r.ToHtml().ToString())) .ToArray())); }
public static IEnumerable<Peptide> BuildSpectre(this Peptide peptide) { var res = new HashSet<Peptide>(); var doubledPeptide = peptide.Concat(peptide); for (uint l = 1; l < peptide.Length; l++) { for (uint i = 0; i < peptide.Length; i++) { var pep = doubledPeptide.Substring(i, l); res.Add(pep); } } return res; }
public static IEnumerable<string> AddFilesInFolders(this IEnumerable<string> assets, IVersionControlCommands vcc, bool versionedFoldersOnly = false) { foreach (var assetIt in new List<string>(assets)) { if (Directory.Exists(assetIt) && (!versionedFoldersOnly || vcc.GetAssetStatus(assetIt).fileStatus != VCFileStatus.Unversioned)) { assets = assets .Concat(Directory.GetFiles(assetIt, "*", SearchOption.AllDirectories) .Where(a => File.Exists(a) && !a.Contains("/.") && !a.Contains("\\.") && (File.GetAttributes(a) & FileAttributes.Hidden) == 0) .Select(s => s.Replace("\\", "/"))) .ToArray(); } } return assets; }
public static bool TryAddItem(this IEnumerable<DataRow> inputCollection, DataRow itemToAdd, out ICollection<DataRow> outputCollection) { bool result = false; outputCollection = null; if (inputCollection.All(item => !item.ContentEquals(itemToAdd))) { inputCollection = inputCollection.Concat(new[] { itemToAdd }); outputCollection = inputCollection.ToArray(); result = true; } return result; }
public static RouteValueDictionary MergeWith(this RouteValueDictionary source, RouteValueDictionary anotherDictionary) { if (source == null) return null; if (anotherDictionary == null) return source; return new RouteValueDictionary( source .Concat(anotherDictionary) .ToLookup( x => x.Key, x => x.Value ) .ToDictionary( x => x.Key, x => x.Last() ) ); }
/// <summary> /// Appends an integer to the specified StringBuilder, separating each group of 3 digits with commas. /// </summary> /// <param name="sb">The <see cref="StringBuilder"/> to which to append the value.</param> /// <param name="value">The value to append to the <see cref="StringBuilder"/>.</param> public static void AppendIntWithCommas(this StringBuilder sb, int value) { Contract.Require(sb, nameof(sb)); var group = 0; var written = 0; for (int div = 1000000000; div > 0; div /= 1000) { group = value / div; if (group > 0 || div == 1) { if (written > 0) { sb.Append(","); } sb.Concat(group, (written > 0) ? 3u : 1u); written++; } value -= group * div; } }
public static StringBuilder GetFormatedDateTimeOffset(this StringBuilder sb, string before, DateTime value, string after = "") { sb.Clear(); //sb.ConcatFormat("{0}{1: yyyy-MM-dd HH:mm:ss.fff}{2}", before, value, after); sb.Append(before); sb.Concat(value.Year, 4, '0', 10, false); sb.Append("-"); sb.Concat(value.Month, 2); sb.Append("-"); sb.Concat(value.Day, 2); sb.Append(" "); sb.Concat(value.Hour, 2); sb.Append(":"); sb.Concat(value.Minute, 2); sb.Append(":"); sb.Concat(value.Second, 2); sb.Append("."); sb.Concat(value.Millisecond, 3); sb.Append(after); return sb; }
//! Convert a given unsigned integer value to a string and concatenate onto the stringbuilder. Assume base ten. public static StringBuilder Concat( this StringBuilder string_builder, uint uint_val, uint pad_amount, char pad_char ) { string_builder.Concat( uint_val, pad_amount, pad_char, 10, true ); return string_builder; }
//! Convert a given unsigned integer value to a string and concatenate onto the stringbuilder. Assume no padding and base ten. public static StringBuilder Concat( this StringBuilder string_builder, uint uint_val ) { string_builder.Concat( uint_val, 0, ms_default_pad_char, 10, true ); return string_builder; }
//! Convert a given float value to a string and concatenate onto the stringbuilder. public static StringBuilder Concat(this StringBuilder string_builder, float float_val, uint decimal_places, uint pad_amount) { string_builder.Concat(float_val, decimal_places, pad_amount, ms_default_pad_char); return string_builder; }
//! Convert a given float value to a string and concatenate onto the stringbuilder. Assumes five decimal places, and no padding. public static StringBuilder Concat(this StringBuilder string_builder, float float_val) { string_builder.Concat(float_val, ms_default_decimal_places, 0, ms_default_pad_char); return string_builder; }
//! Convert a given signed integer value to a string and concatenate onto the stringbuilder. Assume base ten. public static StringBuilder Concat( this StringBuilder string_builder, int int_val, uint pad_amount ) { string_builder.Concat( int_val, pad_amount, ms_default_pad_char, 10, true ); return string_builder; }
//! Convert a given signed integer value to a string and concatenate onto the stringbuilder. Any base value allowed. public static StringBuilder Concat(this StringBuilder string_builder, long long_val, uint pad_amount, char pad_char, uint base_val, bool thousandSeparation) { Debug.Assert(pad_amount >= 0); Debug.Assert(base_val > 0 && base_val <= 16); // Deal with negative numbers if (long_val < 0) { string_builder.Append('-'); long uint_val = long.MaxValue - ((long)long_val) + 1; //< This is to deal with Int32.MinValue string_builder.Concat(uint_val, pad_amount, pad_char, base_val, thousandSeparation); } else { string_builder.Concat((uint)long_val, pad_amount, pad_char, base_val, thousandSeparation); } return string_builder; }
public static IEnumerable<StatementSyntax> AppendUnlessJumps(this IEnumerable<StatementSyntax> statements, IEnumerable<StatementSyntax> tailStatements) { if (Syntax.Block(statements: Syntax.List(statements)).IsGuaranteedToJumpOut()) return statements; return statements.Concat(tailStatements); }
//! Convert a given float value to a string and concatenate onto the stringbuilder public static StringBuilder Concat(this StringBuilder string_builder, float float_val, uint decimal_places, uint pad_amount, char pad_char) { Debug.Assert(pad_amount >= 0); if (decimal_places == 0) { // No decimal places, just round up and print it as an int // Agh, Math.Floor() just works on doubles/decimals. Don't want to cast! Let's do this the old-fashioned way. int int_val; if (float_val >= 0.0f) { // Round up int_val = (int)(float_val + 0.5f); } else { // Round down for negative numbers int_val = (int)(float_val - 0.5f); } string_builder.Concat(int_val, pad_amount, pad_char, 10); } else { int int_part = (int)float_val; // First part is easy, just cast to an integer string_builder.Concat(int_part, pad_amount, pad_char, 10); // Decimal point string_builder.Append('.'); // Work out remainder we need to print after the d.p. float remainder = Math.Abs(float_val - int_part); // Multiply up to become an int that we can print do { remainder *= 10; decimal_places--; } while (decimal_places > 0); // Round up. It's guaranteed to be a positive number, so no extra work required here. remainder += 0.5f; // All done, print that as an int! string_builder.Concat((uint)remainder, 0, '0', 10); } return string_builder; }
public static StringBuilder GetFormatedDateTimeForFilename(this StringBuilder sb, DateTime value) { sb.Clear(); //sb.ConcatFormat("{0}{1: yyyy-MM-dd HH:mm:ss.fff}{2}", before, value, after); sb.Concat(value.Year, 0, '0', 10, false); sb.Concat(value.Month, 2); sb.Concat(value.Day, 2); sb.Append("_"); sb.Concat(value.Hour, 2); sb.Concat(value.Minute, 2); sb.Concat(value.Second, 2); return sb; }
public static IEnumerable<IDataPoint> Add( this IEnumerable<IDataPoint> dp, string name, object val) { return dp.Concat(new DataPoint(name, val).Lift()); }
public static int Max(this IEnumerable<int> collection) => Enumerable.Max(collection.Concat(new[] { int.MinValue }));
public static IEnumerable<ConsoleKeyInfo> AddInputSequence(this IEnumerable<ConsoleKeyInfo> sequence, string text) { return sequence.Concat(text.ToInputSequence()); }
public static StringBuilder GetFormatedTimeSpan(this StringBuilder sb, string before, TimeSpan value, string after = "") { sb.Clear(); //sb.ConcatFormat("{0}{1}{2}", before, value, after); sb.Clear(); //sb.ConcatFormat("{0}{1: yyyy-MM-dd HH:mm:ss.fff}{2}", before, value, after); sb.Append(before); sb.Concat(value.Hours, 2); sb.Append(":"); sb.Concat(value.Minutes, 2); sb.Append(":"); sb.Concat(value.Seconds, 2); sb.Append("."); sb.Concat(value.Milliseconds, 3); sb.Append(after); return sb; }
public static IEnumerable<ConsoleKeyInfo> AddLeftArrowHit(this IEnumerable<ConsoleKeyInfo> sequence) { return sequence.Concat(Enumerable.Repeat(new ConsoleKeyInfo(default(char), ConsoleKey.LeftArrow, false, false, false), 1)); }
public static byte[] Append(this byte[] source, params int[] paramenters) { return source.Concat(paramenters.SelectMany(x => x.ToByteArray())).ToArray(); }
public static IEnumerable<ConsoleKeyInfo> AddRightArrowHit(this IEnumerable<ConsoleKeyInfo> sequence, int times) { return sequence.Concat(Enumerable.Repeat(new ConsoleKeyInfo(default(char), ConsoleKey.RightArrow, false, false, false), times)); }