/// <summary>
 /// Instantiates the correct type of component.
 /// </summary>
 /// <param name="component">The component.</param>
 /// <param name="localVariable">The local variable.</param>
 /// <returns></returns>
 private LocalVariableComponent InstantiateTheCorrectTypeOfComponent(Object component,VariableType localVariable)
 {
     if (component is ObjectComponentType)
         return new LocalVariableObjectComponent((ObjectComponentType)component, systemCharacteristics);
     if (component is VariableComponentType)
         return new LocalVariableVariablesComponent(
             localVariable, 
             (VariableComponentType)component, 
             this.variablesOfDefinitions, 
             this.systemCharacteristics,
             this.ExternalVariables);
     if (component is LiteralComponentType)
         return new LocalVariableLiteralComponent((LiteralComponentType)component);
     if (component is ConcatFunctionType)
         return this.CreateConcatFunctionComponent(component,localVariable);
     if (component is ArithmeticFunctionType)
         return this.CreateArithmeticFunctionComponent(component, localVariable);
     if (component is BeginFunctionType)
         return this.CreateBeginFunctionComponent(component, localVariable);
     if (component is EndFunctionType)
         return this.CreateEndFunctionComponent(component, localVariable);
     if (component is SubstringFunctionType)
         return this.CreateSubstringFunctionComponent(component, localVariable);
     if (component is SplitFunctionType)
         return this.CreateSplitFunctionComponent(component, localVariable);
     if (component is TimeDifferenceFunctionType)
         return this.CreateTimeDifferenceComponent(component, localVariable);
     if (component is RegexCaptureFunctionType)
         return this.CreateRegexCaptureFunctionComponent(component, localVariable);
     if (component is EscapeRegexFunctionType)
         return this.CreateEscapeRegexFunctionComponent(component, localVariable);
     if (component is UniqueFunctionType)
         return this.CreateUniqueFunctionComponent(component, localVariable);
     if (component is CountFunctionType)
         return this.CreateCountFunctionComponent(component, localVariable);
     return null;
 }
 private LocalVariableComponent CreateEscapeRegexFunctionComponent(object component, VariableType localVariable)
 {
     EscapeRegexFunctionType escapeRegexFunctionType = (EscapeRegexFunctionType)component;
     EscapeRegexFunctionComponent escapeRegexFunctionComponent = new EscapeRegexFunctionComponent(escapeRegexFunctionType);
     LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(escapeRegexFunctionType.Item, localVariable);
     escapeRegexFunctionComponent.AddComponent(variableComponent);
     return escapeRegexFunctionComponent;
 }   
        private LocalVariableComponent CreateTimeDifferenceComponent(object component, VariableType localVariable)
        {
            TimeDifferenceFunctionType timeDifferenceType = (TimeDifferenceFunctionType)component;
            TimeDifferenceFunctionComponent timeDifferenceComponent = new TimeDifferenceFunctionComponent(timeDifferenceType);

            for (int i = 0; i < timeDifferenceType.Items.Count(); i++)
            {
                LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(timeDifferenceType.Items[i],localVariable);
                timeDifferenceComponent.AddComponent(variableComponent);
            }
            return timeDifferenceComponent;
        }
 private LocalVariableComponent CreateRegexCaptureFunctionComponent(object component, VariableType localVariable)
 {
     RegexCaptureFunctionType regexCaptureFunctionType = (RegexCaptureFunctionType)component;
     RegexCaptureFunctionComponent regexCaptureFunctionComponent = new RegexCaptureFunctionComponent(regexCaptureFunctionType);
     LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(regexCaptureFunctionType.Item, localVariable);
     regexCaptureFunctionComponent.AddComponent(variableComponent);
     return regexCaptureFunctionComponent;
 }
 private LocalVariableComponent CreateSubstringFunctionComponent(Object component, VariableType localVariable)
 {
     SubstringFunctionType substringFunctionType = (SubstringFunctionType)component;
     SubStringFunctionComponent subStringFunctionComponent = new SubStringFunctionComponent(substringFunctionType);
     LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(substringFunctionType.Item, localVariable);
     subStringFunctionComponent.AddComponent(variableComponent);
     return subStringFunctionComponent;
 }
 private LocalVariableComponent CreateSplitFunctionComponent(object component, VariableType localVariable)
 {
     SplitFunctionType splitFunctionType = (SplitFunctionType)component;
     SplitFunctionComponent splitFunctionComponent = new SplitFunctionComponent(splitFunctionType);
     LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(splitFunctionType.Item, localVariable);
     splitFunctionComponent.AddComponent(variableComponent);
     return splitFunctionComponent;
 }
        private LocalVariableComponent CreateEndFunctionComponent(object component, VariableType localVariable)
        {
            EndFunctionType endFunctionType = (EndFunctionType)component;
            EndFunctionComponent endFunctionComponent = new EndFunctionComponent(endFunctionType);
            LocalVariableComponent localVariableComponent = this.InstantiateTheCorrectTypeOfComponent(endFunctionType.Item, localVariable);
            endFunctionComponent.AddComponent(localVariableComponent);
            return endFunctionComponent;

        }
 private LocalVariableComponent CreateBeginFunctionComponent(object component, VariableType localVariable)
 {
     BeginFunctionType beginFunctionType = (BeginFunctionType)component;
     BeginFunctionComponent beginFunctionComponent = new BeginFunctionComponent(beginFunctionType);
     LocalVariableComponent localVariableComponent = this.InstantiateTheCorrectTypeOfComponent(beginFunctionType.Item, localVariable);
     beginFunctionComponent.AddComponent(localVariableComponent);
     return beginFunctionComponent;
 }
        private LocalVariableComponent CreateArithmeticFunctionComponent(Object component, VariableType localVariable)
        {
            ArithmeticFunctionType arithmeticFunctionType = (ArithmeticFunctionType)component;
            ArithmeticFunctionComponent arithmeticFunctionComponent = new ArithmeticFunctionComponent(arithmeticFunctionType);

            for (int i = 0; i < arithmeticFunctionType.Items.Count(); i++)
            {
                LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(arithmeticFunctionType.Items[i],localVariable);
                arithmeticFunctionComponent.AddComponent(variableComponent);
            }
            return arithmeticFunctionComponent;
        }
        /// <summary>
        /// Creates the concat function component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="localVariable">The local variable.</param>
        /// <returns></returns>
        private LocalVariableComponent CreateConcatFunctionComponent(Object component, VariableType localVariable)
        {
            ConcatFunctionType concatFunctionType = (ConcatFunctionType)component;
            ConcatFunctionComponent concatFunctionComponent = new ConcatFunctionComponent(concatFunctionType, this.variablesOfDefinitions,this.systemCharacteristics);

            for (int i = 0; i < concatFunctionType.Items.Count(); i++)
            {
                LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(concatFunctionType.Items[i],localVariable);
                concatFunctionComponent.AddComponent(variableComponent);
            }
            return concatFunctionComponent;
        }
        private LocalVariableComponent CreateUniqueFunctionComponent(object component, VariableType localVariable)
        {
            var uniqueFunctionType = (UniqueFunctionType)component;
            var uniqueFunctionComponent = new UniqueFunctionComponent(uniqueFunctionType, this.variablesOfDefinitions, this.systemCharacteristics);

            for (int i = 0; i < uniqueFunctionType.Items.Count(); i++)
            {
                LocalVariableComponent variableComponent = this.InstantiateTheCorrectTypeOfComponent(uniqueFunctionType.Items[i], localVariable);
                uniqueFunctionComponent.AddComponent(variableComponent);
            }
            return uniqueFunctionComponent;
        }