public void AddFunction(LuaFunctionNode functionNode)
 {
     for (int i = 0; i < FunctionNodes.Count; i++)
     {
         if (FunctionNodes[i].functionName == functionNode.functionName ||
             string.IsNullOrEmpty(functionNode.functionName))
         {
             return;
         }
     }
     FunctionNodes.Add(functionNode);
 }
        public override string ToString(LuaDocumentNode documentNode)
        {
            StringBuilder builder = new StringBuilder();

            //field
            LuaFieldNode field = new LuaFieldNode($"_{propertyName}", memberType, initStatementNode);

            builder.Append(field.ToString(documentNode)).Append(nextLine);

            //get function
            LuaFunctionNode getFunctionNode = new LuaFunctionNode($"get{propertyName}", memberType, null,
                                                                  new List <LuaBaseStatementNode>());



            if (getStatementNodes == null || getStatementNodes.Count == 0)
            {
                var getStatementNode = new LuaScriptStatementNode(defualtGetStatement);
                getFunctionNode.statementNodes.Add(getStatementNode);
            }
            for (int i = 0; i < getStatementNodes.Count; i++)
            {
                getFunctionNode.statementNodes.Add(getStatementNodes[i]);
            }


            builder.Append(getFunctionNode.ToString(documentNode)).Append(nextLine);

            //set function
            LuaFunctionNode setFunctionNode = new LuaFunctionNode($"set{propertyName}", memberType, new List <string>(),
                                                                  new List <LuaBaseStatementNode>());

            setFunctionNode.functionArg.Add(propertyName);

            if (setStatementNodes == null || setStatementNodes.Count == 0)
            {
                var setStatementNode = new LuaScriptStatementNode(defualtSetStatement);
                setFunctionNode.statementNodes.Add(setStatementNode);
            }

            for (int i = 0; i < setStatementNodes.Count; i++)
            {
                setFunctionNode.statementNodes.Add(setStatementNodes[i]);
            }


            builder.Append(setFunctionNode.ToString(documentNode));

            return(builder.ToString());
        }
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="context"></param>
        public void Parse(string context)
        {
            //requires
            RequireNodes.Clear();
            if (context.Contains(LUA_REQUIRES_TAG))
            {
                var requireContext = context.FindBetween($"{LUA_REQUIRES_TAG}", $"{LUA_REQUIRES_TAG} end");
                var lines          = from line in requireContext.Split('\n') where !string.IsNullOrEmpty(line.Trim()) select line;
                lines.Foreach((line) =>
                {
                    var requireNode = new LuaRequireNode();
                    requireNode.Parse(line);
                    RequireNodes.Add(requireNode);
                });
            }

            //model
            ModelNode = null;
            if (context.Contains(LUA_MODEL_TAG))
            {
                var modelContext = context.FindBetween($"{LUA_MODEL_TAG}", $"{LUA_MODEL_TAG} end");
                ModelNode = new LuaModelNode();
                ModelNode.Parse(modelContext);
            }
            //class
            ClassName          = null;
            ClassInitStatement = null;
            if (context.Contains(LUA_CLASSDEINE_TAG))
            {
                var classDefineContext = context.FindBetween($"{LUA_CLASSDEINE_TAG}", $"{LUA_CLASSDEINE_TAG} end");
                var splits             = classDefineContext.Split('=');
                ClassName          = splits[0].Trim();
                ClassInitStatement = splits[1].Trim() == "{}" ? null : new LuaScriptStatementNode(splits[1].Trim());
            }
            //fields
            FieldNodes.Clear();
            if (context.Contains(LUA_FIELDS_TAG))
            {
                var fieldsContext = context.FindBetween($"{LUA_FIELDS_TAG}", $"{LUA_FIELDS_TAG} end");
                while (true)
                {
                    if (string.IsNullOrEmpty(fieldsContext) || !fieldsContext.Contains(LUA_NEXT_TAG))
                    {
                        break;
                    }
                    var endPosition  = fieldsContext.IndexOf(LUA_NEXT_TAG);
                    var fieldContext = fieldsContext.Substring(0, endPosition).Trim();
                    var fieldNode    = new LuaFieldNode();
                    FieldNodes.Add(fieldNode);
                    fieldNode.Parse(fieldContext);
                    fieldsContext = fieldsContext.FindAfter(LUA_NEXT_TAG).Trim();
                }
            }
            //properties
            PropertyNodes.Clear();
            if (context.Contains(LUA_PROPERTIES_TAG))
            {
                var propertiesContext = context.FindBetween($"{LUA_PROPERTIES_TAG}", $"{LUA_PROPERTIES_TAG} end");
                while (true)
                {
                    if (string.IsNullOrEmpty(propertiesContext) || !propertiesContext.Contains(LUA_NEXT_TAG))
                    {
                        break;
                    }
                    var endPosition     = propertiesContext.IndexOf(LUA_NEXT_TAG);
                    var propertyContext = propertiesContext.Substring(0, endPosition).Trim();
                    var propertyNode    = new LuaPropertyNode();
                    PropertyNodes.Add(propertyNode);
                    propertyNode.Parse(propertyContext);
                    propertiesContext = propertiesContext.FindAfter(LUA_NEXT_TAG).Trim();
                }
            }
            //functions
            FunctionNodes.Clear();
            if (context.Contains(LUA_FUNCTIONS_TAG))
            {
                var functionsContext = context.FindBetween($"{LUA_FUNCTIONS_TAG}", $"{LUA_FUNCTIONS_TAG} end");
                int i = 0;
                while (true)
                {
                    i++;
                    if (i > 100)
                    {
                        break;
                    }
                    if (string.IsNullOrEmpty(functionsContext) || !functionsContext.Contains(LUA_NEXT_TAG) || i > 100)
                    {
                        break;
                    }
                    var endPosition     = functionsContext.IndexOf(LUA_NEXT_TAG);
                    var functionContext = functionsContext.Substring(0, endPosition).Trim();
                    var functionNode    = new LuaFunctionNode();
                    FunctionNodes.Add(functionNode);
                    functionNode.Parse(functionContext);
                    functionsContext = functionsContext.FindAfter(LUA_NEXT_TAG).Trim();
                }
            }
            //statements
            StatementNodes.Clear();
            if (context.Contains(LUA_STATEMENTS_TAG))
            {
                var statementsContext = context.FindBetween($"{LUA_STATEMENTS_TAG}", $"{LUA_STATEMENTS_TAG} end");
                var lines             = from line in statementsContext.SplitAndTrim('\n')
                                        where string.IsNullOrEmpty(line.Trim())
                                        select new LuaScriptStatementNode(line);
                StatementNodes.AddRange(lines);
            }
            //custom
            CustomScript = null;
            if (context.Contains(LUA_CUSTOM_TAG))
            {
                var customContext = context.FindBetween($"{LUA_CUSTOM_TAG}", $"{LUA_CUSTOM_TAG} end");
                CustomScript = customContext.Trim();
            }
        }