C# 对JS编码/解码进行转换

2020-12-13 16:34

阅读:346

标签:des   class   blog   code   ext   get   

 public static class Extension
    {
        #region [编码/解码统一转换]
        /// 
        /// 
        /// 
        /// 
        /// True为Encode;False为Decode
        /// 
        public static string JSCodingString(this string str, bool isEscape = false)
        {
            if (isEscape)
                return Microsoft.JScript.GlobalObject.escape(str);
            else
                return Microsoft.JScript.GlobalObject.unescape(str);
        }

        /// 
        /// js编码解码
        /// 
        /// 
        /// 
        public static void JSCodingEntityList(this List lsto, bool isEscape = false)
        {
            foreach (object o in lsto)
            {
                JSCodingEntity(o, isEscape);
            }
        }

        /// 
        /// js编码解码
        /// 
        /// 
        /// 
        public static void JSCodingEntity(this T o, bool isEscape = false)
        {
            object objValue;
            System.Reflection.PropertyInfo[] propertys = o.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo p in propertys)
            {
                if (p.PropertyType == typeof(System.String))
                {
                    objValue = p.GetValue(o, null);
                    if (objValue != null)
                    {
                        if (objValue.GetType() == typeof(System.String))
                        {
                            if (isEscape)
                                p.SetValue(o, Microsoft.JScript.GlobalObject.escape(objValue.ToString()), null);
                            else
                                p.SetValue(o, Microsoft.JScript.GlobalObject.unescape(objValue.ToString()), null);
                        }
                    }
                }
            }
        }

        /// 
        /// js编码解码
        /// 
        /// 
        /// 
        public static void JSCodingTable(this DataSet o, bool isEscape = false)
        {
            foreach (DataTable t in o.Tables)
            {
                JSCodingEntity(t, isEscape);
            }
        }

        /// 
        /// js编码解码
        /// 
        /// 
        /// 
        public static void JSCodingTable(this DataTable o, bool isEscape = false)
        {
            for (int j = 0; j (this List lsto)
        {
            foreach (object o in lsto)
            {
                ToJSEncodeEntity(o);
            }
        }

        public static void ToJSDecodeEntityList(this List lsto)
        {
            foreach (object o in lsto)
            {
                ToJSDecodeEntity(o);
            }
        }

        public static void ToJSEncodeEntity(this T o)
        {
            object objValue;
            System.Reflection.PropertyInfo[] propertys = o.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo p in propertys)
            {
                if (p.PropertyType == typeof(System.String))
                {
                    objValue = p.GetValue(o, null);
                    if (objValue != null)
                    {
                        if (objValue.GetType() == typeof(System.String))
                        {
                            p.SetValue(o, Microsoft.JScript.GlobalObject.escape(objValue.ToString()), null);
                        }
                    }
                }
            }
        }

        public static void ToJSDecodeEntity(this T o)
        {
            object objValue;
            System.Reflection.PropertyInfo[] propertys = o.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo p in propertys)
            {
                if (p.PropertyType == typeof(System.String))
                {
                    objValue = p.GetValue(o, null);
                    if (objValue != null)
                    {
                        if (objValue.GetType() == typeof(System.String))
                        {
                            p.SetValue(o, Microsoft.JScript.GlobalObject.unescape(objValue.ToString()), null);
                        }
                    }
                }
            }
        }

        public static void ToJSEncodeTable(this DataSet o)
        {
            foreach (DataTable t in o.Tables)
            {
                ToJSEncodeTable(t);
            }
        }

        public static void ToJSDecodeTable(this DataSet o)
        {
            foreach (DataTable t in o.Tables)
            {
                ToJSDecodeTable(t);
            }
        }

        public static void ToJSEncodeTable(this DataTable o)
        {
            for (int j = 0; j 

  

C# 对JS编码/解码进行转换,搜素材,soscw.com

C# 对JS编码/解码进行转换

标签:des   class   blog   code   ext   get   

原文地址:http://www.cnblogs.com/zfanlong1314/p/3800196.html


评论


亲,登录后才可以留言!