コード例 #1
0
        public static byte[] Serialize <T>(ComplianceSerializationDescription <T> description, T inputObject) where T : class, new()
        {
            if (inputObject == null)
            {
                return(null);
            }
            int num = 1;

            num = num + 1 + description.TotalByteFields;
            num = num + 1 + 2 * description.TotalShortFields;
            num = num + 1 + 4 * description.TotalIntegerFields;
            num = num + 1 + 8 * description.TotalLongFields;
            num = num + 1 + 8 * description.TotalDoubleFields;
            num = num + 1 + 16 * description.TotalGuidFields;
            num = num + 1 + 4 * description.TotalStringFields;
            List <Tuple <int, byte[]> > variableWidthMemberBytes = ComplianceSerializer.GetVariableWidthMemberBytes <T>(description, inputObject, ComplianceSerializer.VariableWidthType.String);

            foreach (Tuple <int, byte[]> tuple in variableWidthMemberBytes)
            {
                num += tuple.Item1;
            }
            num = num + 1 + 4 * description.TotalBlobFields;
            List <Tuple <int, byte[]> > variableWidthMemberBytes2 = ComplianceSerializer.GetVariableWidthMemberBytes <T>(description, inputObject, ComplianceSerializer.VariableWidthType.Blob);

            foreach (Tuple <int, byte[]> tuple2 in variableWidthMemberBytes2)
            {
                num += tuple2.Item1;
            }
            num++;
            List <ComplianceSerializer.CollectionField> list = new List <ComplianceSerializer.CollectionField>();
            byte b = 0;

            while ((int)b < description.TotalCollectionFields)
            {
                CollectionItemType itemType = CollectionItemType.NotDefined;
                if (description.TryGetCollectionPropertyItemType(b, out itemType))
                {
                    IEnumerable <object> collectionItems = description.GetCollectionItems(inputObject, b);
                    ComplianceSerializer.CollectionField collectionField = ComplianceSerializer.CollectionField.GetCollectionField(itemType, collectionItems);
                    list.Add(collectionField);
                    num += collectionField.GetSizeOfSerializedCollectionField();
                }
                b += 1;
            }
            byte[] array = new byte[num];
            array[0] = description.ComplianceStructureId;
            int num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, 1, 1, ComplianceSerializer.FixedWidthType.Byte, description.TotalByteFields);

            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 2, ComplianceSerializer.FixedWidthType.Short, description.TotalShortFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 4, ComplianceSerializer.FixedWidthType.Int, description.TotalIntegerFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 8, ComplianceSerializer.FixedWidthType.Long, description.TotalLongFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 8, ComplianceSerializer.FixedWidthType.Double, description.TotalDoubleFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 16, ComplianceSerializer.FixedWidthType.Guid, description.TotalGuidFields);
            num2 = ComplianceSerializer.WriteVariableWidthFieldsToBlob(array, num2, variableWidthMemberBytes);
            num2 = ComplianceSerializer.WriteVariableWidthFieldsToBlob(array, num2, variableWidthMemberBytes2);
            num2 = ComplianceSerializer.WriteCollectionsToBlob(array, num2, list);
            return(array);
        }