wpf+.net 4.5 surface2.0 = 异步多点触控 时间轴 part6

20 篇文章 0 订阅
19 篇文章 0 订阅

最后是工具类用于扩展lambda 污染循环

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Data;
using System.Threading;

namespace Transvalue.Timeline
{
    public static class Pollute
    {
        public static int ToInt32(this string Value)
        {
            try
            {
                int a = Int32.Parse(Value);
                return a;
            }
            catch
            {
                return -1;
            }
        }
        /// <summary>
        /// 如果类型值为Null则返回实例
        /// </summary>
        /// <param name="Value">类型值</param>
        /// <returns></returns>
        public static string DecideNull(this string Value)
        {
            if (Value == null)
            {
                return "";
            }
            else
            {
                return Value;
            }
        }


        /// <summary>
        /// 通过字典的值找KEY列表
        /// </summary>
        /// <typeparam name="T">字典的索引类型</typeparam>
        /// <typeparam name="R">字典的值类型</typeparam>
        /// <param name="dictionary">查询字典</param>
        /// <param name="Value">查询的值</param>
        /// <returns></returns>
        public static List<T> GetKey<T, R>(this Dictionary<T, R> dictionary, R Value)
        {
            List<T> list = new List<T>();
            var a = new Dictionary<Predicate<R>, Action<R>>() 
            {
                { x => dictionary.Values.Contains(x),s => dictionary.Where(i=>i.Value.Equals(s)).ForEach(b=>list.Add(b.Key))}
            };
            a.Where(i => i.Key(Value)).ForEach(i => i.Value(Value));
            return list;
        }
        /// <summary>
        /// 通过字典索引列表返回字典差集
        /// </summary>
        /// <typeparam name="T">字典索引类型</typeparam>
        /// <typeparam name="R">值的类型</typeparam>
        /// <param name="dictionary">字典</param>
        /// <param name="Enumerable">对比索引列表</param>
        /// <returns></returns>
        public static Dictionary<T, R> GetInexistence<T, R>(this Dictionary<T, R> dictionary, IEnumerable<T> Enumerable)
        {
            var a = dictionary.Keys.Except(Enumerable);
            Dictionary<T, R> list = new Dictionary<T, R>();
            foreach (var item in a)
            {
                list.Add(item, dictionary[item]);
            }
            return list;
        }

        public static string GetStringReverse(this string str, int Count)
        {
            string temp = string.Empty;
            int i = 0;

            while (i < str.Count())
            {
                var a = str.Skip(i).Take(Count);
                a.Reverse<char>().ForEach<char>(c => temp += c);
                i += Count;
            }
            return temp;

        }
        /// <summary>
        /// 对IEnumerable泛型类进行污染,循环访问IEnumerable泛型类里的内容,将每个结果发送给指定的方法
        /// </summary>
        /// <typeparam name="T">类型标识符</typeparam>
        /// <typeparam name="R">返回值标识符</typeparam>
        /// <param name="source">>IEnumerable泛型数组</param>
        /// <param name="func">将值发送给指定的方法,该方法接受一个传入参数且不返回值,如:Pollute.log()</param>
        /// <returns></returns>
        public static List<R> ForEach<T, R>(this IEnumerable<T> source, Func<T, R> func)
        {
            List<R> list = new List<R>();
            foreach (var item in source)
            {
                list.Add(func(item));
            }
            return list;
        }

        /// <summary>
        /// 对IEnumerable泛型类进行污染,循环访问IEnumerable泛型类里的内容,将每个结果发送给指定的方法
        /// </summary>
        /// <typeparam name="T">类型标识符</typeparam>
        /// <typeparam name="R">返回值标识符</typeparam>
        /// <param name="source">>IEnumerable泛型数组</param>
        /// <param name="func">将值发送给指定的方法,该方法接受一个传入参数且不返回值,如:Pollute.log()</param>
        /// <returns></returns>
        public static List<R> ForEach<T, R>(this IEnumerable<T> source, Func<T, R> func, object o)
        {
            List<R> list = new List<R>();
            T t = (T)o;
            foreach (T item in source)
            {
                if (item.GetHashCode() == t.GetHashCode())
                {
                    list.Add(func(item));
                }
                else
                {
                    list.Add((R)(object)item);
                }
            }
            return list;
        }
        /// <summary>
        /// 对IEnumerable泛型类进行污染,循环访问IEnumerable泛型类里的内容,将每个结果发送给指定的方法
        /// </summary>
        /// <typeparam name="T">类型标示符</typeparam>
        /// <param name="source">IEnumerable泛型数组</param>
        /// <param name="func">将值发送给指定的方法,该方法接受一个传入参数且不返回值,如:Pollute.log()</param>
        public static void ForEach<T>(this IEnumerable<T> source, Action<T> act)
        {
            foreach (var item in source)
            {
                act(item);
            }
        }


        public static void ForEach<T>(this DataColumnCollection DataTable, Action<T> act) where T : class
        {
            foreach (DataColumn item in DataTable)
            {
                T t = item as T;
                act(t);
            }
        }

        public static void ForEach<T>(this DataRowCollection DataTable, Action<T> act) where T : class
        {
            foreach (DataRow item in DataTable)
            {
                T t = item as T;
                act(t);
            }
        }

        public static void ForEach(this DataRow DataRow, Action<object> act)
        {
            foreach (var item in DataRow.ItemArray)
            {
                act(item);
            }
        }

        /// <summary>
        /// 取垂直线的斜率
        /// </summary>
        /// <param name="f">原始线的斜率</param>
        /// <returns></returns>
        public static float GetSlope(this float f)
        {
            return -1 / f;
        }

        /// <summary>
        /// 直角坐标转换为角坐标,返回 0-2pi
        /// </summary>
        /// <param name="x">x坐标。</param>
        /// <param name="y">y坐标。</param>
        /// <returns></returns>
        public static double GetAngle(this double x, double y)
        {
            y = -y;
            if (x > 0)
            {
                if (y > 0)
                {
                    return Math.Atan(y / x);
                }
                else
                {
                    return 6.28 + Math.Atan(y / x);
                }
            }
            else if (x < 0)
            {
                return Math.Atan(y / x) + Math.PI;
            }
            else
            {
                if (y > 0)
                    return Math.PI / 2;
                else if (y == 0)
                    return 0;
                else
                    return Math.PI * 1.5;
            }
        }

        public static void log(string msg)
        {
            Console.WriteLine("{0}: {1}", Thread.CurrentThread.ManagedThreadId, msg);
        }

    }
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值