Exemplo n.º 1
0
        public static object Deserialize(XdrReader reader, Type type)
        {
            //find the corresponding serialization vector for a given type
            var serializer = LookupSerializer(type);



            //skip discriminators for ancestors
            if (serializer.AncestorUnionsCounts > 0)
            {
                reader.Advance(serializer.AncestorUnionsCounts * 4);
            }
            //resolve unions
            while (serializer.IsUnion)
            {
                type       = serializer.ResolveActualUnionTypeMethod.Invoke(null, new object[] { reader }) as Type;
                serializer = LookupSerializer(type);
            }

            //create new instance of the target model
            var instance = Activator.CreateInstance(type);

            //deserialize using resolved serializer contract
            serializer.DeserializeMethod.Invoke(null, new object[] { instance, reader });
            return(instance);
        }
Exemplo n.º 2
0
 public static T Deserialize <T>(XdrReader reader) where T : class
 {
     return(Deserialize(reader, typeof(T)) as T);
 }