当前位置: 首页>>代码示例>>C#>>正文


C# PolicyContainer类代码示例

本文整理汇总了C#中PolicyContainer的典型用法代码示例。如果您正苦于以下问题:C# PolicyContainer类的具体用法?C# PolicyContainer怎么用?C# PolicyContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PolicyContainer类属于命名空间,在下文中一共展示了PolicyContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatText

        /// <summary>
        /// Used for formatting the entire document
        /// </summary>
        public override string FormatText(PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, string input, int startOffset, int endOffset)
        {
            var policy = policyParent.Get<DFormattingPolicy> (mimeTypeChain);
            var textPolicy = policyParent.Get<TextStylePolicy> (mimeTypeChain);
            var data = new TextEditorData{ Text = input };

            if(IndentCorrectionOnly)
            {
                using(var s = data.OpenStream())
                    using(var r = new StreamReader(s))
                        D_Parser.Formatting.Indent.IndentEngineWrapper.CorrectIndent(r, startOffset, endOffset, data.Document.Replace, policy.Options, new TextStyleAdapter(textPolicy));
                return data.Text;
            }

            var ast = DParser.ParseString(input, false, true) as DModule;
            var formattingVisitor = new DFormattingVisitor(policy.Options, new DocAdapt(data.Document), ast, new TextStyleAdapter(textPolicy));

            // Only clip to a region if it's necessary
            if(startOffset > 0 || endOffset < input.Length-1)
            {
                formattingVisitor.CheckFormattingBoundaries = true;
                var dl = data.Document.OffsetToLocation(startOffset);
                formattingVisitor.FormattingStartLocation = new D_Parser.Dom.CodeLocation(dl.Column, dl.Line);
                dl = data.Document.OffsetToLocation(endOffset);
                formattingVisitor.FormattingEndLocation = new D_Parser.Dom.CodeLocation(dl.Column, dl.Line);
            }

            formattingVisitor.WalkThroughAst();

            formattingVisitor.ApplyChanges(data.Document.Replace);

            return data.Text;
        }
开发者ID:rikkimax,项目名称:Mono-D,代码行数:36,代码来源:DCodeFormatter.cs

示例2: CorrectIndenting

		public override void CorrectIndenting (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, 
			TextEditorData data, int line)
		{
			DocumentLine lineSegment = data.Document.GetLine (line);
			if (lineSegment == null)
				return;

			try {
				var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
				var tracker = new CSharpIndentEngine (data.Document, data.CreateNRefactoryTextEditorOptions (),  policy.CreateOptions ());

				tracker.Update (lineSegment.Offset);
				for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.Length; i++) {
					tracker.Push (data.Document.GetCharAt (i));
				}

				string curIndent = lineSegment.GetIndentation (data.Document);

				int nlwsp = curIndent.Length;
				if (!tracker.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.LengthIncludingDelimiter && data.Document.GetCharAt (lineSegment.Offset + nlwsp) == '*')) {
					// Possibly replace the indent
					string newIndent = tracker.ThisLineIndent;
					if (newIndent != curIndent) 
						data.Replace (lineSegment.Offset, nlwsp, newIndent);
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error while indenting", e);
			}
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:29,代码来源:CSharpFormatter.cs

示例3: CorrectIndenting

		public override void CorrectIndenting (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, 
			TextEditorData data, int line)
		{
			LineSegment lineSegment = data.Document.GetLine (line);
			if (lineSegment == null)
				return;

			var policy = policyParent.Get<CFormattingPolicy> (mimeTypeChain);
			var tracker = new DocumentStateTracker<CIndentEngine> (new CIndentEngine (policy), data);
			tracker.UpdateEngine (lineSegment.Offset);
			for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.EditableLength; i++) {
				tracker.Engine.Push (data.Document.GetCharAt (i));
			}

			string curIndent = lineSegment.GetIndentation (data.Document);

			int nlwsp = curIndent.Length;
			if (!tracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.Length && data.Document.GetCharAt (lineSegment.Offset + nlwsp) == '*')) {
				// Possibly replace the indent
				string newIndent = tracker.Engine.ThisLineIndent;
				if (newIndent != curIndent) 
					data.Replace (lineSegment.Offset, nlwsp, newIndent);
			}
			tracker.Dispose ();
		}
开发者ID:famousthom,项目名称:monodevelop,代码行数:25,代码来源:CFormatter.cs

示例4: CorrectIndentingImplementation

		protected override void CorrectIndentingImplementation (PolicyContainer policyParent, TextEditor editor, int line)
		{
			var lineSegment = editor.GetLine (line);
			if (lineSegment == null)
				return;

			try {
				var policy = policyParent.Get<CSharpFormattingPolicy> (MimeType);
				var textpolicy = policyParent.Get<TextStylePolicy> (MimeType);
				var tracker = new CSharpIndentEngine (policy.CreateOptions (textpolicy));

				tracker.Update (IdeApp.Workbench.ActiveDocument.Editor, lineSegment.Offset);
				for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.Length; i++) {
					tracker.Push (editor.GetCharAt (i));
				}

				string curIndent = lineSegment.GetIndentation (editor);

				int nlwsp = curIndent.Length;
				if (!tracker.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.LengthIncludingDelimiter && editor.GetCharAt (lineSegment.Offset + nlwsp) == '*')) {
					// Possibly replace the indent
					string newIndent = tracker.ThisLineIndent;
					if (newIndent != curIndent) 
						editor.ReplaceText (lineSegment.Offset, nlwsp, newIndent);
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error while indenting", e);
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:29,代码来源:CSharpFormatter.cs

示例5: FormatText

		public string FormatText (PolicyContainer policyParent, string mimeType, string input)
		{
			TextStylePolicy policy;
			if (policyParent != null)
				policy = policyParent.Get <TextStylePolicy> (DesktopService.GetMimeTypeInheritanceChain (mimeType));
			else
				policy = PolicyService.GetDefaultPolicy <TextStylePolicy> (DesktopService.GetMimeTypeInheritanceChain (mimeType));
			
			XmlTextReader reader = new XmlTextReader (new StringReader (input));
			reader.WhitespaceHandling = WhitespaceHandling.None;
			
			StringWriter indentedXmlWriter = new StringWriter ();
			XmlWriterSettings settings = new XmlWriterSettings ();
			settings.Indent = true;
			if (policy.TabsToSpaces) {
				settings.IndentChars = new string (' ', policy.TabWidth);
			} else {
				settings.IndentChars = "\t";
			}
			settings.NewLineChars = policy.GetEolMarker ();
			
			try {
				XmlWriter xmlWriter = XmlTextWriter.Create (indentedXmlWriter, settings);
				xmlWriter.WriteNode (reader, false);
				xmlWriter.Flush ();
			} catch {
				// Ignore malfored xml
				return input;
			}

			return indentedXmlWriter.ToString ();
		}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:32,代码来源:XmlFormatter.cs

示例6: Format

		static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, TextEditor editor, DocumentContext context, int startOffset, int endOffset, bool exact, bool formatLastStatementOnly = false, OptionSet optionSet = null)
		{
			TextSpan span;
			if (exact) {
				span = new TextSpan (startOffset, endOffset - startOffset);
			} else {
				span = new TextSpan (0, endOffset);
			}

			var analysisDocument = context.AnalysisDocument;
			if (analysisDocument == null)
				return;

			using (var undo = editor.OpenUndoGroup (/*OperationType.Format*/)) {
				try {
					var syntaxTree = analysisDocument.GetSyntaxTreeAsync ().Result;

					if (formatLastStatementOnly) {
						var root = syntaxTree.GetRoot ();
						var token = root.FindToken (endOffset);
						var tokens = ICSharpCode.NRefactory6.CSharp.FormattingRangeHelper.FindAppropriateRange (token);
						if (tokens.HasValue) {
							span = new TextSpan (tokens.Value.Item1.SpanStart, tokens.Value.Item2.Span.End - tokens.Value.Item1.SpanStart);
						} else {
							var parent = token.Parent;
							if (parent != null)
								span = parent.FullSpan;
						}
					}

					if (optionSet == null) {
						var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
						var textPolicy = policyParent.Get<TextStylePolicy> (mimeTypeChain);
						optionSet = policy.CreateOptions (textPolicy);
					}

					var doc = Formatter.FormatAsync (analysisDocument, span, optionSet).Result;
					var newTree = doc.GetSyntaxTreeAsync ().Result;
					var caretOffset = editor.CaretOffset;

					int delta = 0;
					foreach (var change in newTree.GetChanges (syntaxTree)) {
						if (!exact && change.Span.Start + delta >= caretOffset)
							continue;
						var newText = change.NewText;
						editor.ReplaceText (delta + change.Span.Start, change.Span.Length, newText);
						delta = delta - change.Span.Length + newText.Length;
					}

					var caretEndOffset = caretOffset + delta;
					if (0 <= caretEndOffset && caretEndOffset < editor.Length)
						editor.CaretOffset = caretEndOffset;
					if (editor.CaretColumn == 1)
						editor.CaretColumn = editor.GetVirtualIndentationColumn (editor.CaretLine);
				} catch (Exception e) {
					LoggingService.LogError ("Error in on the fly formatter", e);
				}
			}
		}
开发者ID:xinfushe,项目名称:monodevelop,代码行数:59,代码来源:OnTheFlyFormatter.cs

示例7: FormatImplementation

		protected override Core.Text.ITextSource FormatImplementation (PolicyContainer policyParent, string mimeType, Core.Text.ITextSource input, int startOffset, int length)
		{
			if (policyParent == null)
				policyParent = PolicyService.DefaultPolicies;
			var txtPol = policyParent.Get<TextStylePolicy> (mimeType);
			var xmlPol = policyParent.Get<XmlFormattingPolicy> (mimeType);
			return new StringTextSource(FormatXml (txtPol, xmlPol, input.Text));
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:8,代码来源:XmlFormatter.cs

示例8: FormatText

		public string FormatText (PolicyContainer policyParent, string mimeType, string input, int fromOffest, int toOffset)
		{
			if (policyParent == null)
				policyParent = PolicyService.DefaultPolicies;
			if (prettyPrinter != null)
				return prettyPrinter.FormatText (policyParent, mimeType, input, fromOffest, toOffset);
			return formatter.FormatText (policyParent, mimeType, input, fromOffest, toOffset);
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:8,代码来源:Formatter.cs

示例9: SetUp

        public void SetUp()
        {
            // Arrange
            _policyContainer = TestDataFactory.CreateValidPolicyContainer();

            // Act
            _return = _policyContainer.AddPolicy<SomePolicy>();
        }
开发者ID:pvivera,项目名称:FluentSecurity,代码行数:8,代码来源:PolicyContainerSpec.cs

示例10: FormatText

		public string FormatText (PolicyContainer policyParent, string mimeType, string input, int fromOffset, int toOffset)
		{
			if (input == null)
				throw new ArgumentNullException (nameof (input));
			if (mimeType == null)
				throw new ArgumentNullException (nameof (mimeType));
			return FormatImplementation (policyParent ?? PolicyService.DefaultPolicies, mimeType, new StringTextSource (input), fromOffset, toOffset - fromOffset).Text;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:8,代码来源:AbstractCodeFormatter.cs

示例11: Format

		public ITextSource Format (PolicyContainer policyParent, string mimeType, ITextSource input, int startOffset, int length)
		{
			if (startOffset < 0 || startOffset > input.Length)
				throw new ArgumentOutOfRangeException (nameof (startOffset), "should be >= 0 && < " + input.Length + " was:" + startOffset);
			if (length < 0 || startOffset + length > input.Length)
				throw new ArgumentOutOfRangeException (nameof (length), "should be >= 0 && < " + (input.Length - startOffset) + " was:" + length);
			try {
				return FormatImplementation (policyParent ?? PolicyService.DefaultPolicies, mimeType, input, startOffset, length);
			} catch (Exception e) {
				LoggingService.LogError ("Error while formatting text.", e);
			}
			return input.CreateSnapshot (startOffset, length);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:13,代码来源:AbstractCodeFormatter.cs

示例12: Format

		public ITextSource Format (PolicyContainer policyParent, ITextSource input, ISegment segment = null)
		{
			try {
				if (segment == null)
					return formatter.Format (policyParent, mimeType, input);
				return formatter.Format (policyParent, mimeType, input, segment.Offset, segment.EndOffset);
			} catch (Exception e) {
				LoggingService.LogError ("Error while formatting text.", e);
				if (segment == null)
					return input;
				return input.CreateSnapshot (segment.Offset, segment.Length);
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:13,代码来源:CodeFormatter.cs

示例13: FormatText

		public string FormatText (PolicyContainer policyParent, string input, ISegment segment = null)
		{
			try {
				if (segment == null)
					return formatter.FormatText (policyParent, mimeType, input, 0, input.Length);
				return formatter.FormatText (policyParent, mimeType, input, segment.Offset, segment.EndOffset);
			} catch (Exception e) {
				LoggingService.LogError ("Error while formatting text.", e);
				if (segment == null)
					return input;
				return input.Substring (segment.Offset, segment.Length);
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:13,代码来源:CodeFormatter.cs

示例14: Format

		public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain,
			TextEditorData data, ProjectDom dom, DomLocation location, bool correctBlankLines)
		{
			var compilationUnit = new MonoDevelop.CSharp.Parser.CSharpParser ().Parse (data);
			var policy = policyParent.Get<CSharpFormattingPolicy> (mimeTypeChain);
			var domSpacingVisitor = new DomSpacingVisitor (policy, data) {
				AutoAcceptChanges = false,
			};
			compilationUnit.AcceptVisitor (domSpacingVisitor, null);
			
			var domIndentationVisitor = new DomIndentationVisitor (policy, data) {
				AutoAcceptChanges = false,
			};
			domIndentationVisitor.CorrectBlankLines = correctBlankLines;
			compilationUnit.AcceptVisitor (domIndentationVisitor, null);
			
			var changes = new List<Change> ();
			changes.AddRange (domSpacingVisitor.Changes);
			changes.AddRange (domIndentationVisitor.Changes);
			RefactoringService.AcceptChanges (null, null, changes);
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:21,代码来源:OnTheFlyFormatter.cs

示例15: InternalFormat

		protected override string InternalFormat (PolicyContainer policyParent, string mimeType, string input, int startOffset, int endOffset)
		{
			IEnumerable<string> mtypes = DesktopService.GetMimeTypeInheritanceChain (mimeType);
			TextStylePolicy currentPolicy = policyParent != null
					? policyParent.Get<TextStylePolicy> (mtypes)
					: MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<TextStylePolicy> (mtypes);
			
			input = input ?? "";
			int line = 0, col = 0;
			string eolMarker = currentPolicy.GetEolMarker ();
			StringBuilder result = new StringBuilder ();
			
			for (int i = startOffset; i <= endOffset; i++) {
				char ch = input[i];
				switch (ch) {
				case '\t':
					if (currentPolicy.TabsToSpaces) {
						int tabWidth = GetNextTabstop (col, currentPolicy.TabWidth) - col;
						result.Append (new string (' ', tabWidth));
						col += tabWidth;
					} else 
						goto default;
					break;
				case '\r':
					if (i + 1 < input.Length && input[i + 1] == '\n')
						i++;
					goto case '\n';
				case '\n':
					result.Append (eolMarker);
					line++;
					col = 0;
					break;
				default:
					result.Append (ch);
					col++;
					break;
				}
			}
			return result.ToString ();
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:40,代码来源:DefaultFormatter.cs


注:本文中的PolicyContainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。