ICSharpCode.NRefactory.CSharp.CodeActions.TestRefactoringContext.Create C# (CSharp) Méthode

Create() public static méthode

public static Create ( string content ) : TestRefactoringContext
content string
Résultat TestRefactoringContext
		public static TestRefactoringContext Create (string content)
		{
			int idx = content.IndexOf ("$");
			if (idx >= 0)
				content = content.Substring (0, idx) + content.Substring (idx + 1);
			int idx1 = content.IndexOf ("<-");
			int idx2 = content.IndexOf ("->");
			
			int selectionStart = 0;
			int selectionEnd = 0;
			if (0 <= idx1 && idx1 < idx2) {
				content = content.Substring (0, idx2) + content.Substring (idx2 + 2);
				content = content.Substring (0, idx1) + content.Substring (idx1 + 2);
				selectionStart = idx1;
				selectionEnd = idx2 - 2;
				idx = selectionEnd;
			}
			
			var doc = new StringBuilderDocument (content);
			var parser = new CSharpParser ();
			var unit = parser.Parse (content, "program.cs");
			foreach (var error in parser.Errors)
				Console.WriteLine (error.Message);
			Assert.IsFalse (parser.HasErrors, "File contains parsing errors.");
			unit.Freeze ();
			var parsedFile = unit.ToTypeSystem ();
			
			IProjectContent pc = new CSharpProjectContent ();
			pc = pc.UpdateProjectContent (null, parsedFile);
			pc = pc.AddAssemblyReferences (new[] { CecilLoaderTests.Mscorlib, CecilLoaderTests.SystemCore });
			
			var compilation = pc.CreateCompilation ();
			var resolver = new CSharpAstResolver (compilation, unit, parsedFile);
			TextLocation location = TextLocation.Empty;
			if (idx >= 0)
				location = doc.GetLocation (idx);
			return new TestRefactoringContext(doc, location, resolver) {
				selectionStart = selectionStart,
				selectionEnd = selectionEnd
			};
		}
		

Usage Example

        protected List <CodeAction> GetActions <T> (string input) where T : CodeActionProvider, new ()
        {
            var ctx = TestRefactoringContext.Create(input);

            ctx.FormattingOptions = formattingOptions;
            return(new T().GetActions(ctx).ToList());
        }
All Usage Examples Of ICSharpCode.NRefactory.CSharp.CodeActions.TestRefactoringContext::Create