public MixinSerializationHelper(SerializationInfo info, StreamingContext context)
        {
            ArgumentUtility.CheckNotNull("info", info);

            _context = context;

            var identifierDeserializer = new SerializationInfoConcreteMixinTypeIdentifierDeserializer(info, "__identifier");
            var identifier             = ConcreteMixinTypeIdentifier.Deserialize(identifierDeserializer);

            var pipelineIdentifier = info.GetString("__participantConfigurationID");
            var pipeline           = SafeServiceLocator.Current.GetInstance <IPipelineRegistry>().Get(pipelineIdentifier);

            var mixinType = pipeline.ReflectionService.GetAdditionalType(identifier);

            _baseMemberValues = (object[])info.GetValue("__baseMemberValues", typeof(object[]));

            // Usually, instantiate a deserialized object using GetSafeUninitializedObject.
            // However, _baseMemberValues being null means that the object itself manages its member deserialization via ISerializable. In such a case, we
            // need to use the deserialization constructor to instantiate the object.
            if (_baseMemberValues != null)
            {
                _deserializedObject = FormatterServices.GetSafeUninitializedObject(mixinType);
            }
            else
            {
                Assertion.IsTrue(typeof(ISerializable).IsAssignableFrom(mixinType));
                _deserializedObject = Activator.CreateInstance(
                    mixinType,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    null,
                    new object[] { info, context },
                    null);
            }
            SerializationImplementer.RaiseOnDeserializing(_deserializedObject, _context);
        }
        public void Create_Identifier()
        {
            var attribute = ConcreteMixinTypeAttribute.Create(_simpleIdentifier);

            var deserializer = new AttributeConcreteMixinTypeIdentifierDeserializer(attribute.ConcreteMixinTypeIdentifierData);

            Assert.That(ConcreteMixinTypeIdentifier.Deserialize(deserializer), Is.EqualTo(_simpleIdentifier));
        }
        public void GetObjectDataForGeneratedTypes_SerializesIdentifier()
        {
            CallGetObjectDataForGeneratedTypes(true);
            var identifierDeserializer = new SerializationInfoConcreteMixinTypeIdentifierDeserializer(_serializationInfo, "__identifier");

            var deserializedIdentifier = ConcreteMixinTypeIdentifier.Deserialize(identifierDeserializer);

            Assert.That(deserializedIdentifier, Is.EqualTo(_identifier));
        }
Esempio n. 4
0
        public void Deserialize()
        {
            var overriders = new HashSet <MethodInfo> {
                _overrider1, _overrider2
            };
            var overridden = new HashSet <MethodInfo> {
                _overridden1, _overridden2
            };
            var deserializerMock = MockRepository.GenerateMock <IConcreteMixinTypeIdentifierDeserializer> ();

            deserializerMock.Expect(mock => mock.GetMixinType()).Return(typeof(BT1Mixin1));
            deserializerMock.Expect(mock => mock.GetOverriders()).Return(overriders);
            deserializerMock.Expect(mock => mock.GetOverridden()).Return(overridden);

            deserializerMock.Replay();

            var identifier = ConcreteMixinTypeIdentifier.Deserialize(deserializerMock);

            deserializerMock.VerifyAllExpectations();
            Assert.That(identifier.MixinType, Is.SameAs(typeof(BT1Mixin1)));
            Assert.That(identifier.Overriders, Is.SameAs(overriders));
            Assert.That(identifier.Overridden, Is.SameAs(overridden));
        }