public void IsList_Valid_Test() { TLVListConv conv = new TLVListConv(); conv.PropInfo = typeof(TmpTLVAble).GetProperty("ListInts"); conv.Typ = conv.PropInfo.PropertyType; conv.ListType = typeof(List<int>); bool result = IsList(conv); Assert.AreEqual(true, result); }
private int Func(TLVListConv conv, List<byte> arr, ITLVable obj, int level) { int len = 0; //obj = (ITLVable)conv.PropInfo.GetValue(obj); System.Collections.IList listData = (System.Collections.IList)conv.PropInfo.GetValue(obj); // Iterate backwards because stream is created backwards for (int i = listData.Count - 1; i >= 0; i--) { // Set (V) len += Func((dynamic)conv.Contains, arr, (dynamic)listData[i], ++level); } //foreach (dynamic o in listData) //{ // // Set (V) // len += Func((dynamic)conv.Contains, arr, o, ++level); //} if (len > 0) { // Set (L) len = SetL(arr, len, true); // Set (T) len = SetT(conv, arr, len, true); } return len; }
private void AddListVal(object o, TLVListConv conv, System.Collections.IList l) { if (conv.ListType.GenericTypeArguments.FirstOrDefault().Name.ToString().ToLower() == "int32") { l.Add(o.GetHashCode()); } else { l.Add(o); } }
protected void ParseList(byte[] arr, ref int idx, uint outerLength, TLVListConv conv, object obj) { Log.DebugFormat("Enter ParseList with idx {0}", idx); int innerLength = 0; int idxPre = idx; var list = conv.ListType.GetConstructor(new Type[] { }).Invoke(new object[] { }); conv.PropInfo.SetValue(obj, list); System.Collections.IList l = list as System.Collections.IList; while (innerLength < outerLength) { object o = Parse(arr, ref idx, null, obj); // todo: add to List //l.Add(o); AddListVal(o, conv, l); innerLength += idx - idxPre; idxPre = idx; } }
private static TLVConv EnrichRek(TLVConv conv, PropertyInfo prop, TLVConv c) { TLVCompositeAttr compAttr = prop.GetCustomAttribute<TLVCompositeAttr>(false); TLVPrimitiveAttr primAttr = prop.GetCustomAttribute<TLVPrimitiveAttr>(false); TLVListAttr listAttr = prop.GetCustomAttribute<TLVListAttr>(false); if (compAttr != null) { c = EnrichCompositeType(prop, compAttr); } else if (listAttr != null) { // TODO c = new TLVListConv(); TLVListConv lConv = c as TLVListConv; SetCommonConvData(prop, c, listAttr); // todo: check this line lConv.Identifier = TLV_IDENTIFIER_LIST; lConv.ListType = listAttr.ListType != null ? listAttr.ListType : lConv.PropInfo.PropertyType; lConv.IsList = true; //lConv.Contains = EnrichRek(lConv, null, lConv.Contains); //listAttr.ListType.GetGenericTypeDefinition(); } else if (primAttr != null) { c = EnrichPrimitiveConv(prop, primAttr); } if (c != null) { listAllConvs.Add(c); } return c; }