封装一个类型转换的方法

public static class ObjectExtension

    {

        public static T Convert<T>(this object target)

        {

            T result = default(T);

 

            if (target != null)

            {

                result = (T)System.Convert.ChangeType(target, typeof(T), CultureInfo.InvariantCulture);

            }

 

            return result;

        }

    }

 

posted @ 2013-04-08 10:16  ゞ追忆o0ゞ  阅读(279)  评论(0编辑  收藏  举报