private string ParseName(string ruleSet, RulesDomModel codeModel) { return _codeSettings.MethodSettings.NameFormat.Replace("[workflow]", _codeSettings.GetInputFile()) .Replace("[ruleSet]", codeModel.ParentRuleSet.Name) .Replace("[ruleName]", codeModel.Name); }
private CodeTypeMember CreateMethod(string ruleSetName, RulesDomModel codeModel) { // Declare a new CodeEntryPointMethod var method = new CodeMemberMethod { Attributes = MemberAttributes.Public, Name = ParseName(ruleSetName, codeModel), ReturnType = new CodeTypeReference(_codeSettings.MethodSettings.Returns), }; string[] paramList = _codeSettings.MethodSettings.ParametersFormat.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (paramList.Length % 2 == 0) // even numbers { for (int i = 0; i < paramList.Length; i += 2) method.Parameters.Add(new CodeParameterDeclarationExpression(paramList[i], paramList[i + 1])); } // Specify that this method will be both static and public if (_codeSettings.IncludeComments && codeModel.Comments.Count > 0) method.Comments.AddRange(codeModel.Comments.ToArray()); var variableResult = new CodeVariableDeclarationStatement(new CodeTypeReference(_codeSettings.MethodSettings.Returns), "result", new CodeDefaultValueExpression( new CodeTypeReference(_codeSettings.MethodSettings.Returns))); method.Statements.Add(variableResult); var conditionStatement = new CodeConditionStatement(codeModel.Condition, codeModel.Then.ToArray(), codeModel.Else.ToArray()); method.Statements.Add(conditionStatement); method.Statements.Add( new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "result"))); return method; }