// Always remember: the whole configuration must be serialized as one single, flat object (or SerializationInfo), we cannot rely on any
        // nested objects to be deserialized in the right order
        public static void GetObjectDataForGeneratedTypes(
            SerializationInfo info,
            StreamingContext context,
            object mixin,
            ConcreteMixinTypeIdentifier identifier,
            bool serializeBaseMembers,
            string pipelineIdentifier)
        {
            ArgumentUtility.CheckNotNull("info", info);
            ArgumentUtility.CheckNotNull("mixin", mixin);
            ArgumentUtility.CheckNotNull("identifier", identifier);

            info.SetType(typeof(MixinSerializationHelper));

            var identifierSerializer = new SerializationInfoConcreteMixinTypeIdentifierSerializer(info, "__identifier");

            identifier.Serialize(identifierSerializer);

            object[] baseMemberValues;
            if (serializeBaseMembers)
            {
                var baseType = mixin.GetType().BaseType;
                Assertion.IsNotNull(baseType, "Generated mixin types always have a base type.");
                MemberInfo[] baseMembers = FormatterServices.GetSerializableMembers(baseType);
                baseMemberValues = FormatterServices.GetObjectData(mixin, baseMembers);
            }
            else
            {
                baseMemberValues = null;
            }

            info.AddValue("__baseMemberValues", baseMemberValues);
            info.AddValue("__participantConfigurationID", pipelineIdentifier);
        }
        public void AddTypeInitializer()
        {
            var serializer = new ExpressionConcreteMixinTypeIdentifierSerializer();

            _identifier.Serialize(serializer);
            var newExpression = serializer.CreateExpression();

            _type.AddTypeInitializer(ctx => Expression.Assign(_identifierField, newExpression));
        }
Ejemplo n.º 3
0
        public void Serialize()
        {
            var overriders = new HashSet <MethodInfo> {
                _overrider1, _overrider2
            };
            var overridden = new HashSet <MethodInfo> {
                _overridden1, _overridden2
            };

            var identifier     = new ConcreteMixinTypeIdentifier(typeof(BT1Mixin1), overriders, overridden);
            var serializerMock = MockRepository.GenerateMock <IConcreteMixinTypeIdentifierSerializer> ();

            identifier.Serialize(serializerMock);

            serializerMock.AssertWasCalled(mock => mock.AddMixinType(typeof(BT1Mixin1)));
            serializerMock.AssertWasCalled(mock => mock.AddOverriders(overriders));
            serializerMock.AssertWasCalled(mock => mock.AddOverridden(overridden));
        }
Ejemplo n.º 4
0
        public void IntegrationTest_GenericMethods()
        {
            var referenceIdentifier = new ConcreteMixinTypeIdentifier(
                typeof(BT1Mixin1),
                new HashSet <MethodInfo> {
                _genericMethod
            },
                new HashSet <MethodInfo> {
                _genericMethod
            });

            var serializer = new ExpressionConcreteMixinTypeIdentifierSerializer();

            referenceIdentifier.Serialize(serializer);

            object result = BuildTypeAndInvokeMethod(serializer.CreateExpression());

            Assert.That(result, Is.EqualTo(referenceIdentifier));
        }