/// <summary> /// Adds a method invoke expression and a partial method definition based on the specified base method name /// to the internal method collection. /// </summary> /// <param name="baseMethodName">base method name w/o the On prefix (like Created for OnCreated)</param> /// <param name="parameters">if provided, the parameters for the method to be generated</param> /// <param name="comments">the comments for the partial property definition</param> public void AddMethodFor(string baseMethodName, CodeParameterDeclarationExpressionCollection parameters, string comments) { Debug.Assert(!string.IsNullOrEmpty(baseMethodName), "Unexpected null or empty base method name!"); if (!string.IsNullOrEmpty(baseMethodName)) { if (!this.methodInvokeExpressions.ContainsKey(baseMethodName)) { string methodName = string.Concat("On", baseMethodName); List <CodeArgumentReferenceExpression> args = new List <CodeArgumentReferenceExpression>(); if (parameters != null && parameters.Count > 0) { foreach (CodeParameterDeclarationExpression paramDeclaration in parameters) { args.Add(new CodeArgumentReferenceExpression(paramDeclaration.Name)); } } // Create method call. // OnMethod(arg1, arg2); this.methodInvokeExpressions.Add(baseMethodName, new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), methodName, args.ToArray())); // Create method declaration. // partial void OnMethod(Type1 param1, Type2 param2); CodeSnippetTypeMember codeSnippet = this.CreateNotificationPartialMethod(baseMethodName, parameters); if (!string.IsNullOrEmpty(comments)) { // Add comment on method declaration. codeSnippet.Comments.AddRange(CodeGenUtilities.GetDocComments(comments, this.isCSharp)); } this.partialMethodSnippets.Add(baseMethodName, codeSnippet); } } }