CodeMemberMethod method = new CodeMemberMethod(); method.Name = "GetString"; method.Attributes = MemberAttributes.Public; method.ReturnType = new CodeTypeReference(typeof(string));
CodeMemberMethod method = new CodeMemberMethod(); method.Name = "AddNumbers"; method.ReturnType = new CodeTypeReference(typeof(int)); method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "a")); method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "b"));
CodeMemberMethod method = new CodeMemberMethod(); method.Name = "PrintMessage"; method.Attributes = MemberAttributes.Public; method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "message")); method.Statements.Add(new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(Console)), "WriteLine", new CodeVariableReferenceExpression("message")));This code creates a CodeMemberMethod object named "PrintMessage" which takes a string parameter named "message" and invokes the Console.WriteLine method with the "message" parameter. The System.CodeDom.CodeMemberMethod class is a part of the System.CodeDom.dll package library.