Popular Posts
Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i... javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... SwiXml - Layout BorderLayout BorderLayoutPane.xml <?xml version="1.0" encoding="UTF-8"?> <panel layout="BorderLayout...
Stats
Linq: Loop extension
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Linq
{
    public static class GenericEachExtension
    {
        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (T t in source)
            {
                action.Invoke(t);
            }
            return source;
        }

        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Func<T, bool> action)
        {
            foreach (T t in source)
            {
                if (!action.Invoke(t)) break;
            }
            return source;
        }

        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Action<T, int> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                action.Invoke(t, i);
                i++;
            }
            return source;
        }

        public static IEnumerable<T> Each<T>(this IEnumerable<T> source, Func<T, int, bool> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                if (!action.Invoke(t, i)) break;
                i++;
            }
            return source;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Collections
{
    public static class EachExtension
    {
        public static IEnumerable Each<T>(this IEnumerable source, Action<T> action)
        {
            foreach (T t in source)
            {
                action.Invoke(t);
            }
            return source;
        }

        public static IEnumerable Each<T>(this IEnumerable source, Func<T, bool> action)
        {
            foreach (T t in source)
            {
                if (!action.Invoke(t)) break;
            }
            return source;
        }

        public static IEnumerable Each<T>(this IEnumerable source, Action<T, int> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                action.Invoke(t, i);
                i++;
            }
            return source;
        }

        public static IEnumerable Each<T>(this IEnumerable source, Func<T, int, bool> action)
        {
            int i = 0;
            foreach (T t in source)
            {
                if (!action.Invoke(t, i)) break;
                i++;
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Action<object> action)
        {
            foreach (object t in source)
            {
                action.Invoke(t);
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Func<object, bool> action)
        {
            foreach (object t in source)
            {
                if (!action.Invoke(t)) break;
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Action<object, int> action)
        {
            int i = 0;
            foreach (object t in source)
            {
                action.Invoke(t, i);
                i++;
            }
            return source;
        }

        public static IEnumerable Each(this IEnumerable source, Func<object, int, bool> action)
        {
            int i = 0;
            foreach (object t in source)
            {
                if (!action.Invoke(t, i)) break;
                i++;
            }
            return source;
        }
    }
}