public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            var result = fsResult.Success;

            // Verify that we actually have an List
            if ((result += CheckType(data, fsDataType.Array)).Failed)
            {
                return(result);
            }


            fsIEnumerableSerializationAdapter adapter = GetAdapter(storageType);

            Type elementType = adapter.GetElementType(storageType);

            var serializedList = data.AsList;

            for (int i = 0; i < serializedList.Count; ++i)
            {
                var    serializedItem = serializedList[i];
                object deserialized   = null;

                var itemResult = Serializer.TryDeserialize(serializedItem, elementType, ref deserialized);
                result.AddMessages(itemResult);
                if (itemResult.Failed)
                {
                    continue;
                }

                adapter.Add(instance, deserialized);
            }

            return(result);
        }
        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);
        }
예제 #3
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);
        }
예제 #4
0
        public override fsFailure TryDeserialize(fsData data, ref object instance, Type storageType)
        {
            fsIEnumerableSerializationAdapter adapter = GetAdapter(storageType);

            Type elementType = adapter.GetElementType(storageType);

            var serializedList = data.AsList;

            for (int i = 0; i < serializedList.Count; ++i)
            {
                var    serializedItem = serializedList[i];
                object deserialized   = null;

                var fail = Serializer.TryDeserialize(serializedItem, elementType, ref deserialized);
                if (fail.Failed)
                {
                    return(fail);
                }

                adapter.Add(instance, deserialized);
            }

            return(fsFailure.Success);
        }