ncupper / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Non-generic version of: Serializer.Deserialize<T> #402

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I was wondering if you could had the method bellow to the Serializer

Please include an e-mail address if this might need a dialogue!
==============
        /// <summary>
        /// Creates a new instance from a protocol-buffer stream
        /// </summary>
        /// <typeparam name="T">The type to be created.</typeparam>
        /// <param name="source">The binary stream to apply to the new instance (cannot be null).</param>
        /// <param name="type">The type of the serialized object</param>
        /// <returns>A new, initialized instance.</returns>

        public static object Deserialize(Stream source, Type type)
        {
            return RuntimeTypeModel.Default.Deserialize(source, null, type);
        }

Thanks

Original issue reported on code.google.com by metitus on 22 Aug 2013 at 11:25

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Just to give an example why I need it:

        static void Main(string[] args)
        {
            var command = new AddOrganizationCommand
            {
                CompanyStartedDate = DateTime.UtcNow,
                Description = "some description",
                Name = "some name",
                PhoneNumber = "0857135496",
                Header =
                    new MessageHeader
                    {
                        Name = "some header name",
                        DateSent = DateTime.UtcNow,
                        EndpointDestination = "some destination",
                        EndpointOrigin = "some origin",
                        MessageId = Guid.NewGuid()
                    }
            };

            var memoryStream = new MemoryStream();

            Serializer.Serialize(memoryStream, command);

            memoryStream.Position = 0;

            //Type name will be saved in a key(type name)/value dictionary
            var type = Type.GetType("Protobuf.AddOrganizationCommand");
            var addOrganizationCommand = Serializer.Deserialize(memoryStream, type);
        }

Original comment by metitus on 22 Aug 2013 at 11:41

GoogleCodeExporter commented 9 years ago
Please see: Serializer.NonGeneric

Original comment by marc.gravell on 22 Aug 2013 at 11:43

GoogleCodeExporter commented 9 years ago
No idea why you created the NonGeneric namespace, you could have 
generic/non-generic overload methods in the same class, but anyway that is your 
decision :)

Thanks

Original comment by metitus on 22 Aug 2013 at 11:46

GoogleCodeExporter commented 9 years ago
Note, in the v2 API, the "real" code is TypeModel *anyway* (Serializer.* just 
calls through to RuntimeTypeModel.Default) - and TypeModel is *entirely* 
non-generic.

Original comment by marc.gravell on 22 Aug 2013 at 12:34

GoogleCodeExporter commented 9 years ago
I understand, but all I am saying is that you could make the the API look a bit 
simpler.

Either way you're doing a very nice work here.

Thanks

Original comment by metitus on 22 Aug 2013 at 1:05