示例#1
0
 public static bool IsVoidFunc(FunctionExpression func)
 {
     if (func.getReturnDescription() == null ||
         func.getReturnDescription().Equals(VOID, StringComparison.OrdinalIgnoreCase))
     {
         return(true);
     }
     return(false);
 }
        /// <summary>
        /// scripts content for a function
        /// </summary>
        /// <param name="functionExpression"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mapAliasWithNode"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns></returns>
        private string GenerateFunctionExpScripts(FunctionExpression functionExpression, ListUIElements listUIElements,
                                                  Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            string accessibility = functionExpression.GetCorrectAccessibility();
            string summary       = functionExpression.getSummary();
            List <ParameterExpression> @params = functionExpression.getParams();
            string name      = functionExpression.getName();
            string returnDes = functionExpression.getReturnDescription();
            string content   = functionExpression.getContent();

            string re = "";

            if (summary != null)
            {
                re += "/// <summary>" + NEW_LINE;
                string[] listLines = summary.Split('\n');
                foreach (string line in listLines)
                {
                    re += "/// " + line + NEW_LINE;
                }
                re += "/// </summary>";
            }
            var pair = GetParamsScripts(@params, listUIElements, mapAliasWithNode, myLog, instanceName);

            if (pair.Item2 != null && pair.Item2.Count > 0)
            {
                for (int fi = 0; fi < pair.Item2.Count; fi++)
                {
                    string paramName = pair.Item2[fi];
                    string paramDesc = @params[fi].getDescription();
                    if (paramDesc == null)
                    {
                        paramDesc = "";
                    }
                    if (re != "")
                    {
                        re += NEW_LINE;
                    }
                    re += "/// <param name=\"" + paramName + "\">" + paramDesc + "</param>";
                }
            }
            string returnType = functionExpression.GetCorrectReturnType();

            if (returnType != FunctionExpression.VOID)
            {
                if (re != "")
                {
                    re += NEW_LINE;
                }
                re += "/// <returns>" + (returnDes ?? "") + "</returns>";
            }
            if (re != "")
            {
                re += NEW_LINE;
            }
            // Ranorex need to insert annotation
            re += InsertAnnotation();
            re += accessibility + " static " + returnType + " " + name + "(";
            re += pair.Item1;
            re += ")" + NEW_LINE;
            re += "{" + NEW_LINE;
            if (content != null)
            {
                string[] listLines = content.Split('\n');
                foreach (string line in listLines)
                {
                    string line1 = line.Trim().StartsWith("//") ? line.Trim() : "// " + line.Trim();
                    re += line1 + NEW_LINE;
                }
            }
            if (returnType != FunctionExpression.VOID)
            {
                re += "return null;" + NEW_LINE;
            }
            re += "}" + NEW_LINE;
            return(re);
        }