public void AddTLVDef(TLVDef field) { if (mMap == null) { mMap = new TLVDefs(); } mMap.AddField(field); }
public void AddField(TLVDef field) { if (field == null) { throw new ArgumentNullException("field"); } if (this.fields.ContainsKey(field.Tag)) { throw new Exception("Tag:" + field.Tag + ",标签定义已经存在。"); } this.fields.Add(field.Tag, field); }
private string ExportToXml() { TLVDef[] array = new TLVDef[this.fields.Count]; int i = 0; foreach (KeyValuePair <string, TLVDef> kvp in this.fields) { array[i++] = kvp.Value; } XmlSerializer serial = new XmlSerializer(typeof(TLVDef[])); StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); serial.Serialize(writer, array); return(sb.ToString()); }
public TLVElement(string tag, string value, TLVDef def, bool isPack) { Tag = Utility.str2Bcd(tag); Value = Encoding.Default.GetBytes(value); mTLVDef = def; if (def == null || def.ValueType == TLVDef.DataType.A || def.ValueType == TLVDef.DataType.B) { R = false; } else { R = true; } if (R) { throw new Exception("Tag:" + tag + ",内容格式不合法"); } }
public TLVElement(string tag, byte[] value, TLVDef def, bool isPack) { Tag = Utility.str2Bcd(tag); Value = value; mTLVDef = def; if ((def == null && isPack) || (def != null && def.ValueType == TLVDef.DataType.R && isPack)) { R = true; } else { R = false; } if (!R && isPack) { throw new Exception("Tag:" + tag + ",内容格式不合法"); } }