Beispiel #1
0
        public virtual object Deserialize(uint clsid, IoBuffer input, ISerializationContext context)
        {
            var property = new cTSOProperty();

            property.Deserialize(input, context);
            //Convert to instance
            var result = ConvertFromProperty(property, context);

            return(result);
        }
Beispiel #2
0
        public override object Deserialize(uint clsid, IoBuffer input, ISerializationContext serializer)
        {
            //note: currently an array full with null values will just return null.
            object result       = null;
            var    count        = input.GetUInt32();
            int    leadingNulls = 0;

            for (int i = 0; i < count; i++)
            {
                var property = new cTSOProperty();
                property.Deserialize(input, serializer);
                //Convert to instance
                var item = ConvertFromProperty(property, serializer);
                if (item == null)
                {
                    leadingNulls++;
                }
                else if (result == null)
                {
                    //still need to make the list!
                    var listType   = typeof(ImmutableList);
                    var consMethod = listType.GetMethods().Where(method => method.IsGenericMethod).FirstOrDefault();
                    if (consMethod == null)
                    {
                        Console.WriteLine("No Generic Methods!");
                        return(null);
                    }
                    else
                    {
                        var generic = consMethod.MakeGenericMethod(item.GetType());
                        if (generic == null)
                        {
                            Console.WriteLine("No Generic: " + item.GetType().ToString());
                            return(null);
                        }
                        result = generic.Invoke(null, new object[] { }); //listType.MakeGenericType(item.GetType());
                    }

                    //result = Activator.CreateInstance(constructedListType);
                    for (int j = 0; j < leadingNulls; j++)
                    {
                        result = result.GetType().GetMethod("Add").Invoke(result, new object[] { null });
                    }
                }
                if (result != null)
                {
                    result = result.GetType().GetMethod("Add").Invoke(result, new object[] { item });
                }
            }

            return(result);
        }