NStub.CSharp.CSharpCodeGenerator.GenerateCode C# (CSharp) Method

GenerateCode() public method

This methods actually performs the code generation for the file current System.CodeDom.CodeNamespace. All classes within the namespace will have exactly one file generated for them.
public GenerateCode ( ) : void
return void
        public void GenerateCode()
        {
            // We want to write a separate file for each type
            foreach (CodeTypeDeclaration codeTypeDeclaration in this.codeNamespace.Types)
            {
                // Create a namespace for the Type in order to put it in scope
                var ns = new CodeNamespace(this.codeNamespace.Name);

                // Clean the type name
                codeTypeDeclaration.Name =
                    Utility.ScrubPathOfIllegalCharacters(codeTypeDeclaration.Name);

                // Create our test type
                codeTypeDeclaration.Name =
                    Utility.GetUnqualifiedTypeName(codeTypeDeclaration.Name) + "Test";
                codeTypeDeclaration.IsPartial = true;

                // Give it a default public constructor
                var codeConstructor = new CodeConstructor { Attributes = MemberAttributes.Public };
                codeTypeDeclaration.Members.Add(codeConstructor);

                // Set out member names correctly
                foreach (CodeTypeMember typeMember in codeTypeDeclaration.Members)
                {
                    if (typeMember is CodeMemberMethod)
                    {
                        // We don't generate default constructors
                        if (!(typeMember is CodeConstructor))
                        {
                            CreateStubForCodeMemberMethod(typeMember as CodeMemberMethod);
                        }
                    }
                }

                ns.Types.Add(codeTypeDeclaration);

                RemoveDuplicatedMembers(codeTypeDeclaration);

                this.WriteClassFile(codeTypeDeclaration.Name, ns);
            }
        }