示例#1
0
        /// <summary>
        /// Takes a processing node and determines if it extends other recursive nodes. If it does, then it calls the callback with the recursive node.
        /// </summary>
        /// <typeparam name="TResult">Type of the result of the processor</typeparam>
        /// <typeparam name="TSerializer">Type of the serializer</typeparam>
        /// <param name="processor">Processor</param>
        /// <param name="callbackName">Name of the method in the class, must be the same that calls it</param>
        public static void ProcessNode <TResult, TSerializer>(
            IProcessorNode <TResult, TSerializer> processor, string callbackName, params object[] args)
            where TSerializer : ISerializer
        {
            if (processor is ISimpleProcessorNode <TResult, TSerializer> )
            {
                //We don't have to do anything with a simple processor
                return;
            }
            else
            {
                //We check if it's a recursive processor
                if (!InheritsFromRecursiveNode(processor.GetType()))
                {
                    throw new ArgumentException(string.Format("The type '{0}' must be recursive", processor.GetType().Name), "processor");
                }

                //We cast to the recursive node
                var recType = ObtainSuperClass(processor.GetType(), IsRecursiveNode);

                //We obtain the remaining list of processors
                var rest = recType.GetProperty("ProcessorStructure").GetValue(processor, null);

                //Gets the generic types
                Type r1Type = recType.GetGenericArguments()[1];
                Type r2Type = recType.GetGenericArguments()[2];

                //We apply recursion over the internal list of processors
                var methodArgs = new[] { rest }.Concat(args).ToArray();
                typeof(ProcessorUtilities)
                .GetMethod(callbackName, BindingFlags.Public | BindingFlags.Static)
                .MakeGenericMethod(new[] { r1Type, r2Type })
                .Invoke(null, methodArgs);
            }
        }
示例#2
0
 protected IProcessorStructure <TResult, TSerializer> CreateProcessorStructure <TResult>(IProcessorNode <TResult, TSerializer> processor)
 {
     return(new ProcessorStructure <TResult, TSerializer>(processor));
 }
示例#3
0
 public void Add(IProcessorNode <TResult, TSerializer> item)
 {
     ProcessorList.Add(item);
 }
示例#4
0
 public void Insert(int index, IProcessorNode <TResult, TSerializer> item)
 {
     ProcessorList.Insert(index, item);
 }
示例#5
0
 public int IndexOf(IProcessorNode <TResult, TSerializer> item)
 {
     return(ProcessorList.IndexOf(item));
 }
示例#6
0
 public bool Remove(IProcessorNode <TResult, TSerializer> item)
 {
     return(ProcessorList.Remove(item));
 }
示例#7
0
 public bool Contains(IProcessorNode <TResult, TSerializer> item)
 {
     return(ProcessorList.Contains(item));
 }