Exemple #1
0
        public override object ConvertToObject(byte[] bytes, object parentObj)
        {
            var collectionSizePropertyInfo = parentObj.GetType().GetProperty(CollectionSizePropertyName);
            var collectionPropertyInfo     = parentObj.GetType().GetProperty(CollectionPropertyName);

            var collectionSizeString    = collectionSizePropertyInfo.GetValue(parentObj, null).ToString();
            var collectionPropertyValue = collectionPropertyInfo.GetValue(parentObj, null);

            var collectionSize = int.Parse(collectionSizeString);

            if (collectionSize * SingleDataSize != bytes.Length)
            {
                throw new ArgumentNullException();
            }

            for (int i = 0; i < collectionSize; i++)
            {
                var elementBytes = new byte[SingleDataSize];
                for (int j = 0; j < SingleDataSize; j++)
                {
                    elementBytes[i] = bytes[i * SingleDataSize + j];
                }

                var elementInstance = DataPackageConvert.ToObject(elementBytes, CollectionElementType);

                DataFieldType.InvokeMember("Add", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, collectionPropertyValue, new[] { elementInstance });
            }

            return(collectionPropertyValue);
        }
 public override object ConvertToObject(byte[] bytes)
 {
     return(DataPackageConvert.ToObject(bytes, DataFieldType));
 }