コード例 #1
0
        public override List <Change> PerformChanges(RefactoringOptions options, object properties)
        {
            List <Change> changes       = new List <Change>();
            var           resolveResult = options.ResolveResult;

            if (resolveResult == null)
            {
                throw new InvalidOperationException("Cannot generate class here");
            }
            var resType = resolveResult.ResolvedType;

            var    doc           = options.Document;
            var    editor        = doc.Editor;
            var    currentDir    = doc.FileName.ParentDirectory;
            var    nspace        = resType.Namespace;
            string typeName      = resolveResult.ResolvedExpression.Expression;
            var    body          = resType.Type.BodyRegion;
            var    content       = editor.GetTextBetween(body.Start.Line, 1, body.End.Line, body.End.Column);
            var    contentLength = content.Length;

            content = fileFormatResolver.GetNewTypeFileContent(content, nspace, editor.EolMarker);
            CreateFileChange createFileChange = new CreateFileChange(@"{0}\{1}.cs".ToFormat(currentDir, typeName), content);

            changes.Add(createFileChange);

            TextReplaceChange textReplaceChange = new TextReplaceChange();

            textReplaceChange.FileName     = context.GetCurrentFilePath();
            textReplaceChange.RemovedChars = contentLength + 1;
            int num = editor.Document.LocationToOffset(body.Start.Line, 1);

            textReplaceChange.Offset       = num - 1;
            textReplaceChange.InsertedText = string.Empty;
            changes.Add(textReplaceChange);

            return(changes);
        }
コード例 #2
0
        public void Returns_the_new_file_content()
        {
            string fileFormat = resolver.GetNewTypeFileContent("Something", "SomeNameSpace", eol);

            Assert.AreEqual("namespace SomeNameSpace {\r\nSomething\r\n}", fileFormat);
        }