public void ProcessReferenceType <T>(IWriteOnlyExactValueDescriptor <T> descriptor)
            where T : class
        {
            Type type;

            if (TryReadReferenceType(descriptor, out type))
            {
                // Do not create instance when predefined type, Just route to it.
                if (BinaryReaderWriterExtensions.IsPredefinedType(type))
                {
                    descriptor.Route(
                        new BinaryStateMember
                            (new MyCustomStateMember((IReflectionStateMember)descriptor.StateMember,
                                                     type),
                            true,
                            true),
                        descriptor.Owner,
                        true);

                    return;
                }

                T instance = (T)Activator.CreateInstance(type);
                _objects.Add(instance);
                descriptor.Set(instance);
                descriptor.Climb();
            }
        }
Exemplo n.º 2
0
        public void ProcessObject(IWriteOnlyExactValueDescriptor <object> descriptor)
        {
            XElement element = _reader.Element(descriptor.StateMember.Name);

            XAttribute attribute = element.Attribute("Type");

            if (attribute != null)
            {
                var type = attribute.Value;

                Type instanceType = Type.GetType(type);

                // TODO: this will be the route method..
                descriptor.Route
                    (new MyCustomStateMember((IReflectionStateMember)descriptor.StateMember,
                                             instanceType), descriptor.Owner, true);
            }
        }