Exemple #1
0
        void SerializeArray(object instance, Type type, IKey inKey, ILogPrinter inLogger)
        {
            //if (string.IsNullOrEmpty(inKey.GetName()))
            //inKey.SetName("Values");

            Type declaredItemType = type.GetElementType();
            bool atomic_member    = declaredItemType.IsAtomic();

            Array multi_dim_array = instance as Array;

            CMultiArrayIndexer indexer = new CMultiArrayIndexer(multi_dim_array);

            while (indexer.MoveNext())
            {
                object value     = multi_dim_array.GetValue(indexer.Current);
                IKey   dim_child = GetOrCreateKeyByArrayIndex(inKey, indexer.Current, indexer.Lengthes, atomic_member);
                if (atomic_member)
                {
                    AddValueToKey(dim_child, value);
                }
                else
                {
                    IKey child = dim_child.CreateArrayKey();
                    Serialize(value, declaredItemType, child, 0, inLogger);
                }
            }
        }
Exemple #2
0
        IKey GetOrCreateKeyByArrayIndex(IKey inParent, int[] indicies, int[] lengthes, bool atomic_elems)
        {
            IKey key         = inParent;
            int  keys_length = indicies.Length - 1; //length of key chaine

            //indicies.Length - 1 - last array to one key

            for (int i = 0; i < keys_length; i++)
            {
                int index  = indicies[i];
                int length = lengthes[i];
                while (index >= key.GetChildCount())
                {
                    key.CreateArrayKey();
                }

                key = key.GetChild(index);
            }
            return(key);
        }
Exemple #3
0
        void SerializeGenericCollection(object instance, Type type, IKey inKey, int inInheriteDeep, ILogPrinter inLogger)
        {
            var collection = instance as IEnumerable;

            Type[] gen_args = type.GetGenericArguments();
            if (gen_args.Length == 0)
            {
                LogError(inLogger, string.Format("SerializeGenericCollection: Generic Arguments are None. Type {0}. Instance {1}", type.Name, instance));
                return;
            }

            Type declaredItemType = gen_args[0];
            bool atomic_member    = declaredItemType.IsAtomic();

            IKey tree_key = inKey;

            if (tree_key.GetValuesCount() > 0 || tree_key.GetChildCount() > 0)
            {
                tree_key = inKey.CreateChildKey("BaseCollection");
            }

            if (atomic_member)
            {
                foreach (var item in collection)
                {
                    AddValueToKey(tree_key, item);
                }
            }
            else
            {
                foreach (var item in collection)
                {
                    IKey child = tree_key.CreateArrayKey();
                    Serialize(item, declaredItemType, child, 0, inLogger);
                }
            }
        }