public static String GenerateFullClass(ScriptParsed ScriptParsed, String CodeNamespace, String className, String method = "Method")
        {
            String resp  = GenerateFullClass(ScriptParsed.References, ScriptParsed.UsingStatements, CodeNamespace, className, ScriptParsed.MethodCode, method);
            int    index = IndexOfNth(resp, "{", 2);

            String begin = resp.Substring(0, index + 1);

            begin += Environment.NewLine;
            String end = resp.Substring(index + 1);

            String full = begin + ScriptParsed.AuxiliarFunctionsCode + Environment.NewLine + end;

            return(full);
        }
        public String GetCode(ScriptParsed ScriptParsed)
        {
            String resp  = GetCode();
            int    index = IndexOfNth(resp, "{", 2);

            String begin = resp.Substring(0, index + 1);

            begin += Environment.NewLine;
            String end = resp.Substring(index + 1);

            String full = begin + ScriptParsed.AuxiliarFunctionsCode + Environment.NewLine + ScriptParsed.AuxiliarVariableCode + Environment.NewLine + end;

            return(full);
        }
 public Generator(ScriptParsed ScriptParsed, String CodeNamespace, bool addCoreNetAPIs = true ,bool addXNAReferences = false)
     : this(ScriptParsed.references, ScriptParsed.UsingStatements, CodeNamespace, addCoreNetAPIs, addXNAReferences)
 {
 }
        public static String GenerateFullClass(ScriptParsed ScriptParsed, String CodeNamespace, String className, String method = "Method")
        {
            String resp = GenerateFullClass(ScriptParsed.References, ScriptParsed.UsingStatements, CodeNamespace, className,ScriptParsed.MethodCode ,method);
            int index = IndexOfNth(resp, "{", 2);

            String begin = resp.Substring(0, index + 1);
            begin += Environment.NewLine;
            String end = resp.Substring(index + 1);

            String full = begin + ScriptParsed.AuxiliarFunctionsCode + Environment.NewLine + end;
            return full;
        }
        public String GetCode(ScriptParsed ScriptParsed)
        {

            String resp = GetCode();
            int index = IndexOfNth(resp, "{", 2);

            String begin = resp.Substring(0, index + 1);
            begin += Environment.NewLine;
            String end = resp.Substring(index + 1);

            String full = begin + ScriptParsed.AuxiliarFunctionsCode + Environment.NewLine + ScriptParsed.AuxiliarVariableCode + Environment.NewLine + end;
            return full;
            
        }
 public Generator(ScriptParsed ScriptParsed, String CodeNamespace, bool addCoreNetAPIs = true, bool addXNAReferences = false)
     : this(ScriptParsed.references, ScriptParsed.UsingStatements, CodeNamespace, addCoreNetAPIs, addXNAReferences)
 {
 }
        public static ScriptParsed ParseScriptCode(String code)
        {
            ScriptParsed ScriptParsed   = new ScriptParsed();
            bool         insideFunction = false;
            bool         isVariable     = false;
            int          isusing        = 0;
            int          brackets       = 0;

            foreach (var item2 in code.Split('\n'))
            {
                String iter = item2.Replace("\r", "");
                foreach (var item in iter.Split(' '))
                {
                    if (isusing == 1)
                    {
                        if (item.Contains(';'))
                        {
                            ScriptParsed.usingStatements.Add(item.Replace(";", ""));
                            isusing = 0;
                            continue;
                        }
                        else
                        {
                            ScriptParsed.usingStatements.Add(item);
                            isusing = 2;
                            continue;
                        }
                    }
                    if (isusing == 2)
                    {
                        isusing = 0;
                        continue;
                    }

                    if (item == "using")
                    {
                        isusing = 1;
                        continue;
                    }

                    if (item.ToUpperInvariant() == "FUNCTION:")
                    {
                        insideFunction = true;
                        brackets       = -1;
                        continue;
                    }

                    if (item.ToUpperInvariant() == "GLOBAL:")
                    {
                        isVariable = true;
                        continue;
                    }

                    if (isVariable)
                    {
                        if (item.IndexOf(";") >= 0)
                        {
                            isVariable = false;
                            if (item.Count() != 1)
                            {
                                ScriptParsed.variables += item.Substring(0, item.IndexOf(";"));
                                ScriptParsed.variables += ";\n";
                            }
                            else
                            {
                                ScriptParsed.variables += item;
                                ScriptParsed.variables += "\n";
                            }
                            continue;
                        }
                        else
                        {
                            ScriptParsed.variables += item;
                            ScriptParsed.variables += " ";
                        }
                    }

                    if (insideFunction)
                    {
                        if (brackets == -1)
                        {
                            if (item == "{")
                            {
                                brackets = 0;
                            }
                        }

                        if (item == "{")
                        {
                            brackets++;
                        }

                        if (item == "}")
                        {
                            brackets--;
                        }

                        if (brackets == 0)
                        {
                            insideFunction = false;
                        }

                        ScriptParsed.functions += item + " ";
                    }
                    else if (!isVariable)
                    {
                        ScriptParsed.newCode += item + " ";
                    }
                }

                if (insideFunction)
                {
                    ScriptParsed.functions += "\n";
                }
                else
                {
                    ScriptParsed.newCode += "\n";
                }
            }
            return(ScriptParsed);
        }
        public static ScriptParsed ParseScriptCode(String code)
        {
            ScriptParsed ScriptParsed = new ScriptParsed();
            bool insideFunction = false;
            bool isVariable = false;
            int isusing = 0;            
            int brackets = 0;            
            foreach (var item2 in code.Split('\n'))
            {
                String iter = item2.Replace("\r", "");
                foreach (var item in iter.Split(' '))
                {

                    if (isusing == 1)
                    {
                        if (item.Contains(';'))
                        {
                            ScriptParsed.usingStatements.Add(item.Replace(";", ""));
                            isusing = 0;
                            continue;
                        }
                        else
                        {
                            ScriptParsed.usingStatements.Add(item);
                            isusing = 2;
                            continue;
                        }
                    }
                    if (isusing == 2)
                    {
                        isusing = 0;
                        continue;
                    }

                    if (item == "using")
                    {
                        isusing = 1;
                        continue;
                    }

                    if (item.ToUpperInvariant() == "FUNCTION:")
                    {
                        insideFunction = true;
                        brackets = -1;
                        continue;
                    }

                    if (item.ToUpperInvariant() == "GLOBAL:")
                    {
                        isVariable = true;                        
                        continue;
                    }

                    if (isVariable)
                    {
                        if (item.IndexOf(";") >= 0)
                        {
                            isVariable = false;
                            if (item.Count() != 1)
                            {
                                ScriptParsed.variables += item.Substring(0, item.IndexOf(";"));
                                ScriptParsed.variables += ";\n";
                            }
                            else
                            {
                                ScriptParsed.variables += item;
                                ScriptParsed.variables += "\n";
                            }
                            continue;
                        }
                        else
                        {
                           ScriptParsed.variables += item;
                           ScriptParsed.variables += " ";
                        }

                    }

                    if (insideFunction)
                    {
                        if (brackets == -1)
                        {
                            if (item == "{")
                            {
                                brackets = 0;
                            }
                        }

                        if (item == "{")
                        {
                            brackets++;
                        }

                        if (item == "}")
                        {
                            brackets--;
                        }

                        if (brackets == 0)
                        {
                            insideFunction = false;
                        }

                        ScriptParsed.functions += item + " ";
                    }
                    else if(!isVariable)
                    {
                        ScriptParsed.newCode += item + " ";
                    }
                }

                if (insideFunction)
                {
                    ScriptParsed.functions += "\n";
                }
                else
                {
                    ScriptParsed.newCode += "\n";
                }
            }
            return ScriptParsed;
        }