ソースコード public static string ReplaceFirst ( this string self, string oldValue, string newValue ) { var startIndex = self.IndexOf( oldValue ); if ( startIndex == -1 ) return self; return self .Remove( startIndex, oldValue.Length ) .Ins…
ソースコード using System; public static class FloatExtensions { public static bool IsZero( this float self ) { return self.IsZero( float.Epsilon ); } public static bool IsZero( this float self, float epsilon ) { return Math.Abs( self ) < …
拡張メソッド using NPOI.SS.UserModel; namespace Kogane { public static class ICellExtensionMethods { public static string GetValue( this ICell self ) { if ( self == null ) return string.Empty; return self.CellType switch { CellType.Numeric…
ソースコード using System; using System.Collections.Generic; using JetBrains.Annotations; namespace Kogane { public static class IEnumerablePeekExtensionMethods { public static IEnumerable<T> Peek<T> ( [NotNull] this IEnumerable<T> source, [NotNull</t></t></t>…
ソースコード using System; using System.Collections.Generic; using JetBrains.Annotations; using UnityEngine; namespace Kogane { public static class IEnumerableLogExtensionMethods { public delegate void LogDelegate( object item ); public st…
概要 using System.Collections.Generic; namespace Kogane { public static class SequenceJoinTupleExtensionMethods { public static (T1, T2)[] JoinTuple<T1, T2>( this T1[] self, T2[] other ) { var count = self.Length; var result = new (T1, T2)[ count </t1,>…
概要 using System.Collections.Generic; using System.Linq; namespace Kogane { public static class EnumerableExtensionMethods { public static IEnumerable<T> PrependIf<T> ( this IEnumerable<T> self, bool conditional, T element ) { return !conditional </t></t></t>…
ソースコード using System; using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static bool HasDuplication<TKey, TSource> ( this IEnumerable<TSource> self, Func<TSource, TKey> keySelector ) { return self .GroupBy( keySelector ) .Any( </tsource,></tsource></tkey,>…
ソースコード using System; public static class IntExt { public static int GetDigits( this int num ) { return num == 0 ? 1 : ( int ) Math.Log10( num ) + 1; } } 使用例 using System; public static class Program { private static void Main() { …
ソースコード using System; using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<TKey> GetDuplication<TKey, TSource> ( this IEnumerable<TSource> self, Func<TSource, TKey> keySelector ) { return self .GroupBy( keySelector )</tsource,></tsource></tkey,></tkey>…
ソースコード using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<(T item1, T item2)> Combine<T> ( this IEnumerable<T> first, IEnumerable<T> second ) { return first.SelectMany( i1 => se</t></t></t>…
はじめに 上記サイト様が、リストから組み合わせを取得できる関数を公開されております こちらを少し修正して、配列やリストから重複組合せを取得できる拡張メソッドを作りました ソースコード using System.Collections.Generic; using System.Linq; public…
はじめに 上記サイト様が、リストから組み合わせを取得できる関数を公開されております こちらを少し修正して、配列やリストから組合せを取得できる拡張メソッドを作りました ソースコード using System.Collections.Generic; using System.Linq; public sta…
ソースコード using System; using System.Reflection; public static class ParameterInfoExt { public static bool HasParams( this ParameterInfo param ) { var type = typeof( ParamArrayAttribute ); return param.GetCustomAttributes( type, false )…
ソースコード using System; public static class TypeExt { public static string GetAliasName( this Type self ) { switch ( self.FullName ) { case "System.Boolean": return "bool"; case "System.Byte": return "byte"; case "System.SByte": return …
ソースコード using System; using System.Collections.Generic; public static class ListExt { public static bool TryFind<T>( this List<T> self, Predicate<T> match, out T result ) where T : class { result = self.Find( match ); return result != null; } </t></t></t>…
はじめに 上記サイト様が公開されているプログラムを参考に 二次元配列を回転させる拡張メソッドを作成しました ソースコード public static class ArrayExt { // 時計回りに 90 度回転 public static T[,] RotateClockwise<T>( this T[,] self ) { int rows = </t>…
ソースコード using System.Text.RegularExpressions; public static class StringExt { public static int ExtractInteger( this string self ) { return int.Parse( Regex.Replace( self, @"[^0-9]", string.Empty ) ); } } 使い方 var str1 = "s012"; Con…
はじめに 「FastEnum」をプロジェクトに追加することで 高速な列挙型の API を使用できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します 「参照」タ…
はじめに 「FastLinq」をプロジェクトに追加することで 高速な LINQ を使用できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します 「参照」タブを選…
ソースコード using System.Collections.Generic; using System.Linq; public static class IListExt { public static void Deconstruct<T> ( this IList<T> self, out T first, out IList<T> rest ) { first = self.Count > 0 ? self[ 0 ] : default; rest = self.Sk</t></t></t>…
ソースコード using System; using System.Collections.Generic; public static class IEnumerableExt { public static IEnumerable<(int index, T value)> WithIndex<T> ( this IEnumerable<T> source ) { if ( source == null ) { throw new ArgumentNullExcepti</t></t>…
ソースコード using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<T> Concat<T> ( this IEnumerable<T> first, params T[] second ) { return Enumerable.Concat( first, second ); } } 使用例 </t></t></t>…
ソースコード using System; using System.Collections.Generic; public static class IEnumerableExt { public static Tuple<IEnumerable<T>, IEnumerable<T>> Partition<T> ( this IEnumerable<T> self, Func<T, bool> predicate ) { var ok = new List<T>(); var ng = new List<T>(); foreach ( v</t></t></t,></t></t></t></ienumerable<t>…
ソースコード using System.Collections.Generic; using System.Linq; public static class IEnumerableExt { public static IEnumerable<T> Flatten<T> ( this IEnumerable<IEnumerable<T>> self ) { return self.SelectMany( c => c ); } } 使用例 通常 foreach ( var n in list</ienumerable<t></t></t>…
ソースコード using System.Collections.Generic; public static class DictionaryExt { public static bool Remove<TKey, TValue> ( this Dictionary<TKey, TValue> self, TKey key, out TValue value ) { self.TryGetValue( key, out value ); return self.Remove( key ); } } 使用方法</tkey,></tkey,>…
ソースコード System.Random 版 using System; using System.Collections.Generic; using System.Linq; public static partial class IEnumerableExt { private static readonly Random m_random = new Random(); public static T RandomAt<T>( this IEnumerable<T></t></t>…
はじめに 「LinqFaster」をプロジェクトに追加することで 高速な LINQ を使用できるようになります インストール Visual Studio メニューの「ツール>NuGet パッケージ マネージャー> ソリューションの NuGet パッケージの管理」を選択します 「参照」タブを…
ソースコード public static class StringExt { public static bool IsLower( this string self ) { for ( int i = 0; i < self.Length; i++ ) { if ( char.IsUpper( self[ i ] ) ) { return false; } } return true; } } 使い方 var str = "abcde"; var isL…
ソースコード public static class StringExt { public static bool IsUpper( this string self ) { for ( int i = 0; i < self.Length; i++ ) { if ( char.IsLower( self[ i ] ) ) { return false; } } return true; } } 使い方 var str = "ABCDE"; var isU…