Project description

Hopefully useful C# extensions.

Why to "See Sharper"

LINQ is certainly a great library, but I personally have never got used to the way of thinking, which are LINQ developers forced to. Since I'm using Java and Groovy (and the great language features of both) for many years, I decided to re-implement some of them for the .NET environment.

See.Sharper can therefore be seen as a lightweight (and much much simpler) replacement of LINQ.

All extension methods seen in See.Sharper are implemented using Extension methods and Lambda expressions, they do not simply cover the LINQ methods.

Important methods extending IEnumerable and IEnumerable<I> types (i.e. collections) have their corresponding parallel overloads. The advantage of parallel processing is that you can spread the load on all available cores and reduce the time required to perform the requested operation (in my testing approx. 45% on dual core machine running 32-bit OS).

Use it with joy, I hope that See.Sharper save you a lot of time and will make your code more readable, transparent .. and groovy :-)

Although this project is open, you can support the authors by making a donation.

Several examples

Recursive file listing with filter

  List<FileInfo> files = new List<FileInfo>();

  new DirectoryInfo(@"<MyProjectFolder>").With(folder => {
    folder.EachFileRecurse(file => {
      files.Add(file);
    });
  });

  bool doInParallel = true;

  /* List all C# source files */
  files.FindAll<FileInfo>(doInParallel, file => file.Name.EndsWith(".cs")).EachWithIndex<FileInfo>(doInParallel, (file, index) => {
    System.Console.WriteLine(
      "File #{0} : {1}", new object[] { index, file.Name }
    );
  });

Overview of methods

  • System.Array
    • object First(this Array self)
    • T First<T>(this Array self)
    • bool IndexInBounds(this Array self, int index)
    • bool IndexInBounds(this Array self, long index)
    • object Last(this Array self)
    • T Last<T>(this Array self)
  • System.Boolean
    • Boolean And(this Boolean self, Boolean right)
    • Boolean Or(this Boolean self, Boolean right)
    • Boolean Xor(this Boolean self, Boolean right)
  • System.Int32
    • bool IsEven(this Int32 self)
    • bool IsOdd(this Int32 self)
    • void Times<Int32>(this Int32 self, Action<int> action)
  • System.IDisposable
    • void Using<I>(this I self, Action<I> action) where I : IDisposable
  • System.Object
    • void With<I>(this I self, Action<I> action)
  • System.String
    • string Decrypt(this string self, string password)
    • string Encrypt(this string self, string password)
    • bool EqualsIgnoreCase(this string self, string s)
    • bool Matches(this string self, string pattern)
  • System.Uri
    • FileInfo Download(this Uri self, string localPath)
  • System.Collections.IEnumerable
    • IList Collect(this IEnumerable self, Func<object, object> transformer)
    • IList Collect(this IEnumerable self, bool parallel, Func<object, object> transformer)
    • static IList CollectParallel(this IEnumerable self, Func<object, object> transformer)
    • int Count(this IEnumerable self, Func<object, bool> filter)
    • int Count(this IEnumerable self, bool parallel, Func<object, bool> filter)
    • int CountParallel(this IEnumerable self, Func<object, bool> filter)
    • void Each(this IEnumerable self, Action<object> action)
    • void Each(this IEnumerable self, bool parallel, Action<object> action)
    • void EachParallel(this IEnumerable self, Action<object> action)
    • void EachWithIndex(this IEnumerable self, Action<object, int> action)
    • void EachWithIndex(this IEnumerable self, bool parallel, Action<object, int> action)
    • void EachWithIndexParallel(this IEnumerable self, Action<object, int> action)
  • System.Collections.Generic.IEnumerable<I>
    • IList<O> Collect<I, O>(this IEnumerable<I> self, Func<I, O> transformer)
    • IList<O> Collect<I, O>(this IEnumerable<I> self, bool parallel, Func<I, O> transformer)
    • IList<O> CollectParallel<I, O>(this IEnumerable<I> self, Func<I, O> transformer)
    • void Each<I>(this IEnumerable<I> self, Action<I> action)
    • void Each<I>(this IEnumerable<I> self, bool parallel, Action<I> action)
    • void EachParallel<I>(this IEnumerable<I> self, Action<I> action)
    • void EachWithIndex<I>(this IEnumerable<I> self, Action<I, int> action)
    • void EachWithIndex<I>(this IEnumerable<I> self, bool parallel, Action<I, int> action)
    • void EachWithIndexParallel<I>(this IEnumerable<I> self, Action<I, int> action)
    • I Find<I>(this IEnumerable<I> self, Func<I, bool> filter)
    • IList<I> FindAll<I>(this IEnumerable<I> self, Func<I, bool> filter)
    • IList<I> FindAll<I>(this IEnumerable<I> self, bool parallel, Func<I, bool> filter)
    • IList<I> FindAllParallel<I>(this IEnumerable<I> self, Func<I, bool> filter)
    • IDictionary<K, List<I>> GroupBy<I, K>(this IEnumerable<I> self, Func<I, K> mapper)
    • string ToListString<I>(this IEnumerable<I> self)
    • string ToListString<I>(this IEnumerable<I> self, string separator)
    • string ToListString<I>(this IEnumerable<I> self, string separator, bool keepLastSeparator)
    • IList<I> Unique<K, I>(this IEnumerable<I> self, Func<I, K> mapper)
  • System.IO.DirectoryInfo
    • void CreateFully(this DirectoryInfo self)
    • void EachFile(this DirectoryInfo self, Action<FileInfo> action)
    • void EachFile(this DirectoryInfo self, string pattern, Action<FileInfo> action)
    • void EachFileRecurse(this DirectoryInfo self, Action<FileInfo> action)
    • void EachFileRecurse(this DirectoryInfo self, string pattern, Action<FileInfo> action)
  • System.IO.FileInfo
    • void EachByte(this FileInfo self, Action<byte> action)
    • void EachLine(this FileInfo self, Action<string> action)
    • void WithReader(this FileInfo self, Action<StreamReader> action)
    • void WithReader(this FileInfo self, Encoding encoding, Action<StreamReader> action)
  • System.IO.FileSystemInfo
    • string GetRelativeName(this FileSystemInfo self, FileSystemInfo parent)
    • string GetRelativeName(this FileSystemInfo self, string parent)
  • System.IO.Stream
    • void CloseQuietly(this Stream self)
    • void CopyTo<S>(this S self, S target) where S : Stream
    • void CopyTo<S>(this S self, S target, int bufferSize) where S : Stream
    • void CopyTo<S>(this S self, S target, bool closeSelf, bool closeTarget) where S : Stream
    • void CopyTo<S>(this S self, S target, int bufferSize, bool closeSelf, bool closeTarget) where S : Stream
  • System.IO.TextReader
    • void CloseQuietly(this TextReader self)

Last edited Sep 17, 2010 at 7:51 AM by Yasas, version 15