private void Process(ref List <SmsMessage> smsMessageList, ref int rowPtr, ref List <CsvColumn <CsvColCell <string> > > cols) { for (; rowPtr < cols[0].Cells.Count; rowPtr++) { var smsMessage = new SmsMessage(); for (int i = CsvFormatRules.StartOffset; i <= CsvFormatRules.DataColCount; i++) { var currentColumn = cols[i - CsvFormatRules.StartOffset]; var cell = currentColumn.Cells[rowPtr]; var value = PrepareCellValue(cell.Value, smsMessage.GetType().GetProperties()[i]); smsMessage.GetType().GetProperties()[i].SetValue(smsMessage, value); } smsMessageList.Add(smsMessage); } }
private void PrepareCsvFormatRules() { var mockMessage = new SmsMessage(); var smsEntityProperties = mockMessage.GetType().GetProperties(); CsvFormatRules.DataColCount = smsEntityProperties .ToList() .FindAll(property => property.GetCustomAttributes(true) .Contains(new CsvDataColumnAttribute())) .Count; }
/// <summary> /// 转换为协议二进制 /// </summary> /// <param name="message">对象</param> /// <returns></returns> public static byte[] ToProtocolBinaryArray(SmsMessage message) { var type = message.GetType(); var props = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); int length = 0; var paramList = new List <ProtocolParam>(); foreach (var property in props) { var protocols = property.GetCustomAttributes(typeof(ProtocolDescAttribute), false); if (protocols.Length == 0) { continue; } var desc = (ProtocolDescAttribute)protocols[0]; var param = new ProtocolParam { Name = desc.Name, Size = desc.MultiBy == null ? desc.Size : desc.Size * Value(paramList, desc) // 会根据其他值的变化而变化 }; if (desc.Tag != 0) // TLV Format { var tlv = GetTlvValue(message, property, desc.Tag, desc.Size); if (tlv == null) { continue; } param.Value = tlv; param.Size += 4; } else { param.Value = GetValue(message, property, desc.Size, param.Size); } paramList.Add(param); length += param.Size; } var result = new byte[length]; int index = 0; foreach (var param in paramList) { index = Padding(param.Value, result, index, param.Size); } return(result); }