public void IsList_NoList_Test() { TLVConv conv = new TLVCompositeConv(); conv.PropInfo = typeof(TmpTLVAble).GetProperty("A"); conv.Typ = conv.PropInfo.PropertyType; bool result = IsList(conv); Assert.AreEqual(false, result); }
private int Func(TLVCompositeConv conv, List<byte> arr, ITLVable obj, int level) { int len = 0; // When coming from Func(TLVListConv c, ... ), PropInfo is null and object already set if (level > 0 && conv.PropInfo != null) obj = (ITLVable)conv.PropInfo.GetValue(obj); // When generic - now get the real underlying Conv if (conv.IsGeneric) { conv = TransMap[obj.TlvStructId]; } foreach (dynamic c in conv.Children) { // Set (V) len += Func(c, arr, obj, ++level); } if (len > 0) { // Set (L) len = SetL(arr, len, true); // Set (T) len = SetT(conv, arr, len, true); } return len; }
protected void ParseConstructed(byte[] arr, ref int idx, uint outerLength, TLVCompositeConv conv, object obj) { // Iterate reverse, because children are stored in reverse order for encoding! for (int i = conv.Children.Count - 1; i >= 0; i--) { if (conv.Children[i] is TLVCompositeConv) { var embeddedObj = Parse(arr, ref idx, null, null); conv.Children[i].PropInfo.SetValue(obj, embeddedObj); } else { var value = Parse(arr, ref idx, conv.Children[i], obj); } } }
/// <summary> /// This class tries to extract the parameterless constructor to be available late to create objects of this entity /// </summary> /// <param name="conv"></param> protected static void SetCtor(TLVCompositeConv conv) { try { // Get parameterless Constructor to create obj fast ConstructorInfo constructor = conv.Typ.GetConstructor(new Type[] { }); conv.CreateInstance = constructor.Invoke; // Test-Create ITLVable newObj2 = (ITLVable)conv.CreateInstance.Invoke(new object[] { }); } catch (Exception e) { Console.WriteLine(e); } }
private static TLVConv EnrichCompositeType(PropertyInfo prop, TLVCompositeAttr compAttr) { TLVConv c = new TLVCompositeConv(); TLVCompositeConv comp = c as TLVCompositeConv; SetCommonConvData(prop, c, compAttr); // can only provide TLVCompositeTypeAttr if is not generic if (!prop.PropertyType.Equals(typeof(ITLVable))) { TLVCompositeTypeAttr a = prop.PropertyType.GetCustomAttribute<TLVCompositeTypeAttr>(false); comp.CompTypeAttr = TransMap[a.StructId].CompTypeAttr; } else { comp.IsGeneric = true; } return c; }
private static void CreateConvType(Type type) { TLVCompositeTypeAttr attr = type.GetCustomAttribute<TLVCompositeTypeAttr>(false); if (TransMap.ContainsKey(attr.StructId)) { throw new ApplicationException("A TlvCompositeAttr has already been registered with StructId: " + attr.StructId); } TLVCompositeConv conv = new TLVCompositeConv(); conv.Typ = type; conv.CompTypeAttr = attr; conv.Identifier = GetIdentifierOctet(conv); // TODO: make this call withing TLVCompositeConv-Property? TransMap.Add(attr.StructId, conv); listAllConvs.Add(conv); }