Пример #1
0
		public string GetRegion(Label label)
		{
			var region = regions.Get(label.Name, null);
			if (region == null)
				return null;
			return code.Substring(region.dataStart, region.dataLength).RemoveCommonNesting();
		}
Пример #2
0
		public string GetRegion(Label label)
		{
			if (!members.ContainsKey(label.Name))
				return null;
			var nodes = members[label.Name];
			if (label.OnlyBody)
				return string.Join("\r\n\r\n", nodes.Select(GetBody));
			return String.Join("\r\n\r\n", nodes.Select(node => node.ToPrettyString()));
		}
Пример #3
0
		private static bool Remove(Label label, ref SyntaxNode tree)
		{
			var members = tree.GetMembers()
				.Where(node => node.Identifier().ValueText == label.Name)
				.ToList();
			if (!members.Any())
				return false;
			if (label.OnlyBody)
				tree = tree.RemoveNodes(members.SelectMany(syntax => syntax.GetBody()), SyntaxRemoveOptions.KeepNoTrivia);
			else
				tree = tree.RemoveNodes(members, SyntaxRemoveOptions.KeepExteriorTrivia);
			return true;
		}
Пример #4
0
		public string RemoveSolution(string code, Label label, out int index)
		{
			var regions = RegionsParser.GetRegions(code);
			if (!regions.ContainsKey(label.Name))
			{
				index = -1;
				return code;
			}

			var region = regions[label.Name];
			index = region.fullStart;
			return code.Remove(region.fullStart, region.fullLength);
		}
Пример #5
0
		public string RemoveSolution(string code, Label label, out int index)
		{
			foreach (var regionRemover in regionRemovers)
			{
				code = regionRemover.RemoveSolution(code, label, out index);
				if (index < 0)
					continue;
				code = code.Insert(index, pragma);
				index += pragma.Length;
				return code;
			}
			index = -1;
			return code;
		}
Пример #6
0
		public string RemoveSolution(string code, Label label, out int index)
		{
			var tree = CSharpSyntaxTree.ParseText(code).GetRoot();
			var solution = tree.GetMembers().FirstOrDefault(node => node.Identifier().ValueText == label.Name);
			if (solution == null)
			{
				index = -1;
				return code;
			}
			if (label.OnlyBody)
			{
				var body = solution.GetBody();
				index = body.FullSpan.Start;
				tree = tree.RemoveNodes(body, SyntaxRemoveOptions.KeepNoTrivia);
			}
			else
			{
				index = solution.Span.Start;
				tree = tree.RemoveNode(solution, SyntaxRemoveOptions.KeepExteriorTrivia);
			}

			code = tree.ToFullString();
			return code;
		}
Пример #7
0
		public string GetRegion(Label label)
		{
			return extractors.Select(extractor => extractor.GetRegion(label)).FirstOrDefault(res => res != null);
		}