public ReflectionData(Type typeData) { EnsureTypeHasRequiredAttributes(typeData); Properties = GetTypeProperties(typeData).ToList(); MetaLength = Properties.Sum(p => p.Attribute.Length); IdProperty = Properties.SingleOrDefault(p => p.Attribute.BinaryDataType == BinaryDataType.Id); LengthProperty = Properties.SingleOrDefault(p => p.Attribute.BinaryDataType == BinaryDataType.Length); BodyProperty = Properties.SingleOrDefault(p => p.Attribute.BinaryDataType == BinaryDataType.Body); ComposeProperty = Properties.SingleOrDefault(p => p.Attribute.BinaryDataType == BinaryDataType.Compose); }
static int CalculateRealLength(BinaryMember lengthProperty, object data, int metaLength, object dataLength) { var lengthValue = lengthProperty.Type == typeof(int) ? dataLength : Convert.ChangeType(dataLength, lengthProperty.Type); lengthProperty.Set(data, lengthValue); try { return((int)lengthValue + metaLength); } catch (InvalidCastException) { return(Convert.ToInt32(lengthValue) + metaLength); } }