| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 | 
							- using Newtonsoft.Json;
 
- using Newtonsoft.Json.Converters;
 
- using Newtonsoft.Json.Linq;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.ComponentModel;
 
- using System.Data;
 
- using System.Linq;
 
- using System.Reflection;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- namespace WCS_Client
 
- {
 
-     /// <summary>
 
-     /// 扩展.json序列反序列化
 
-     /// </summary>
 
-     public static partial class Extensions
 
-     {
 
-         /// <summary>
 
-         /// 转成json对象
 
-         /// </summary>
 
-         /// <param name="Json">json字串</param>
 
-         /// <returns></returns>
 
-         public static object ToJson(this string Json)
 
-         {
 
-             return Json == null ? null : JsonConvert.DeserializeObject(Json);
 
-         }
 
-         /// <summary>
 
-         /// 转成json字串
 
-         /// </summary>
 
-         /// <param name="obj">对象</param>
 
-         /// <returns></returns>
 
-         public static string ToJson(this object obj)
 
-         {
 
-             var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
 
-             return JsonConvert.SerializeObject(obj, timeConverter);
 
-         }
 
-         /// <summary>
 
-         /// 转成json字串
 
-         /// </summary>
 
-         /// <param name="obj">对象</param>
 
-         /// <param name="datetimeformats">时间格式化</param>
 
-         /// <returns></returns>
 
-         public static string ToJson(this object obj, string datetimeformats)
 
-         {
 
-             var timeConverter = new IsoDateTimeConverter { DateTimeFormat = datetimeformats };
 
-             return JsonConvert.SerializeObject(obj, timeConverter);
 
-         }
 
-         /// <summary>
 
-         /// 字串反序列化成指定对象实体
 
-         /// </summary>
 
-         /// <typeparam name="T">实体类型</typeparam>
 
-         /// <param name="Json">字串</param>
 
-         /// <returns></returns>
 
-         public static T ToObject<T>(this string Json)
 
-         {
 
-             return Json == null ? default(T) : JsonConvert.DeserializeObject<T>(Json);
 
-         }
 
-         /// <summary>
 
-         /// 字串反序列化成指定对象实体(列表)
 
-         /// </summary>
 
-         /// <typeparam name="T">实体类型</typeparam>
 
-         /// <param name="Json">字串</param>
 
-         /// <returns></returns>
 
-         public static List<T> ToList<T>(this string Json)
 
-         {
 
-             return Json == null ? null : JsonConvert.DeserializeObject<List<T>>(Json);
 
-         }
 
-         /// <summary>
 
-         /// 字串反序列化成DataTable
 
-         /// </summary>
 
-         /// <param name="Json">字串</param>
 
-         /// <returns></returns>
 
-         public static DataTable ToTable(this string Json)
 
-         {
 
-             return Json == null ? null : JsonConvert.DeserializeObject<DataTable>(Json);
 
-         }
 
-         /// <summary>
 
-         /// 字串反序列化成linq对象
 
-         /// </summary>
 
-         /// <param name="Json">字串</param>
 
-         /// <returns></returns>
 
-         public static JObject ToJObject(this string Json)
 
-         {
 
-             return Json == null ? JObject.Parse("{}") : JObject.Parse(Json.Replace(" ", ""));
 
-         }
 
-         public static DataTable GetAttributesDataTable(this object obj)
 
-         {
 
-             var tb = new DataTable(obj.GetType().Name);
 
-             tb.Columns.Add("信号说明", typeof(string));
 
-             tb.Columns.Add("信号名称", typeof(string));
 
-             tb.Columns.Add("信号值", typeof(string));
 
-             Type t = obj.GetType();
 
-             //属性遍历
 
-             foreach (System.Reflection.PropertyInfo pi in t.GetProperties())
 
-             {
 
-                 AttributeCollection attributes = TypeDescriptor.GetProperties(t)[pi.Name].Attributes;
 
-                 DescriptionAttribute myAttribute = (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
 
-                 string describle = myAttribute.Description;
 
-                 string proname = pi.Name;
 
-                 var abc = pi.GetValue(obj, null);
 
-                 var values = new object[3];
 
-                 values[0] = describle;
 
-                 values[1] = proname;
 
-                 values[2] = abc;
 
-                 tb.Rows.Add(values);
 
-             }
 
-             return tb;
 
-         }
 
-         /// <summary>
 
-         /// 扩展方法,获得枚举的Description
 
-         /// </summary>
 
-         /// <param name="value">枚举值</param>
 
-         /// <param name="nameInstead">当枚举值没有定义DescriptionAttribute,是否使用枚举名代替,默认是使用</param>
 
-         /// <returns>枚举的Description</returns>
 
-         public static string GetDescription(this Enum value, Boolean nameInstead = true)
 
-         {
 
-             Type type = value.GetType();
 
-             string name = Enum.GetName(type, value);
 
-             if (name == null)
 
-             {
 
-                 return null;
 
-             }
 
-             FieldInfo field = type.GetField(name);
 
-             DescriptionAttribute attribute = System.Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
 
-             if (attribute == null && nameInstead == true)
 
-             {
 
-                 return name;
 
-             }
 
-             return attribute?.Description;
 
-         }
 
-     }
 
- }
 
 
  |