示例#1
0
        public void Execute(IResponseWriter writer, string[] arguments)
        {
            if (arguments.Length < 2)
            {
                writer.Write("error|Invalid number of arguments. " +
                             "Usage: new {template name} {item name} {template arguments}");
                return;
            }

            var className = getFileName(arguments[1]);
            var location  = getLocation(arguments[1]);

            if (!_project.Read(location, _getTypesProviderByLocation))
            {
                return;
            }

            var template = _pickTemplate(arguments[0], _project.Type);

            if (template == null)
            {
                writer.Write("error|No template with the name {0} exists.", arguments[0]);
                return;
            }
            var ns = getNamespace(location, _project.Fullpath, _project.DefaultNamespace);

            template.Run(location, className, ns, _project.Fullpath, _project.Type, getArguments(arguments));
            if (template.File == null)
            {
                return;
            }

            _project.AppendFile(template.File);
            _project.Write();

            writer.Write("comment|Created class {0}.{1}", ns, className);
            writer.Write("comment|Full path {0}", template.File.Fullpath);

            gotoFile(writer, template.File.Fullpath, template.Line, template.Column, location);
        }