/// <summary> /// 根据 具体类型 获取单个数据格子数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <param name="membersDic">需要序列化的成员</param> /// <returns></returns> public List <DataColumn> GetColumns <T>(T t, Dictionary <MemberInfo, string> membersDic) { List <DataColumn> columns = new List <DataColumn>(); foreach (var member in membersDic) { string val = string.Empty; MemberInfo m = member.Key; if (m is PropertyInfo) { PropertyInfo info = m as PropertyInfo; val = StringConvert.ConvertToString(info.GetValue(t, null), info.PropertyType); } else { FieldInfo info = m as FieldInfo; val = StringConvert.ConvertToString(info.GetValue(t), info.FieldType); } columns.Add(new DataColumn() { value = FitterCsv_GetColum(val) }); } return(columns); }
/// <summary> /// 对象与字符串的相互转换 /// </summary> public void String() { Log.L(""); Log.L("开始对象与字符串的相互转换:"); Log.L("生成一个字典对象,并转换成字符串"); HuMan hu = new HuMan() { age = 6, Name = "abc", sex = "sex", heigth = 16, width = 20 }; Dictionary <int, HuMan> hus = new Dictionary <int, HuMan>() { { 1, hu }, { 2, hu } }; var str = StringConvert.ConvertToString(hus); Log.L("转换出来的字符串是:"); Console.WriteLine(str + "\n"); Log.L("将字符串转换回去:"); Dictionary <int, HuMan> hus2; Log.L("转换" + (StringConvert.TryConvert(str, out hus2) ? "成功" : "失败")); Console.WriteLine($"由字符串转换回来的对象:{hus2}\n"); }
private static XmlElement SerializeField <T>(XmlElement root, string name, T value) { XmlElement ele = root.OwnerDocument.CreateElement(name); if (value != null) { Type type = value.GetType(); XmlNode node = root.OwnerDocument.CreateTextNode(StringConvert.ConvertToString(value, type)); ele.AppendChild(node); root.AppendChild(ele); } else if (name != "UserData") { Log.W("SubWin " + name + " value is mull,will not Serializate"); } return(root); //try //{ //} //catch (Exception) //{ // throw new Exception(name); //} }
/// <summary> /// 根据 具体类型 获取单个数据格子数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <param name="membersDic">需要序列化的成员</param> /// <returns></returns> public List <DataColumn> GetColumns <T>(T t, Dictionary <MemberInfo, string> membersDic) { List <DataColumn> columns = new List <DataColumn>(); membersDic.ForEach((member) => { string val = string.Empty; MemberInfo m = member.Key; if (m is PropertyInfo) { PropertyInfo info = m as PropertyInfo; val = StringConvert.ConvertToString(info.GetValue(t, null), info.PropertyType); } else { FieldInfo info = m as FieldInfo; val = StringConvert.ConvertToString(info.GetValue(t), info.FieldType); } columns.Add(new DataColumn() { HeadLineName = member.Value, //StrValue = val StrValue = FitterCsv_GetColum(val) }); }); return(columns); }
public XmlElement Serializate(XmlDocument doc) { XmlElement root = doc.CreateElement(name); XmlNode node = root.OwnerDocument.CreateTextNode(StringConvert.ConvertToString(offset, offset.GetType())); root.AppendChild(node); return(root); }
public void String() { HuMan hu = new HuMan() { age = 6, Name = "xxl", sex = "sex", heigth = 16, width = 20 }; Dictionary <int, HuMan> hus = new Dictionary <int, HuMan>() { { 1, hu }, { 2, hu } }; var str = StringConvert.ConvertToString(hus); Console.WriteLine(str); Dictionary <int, HuMan> hus2; Console.WriteLine(StringConvert.TryConvert(str, out hus2)); Console.WriteLine(hus2); }
protected static XmlElement SerializeField <T>(XmlElement root, string name, T value) { try { XmlElement ele = root.OwnerDocument.CreateElement(name); if (value != null) { Type type = value.GetType(); XmlNode node = root.OwnerDocument.CreateTextNode(StringConvert.ConvertToString(value, type)); ele.AppendChild(node); root.AppendChild(ele); } else { //Log.W("GUICanvas: " + name + " value is mull,will not Serializate"); } return(root); } catch (Exception) { throw new Exception(name); } }
private void ListenView(Type publishType, int code, IEventArgs args, object[] param) { GamePanelViewArg arg = (GamePanelViewArg)args; GamePanelViewEveType type = (GamePanelViewEveType)code; switch (type) { case GamePanelViewEveType.Button_OK: APP.net.SendTcpMessage(new PanRequest() { account = APP.acc, name = APP.uname, colomn = new GameColum() { color = StringConvert.ConvertToString(pickColor), posX = (int)curSelectPos.x, posY = (int)curSelectPos.y }, size = pan_size }); break; case GamePanelViewEveType.Input_X: arg.input_x = Mathf.Clamp(arg.input_x, 0, MapSize); curSelectPos = new Vector2(arg.input_x, curSelectPos.y); break; case GamePanelViewEveType.Input_Y: arg.input_y = Mathf.Clamp(arg.input_y, 0, MapSize); curSelectPos = new Vector2(curSelectPos.x, arg.input_y); break; case GamePanelViewEveType.Color: pickColor = arg.color; break; case GamePanelViewEveType.Button_Chat: APP.net.SendTcpMessage(new ChatBroadCast() { acc = APP.acc, name = APP.uname, message = chat }); chat = string.Empty; break; case GamePanelViewEveType.Input_Chat: chat = arg.input_chat; break; case GamePanelViewEveType.Slider_Pan_size: pan_size = arg.slider_panSize; break; case GamePanelViewEveType.Button_ForMap: APP.net.SendTcpMessage(new AskPanRequest() { account = APP.acc, name = APP.uname }); break; } }