Example #1
0
        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);
        }
Example #2
0
        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;
        }
Example #3
0
 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);
     }
 }
Example #4
0
        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;
            }
        }
Example #5
0
        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;
        }