Exemple #1
0
        public void CompileAndCompose()
        {
            while (compileQueue.Count != 0)
            {
                LocalCompilationContext context = compileQueue.Dequeue();
                context.Compile();
                composeQueue.Enqueue(context);
            }

            if (WithComments)
            {
                Console.WriteLine();
                Console.WriteLine("Dependencies list:");
                foreach (Type dependenceType in Dependencies.Keys)
                {
                    Console.WriteLine(dependenceType);
                }
            }

            while (composeQueue.Count != 0)
            {
                LocalCompilationContext context = composeQueue.Dequeue();
                context.Compose();
            }
        }
Exemple #2
0
        public SerializationMethodsBase AddTypeDependence(Type type)
        {
            SerializationMethodsBase result;

            if (Dependencies.TryGetValue(type, out result))
            {
                return(result);
            }
            else
            {
                if (Serializer.GetCached(type, out result))
                {
                }
                else
                {
                    // Collections like types
                    if (type.IsArray)
                    {
                        result = new ArraySerializationMethodsChain(type, AddTypeDependence(type.GetElementType()), false);
                    }
                    else if (type.GetInterfaces().Any((Type t) => SerializeStream.IsCollectionType(t)))
                    {
                        Type elementType = type.GetInterfaces().First((Type interfaceType) => interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(ICollection <>)).GetGenericArguments()[0];
                        result = (SerializationMethodsBase)typeof(CollectionSerializationMethodsChain <,>).MakeGenericType(type, elementType).GetConstructor(new Type[] { typeof(SerializationMethodsBase), typeof(bool) }).Invoke(new object[] { AddTypeDependence(elementType), false });
                    }
                    else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                    {
                        Type[] genericArgs = type.GetGenericArguments();
                        result = (SerializationMethodsBase)typeof(KeyValuePairSerializationMethodsChain <, ,>).MakeGenericType(type, genericArgs[0], genericArgs[1]).GetConstructor(new Type[] { typeof(SerializationMethodsBase), typeof(SerializationMethodsBase), typeof(bool) }).Invoke(new object[] { AddTypeDependence(genericArgs[0]), AddTypeDependence(genericArgs[1]), false });
                    }
                    else
                    {
                        LocalCompilationContext compileContext = new LocalCompilationContext(type, this);
                        compileQueue.Enqueue(compileContext);
                        result = compileContext.serializationMethods;
                    }
                }
            }
            Dependencies.Add(type, result);
            return(result);
        }