2012年6月4日

I spent more than 2 days get these. Hope it help your code shorter

especially in lambda expression.

It works for both structure and reference types.

 1 public static bool IsItemOfCollection<T, TCollection>(this T thisT, TCollection collection) where TCollection : ICollection<T>
 2         {
 3             return collection.Contains(thisT);
 4         }
 5 
 6 public static bool Greater<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T>
 7         {
 8             return thisT.CompareTo(obj) > 0;
 9         }
10 
11         public static bool Less<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T>
12         {
13             return thisT.CompareTo(obj) < 0;
14         }
15 
16         public static bool GreaterThan<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T>
17         {
18             return thisT.CompareTo(obj) >= 0;
19         }
20 
21         public static bool LessThan<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T>
22         {
23             return thisT.CompareTo(obj) <= 0;
24         }
25 
26         public static bool NotEquals<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T>
27         {
28             return !thisT.Equals(obj);
29         }
posted @ 2012-06-04 00:57 IT老民工 阅读(8) 评论(0) 编辑

2011年12月22日

        /// <summary>
        /// Convert DataTable to Html Table.
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <returns>Html string</returns>
        public static string ToHtmlTable(this DataTable dt)
        {
            GridView gridView = new GridView();
            gridView.AutoGenerateColumns = true;
            gridView.DataSource = dt;
            gridView.DataBind();
 
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter htw = new HtmlTextWriter(sw);
 
            gridView.RenderControl(htw);
 
            return sb.ToString();
        }
posted @ 2011-12-22 02:06 IT老民工 阅读(45) 评论(0) 编辑

2011年8月23日

摘要: jQuery Filter ID阅读全文
posted @ 2011-08-23 06:21 IT老民工 阅读(32) 评论(0) 编辑

2011年8月9日

Can't find sequence as Oracle sequence. I did one on Ms SQL server

create a table only one column "id"

CREATE PROCEDURE dbo.GetSeqenceNumber

AS

DECLARE @count decimal

SELECT @count = id FROM JsSequence

UPDATE JsSequence

SET id = @count + 1

SELECT id FROM JsSequence

posted @ 2011-08-09 04:35 IT老民工 阅读(53) 评论(0) 编辑
 

using System.Web.Script.Serialization;


public static class JsonExtension

    {

        public static T JsonToObject<T>(this string sJson)

        {

            return (T)new JavaScriptSerializer().Deserialize(sJson, typeof(T));

        }

 

        public static string ObjectToJson(this object obj)

        {

            return new JavaScriptSerializer().Serialize(obj);

        }

    }

posted @ 2011-08-09 04:05 IT老民工 阅读(68) 评论(0) 编辑

2011年4月1日

折腾了小半天,发现EntLib5.0 reference GAC not work. You can use assembly as reference from EntLib50Src\bin only.

Don't know what is wrong but this way works fine.

posted @ 2011-04-01 21:12 IT老民工 阅读(54) 评论(0) 编辑

2011年1月12日

摘要: Spent about 2 hours get this idea.阅读全文
posted @ 2011-01-12 23:47 IT老民工 阅读(108) 评论(0) 编辑

2010年9月29日

摘要: 1. 把两个DICTIONARY 叠加在一起。并且返回DICTIONARY.2. 给DICTIONARY的VALUE排序。我从GOOGLE上找不到现成的, 只好花时间写了两段。希望节约大家的时间。阅读全文
posted @ 2010-09-29 11:49 IT老民工 阅读(402) 评论(0) 编辑

2010年9月22日

摘要: 代码阅读全文
posted @ 2010-09-22 19:05 IT老民工 阅读(114) 评论(0) 编辑

2010年9月13日

摘要: 从不抱怨,如果你不喜欢你目前的环境,改变它。如果你不能改变它,改变你自己。If you don't like your environment change it. If you can't change it, change yourself.阅读全文
posted @ 2010-09-13 07:48 IT老民工 阅读(35) 评论(0) 编辑