public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
        {
            var result = fsResult.Success;

            fsIEnumerableSerializationAdapter adapter = GetAdapter(storageType);
            Type elementType = adapter.GetElementType(storageType);

            serialized = fsData.CreateList(adapter.HintSize(instance));
            var serializedList = serialized.AsList;

            foreach (object item in adapter.Iterate(instance))
            {
                fsData serializedItem;

                var itemResult = Serializer.TrySerialize(elementType, item, out serializedItem);
                result.AddMessages(itemResult);
                if (itemResult.Failed)
                {
                    continue;
                }

                serializedList.Add(serializedItem);
            }

            return(result);
        }
Esempio n. 2
0
        public override fsFailure TrySerialize(object instance, out fsData serialized, Type storageType)
        {
            serialized = fsData.CreateList();

            fsIEnumerableSerializationAdapter adapter = GetAdapter(storageType);
            Type elementType = adapter.GetElementType(storageType);

            foreach (object item in adapter.Iterate(instance))
            {
                fsData serializedItem;

                var fail = Serializer.TrySerialize(elementType, item, out serializedItem);
                if (fail.Failed)
                {
                    return(fail);
                }

                serialized.AsList.Add(serializedItem);
            }

            return(fsFailure.Success);
        }