• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SyntaxTree.Span类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CalculatePadding

        // internal for unit testing only, not intended to be used directly in code
        internal static int CalculatePadding(RazorEngineHost host, Span target, int generatedStart)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            int padding;

            padding = CollectSpacesAndTabs(target, host.TabSize) - generatedStart;

            // if we add generated text that is longer than the padding we wanted to insert we have no recourse and we have to skip padding
            // example:
            // Razor code at column zero: @somecode()
            // Generated code will be:
            // In design time: __o = somecode();
            // In Run time: Write(somecode());
            //
            // In both cases the padding would have been 1 space to remote the space the @ symbol takes, which will be smaller than the 6 chars the hidden generated code takes.
            if (padding < 0)
            {
                padding = 0;
            }

            return padding;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:32,代码来源:CodeGeneratorPaddingHelper.cs


示例2: CodeBlockInfo

 public CodeBlockInfo(string name, SourceLocation start, bool isTopLevel, Span transitionSpan, Span initialSpan) {
     Name = name;
     Start = start;
     IsTopLevel = isTopLevel;
     TransitionSpan = transitionSpan;
     InitialSpan = initialSpan;
 }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:7,代码来源:CodeBlockInfo.cs


示例3: OwnsChange

 public virtual bool OwnsChange(Span target, TextChange change)
 {
     int end = target.Start.AbsoluteIndex + target.Length;
     int changeOldEnd = change.OldPosition + change.OldLength;
     return change.OldPosition >= target.Start.AbsoluteIndex &&
            (changeOldEnd < end || (changeOldEnd == end && AcceptedCharacters != AcceptedCharacters.None));
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:7,代码来源:SpanEditHandler.cs


示例4: GenerateCode

		public override void GenerateCode (Span target, CodeGeneratorContext context)
		{
			if (context.Host.DesignTimeMode)
				return;

			ExpressionRenderingMode oldMode = context.GetExpressionRenderingMode ();

			var sb = new StringBuilder ();
			sb.Append (", Tuple.Create<string,object,bool> (");
			sb.WriteCStyleStringLiteral (Prefix.Value);
			sb.Append (", ");

			if (ValueGenerator != null) {
				context.SetExpressionRenderingMode (ExpressionRenderingMode.InjectCode);
			} else {
				sb.WriteCStyleStringLiteral (Value);
				sb.Append (", true)");
			}
			context.BufferStatementFragment (sb.ToString ());

			if (ValueGenerator != null) {
				ValueGenerator.Value.GenerateCode (target, context);
				context.FlushBufferedStatement ();
				context.SetExpressionRenderingMode (oldMode);
				context.AddStatement (", false)");
			} else {
				context.FlushBufferedStatement ();
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:29,代码来源:PreprocessedLiteralAttributeCodeGenerator.cs


示例5: Parse

 public IEnumerable<Node> Parse(Span span)
 {
     return new[]
     {
         new ExpressionNode(span.Content)
     };
 }
开发者ID:ryanhaugh,项目名称:razorblade,代码行数:7,代码来源:ExpressionCodeSpanParser.cs


示例6: TryVisitSpecialSpan

        protected override bool TryVisitSpecialSpan(Span span)
        {
            var vistors = (Vistors ?? Enumerable.Empty<CSharpRazorCodeGeneratorSpanVisitor>());

            return base.TryVisitSpecialSpan(span)
                || vistors.FirstOrDefault(x => x.TryVisit(span)) != null;
        }
开发者ID:RazorPad,项目名称:RazorPad.Core,代码行数:7,代码来源:ViewComponentCSharpRazorCodeGenerator.cs


示例7: PadStatement

        // Special case for statement padding to account for brace positioning in the editor.
        public static string PadStatement(RazorEngineHost host, string code, Span target, ref int startGeneratedCode, out int paddingCharCount)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            // We are passing 0 rather than startgeneratedcode intentionally (keeping v2 behavior).
            int padding = CalculatePadding(host, target, 0);

            // We treat statement padding specially so for brace positioning, so that in the following example:
            //   @if (foo > 0)
            //   {
            //   }
            //
            // the braces shows up under the @ rather than under the if.
            if (host.DesignTimeMode &&
                padding > 0 &&
                target.Previous.Kind == SpanKind.Transition && // target.Previous is guaranteed to be none null if you got any padding.
                String.Equals(target.Previous.Content, SyntaxConstants.TransitionString))
            {
                padding--;
                startGeneratedCode--;
            }

            string generatedCode = PadInternal(host, code, padding, out paddingCharCount);

            return generatedCode;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:35,代码来源:CodeGeneratorPaddingHelper.cs


示例8: GenerateCode

        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            // We parsed: "@contentType Text.Html"
            // And we assigned this code generator to the "Text.Html" part
            // So this node's content should be "Text.Html"
            string contentType = target.Content;

            // The final code we want is something like
            // Response.ContentType = ContentTypes.Text.Html;

            // So, we start by injecting the "prolog" (this is compiler speak for the stuff before the user code)
            context.BufferStatementFragment("Response.ContentType = ContentTypes.");

            // Now we tell the code generator infrastructure that we're at the start of user code
            // This allows us to inject markers so the editor can light up.
            context.MarkStartOfGeneratedCode();

            // Here's our user code!
            context.BufferStatementFragment(contentType);

            // And we tell Razor we're finished with user code, again for the editor
            context.MarkEndOfGeneratedCode();

            // Finally, we inject the "epilog" (compiler speak for stuff after the user code)
            context.BufferStatementFragment(";");

            // And output the whole statement to the generated Execute method
            context.FlushBufferedStatement();
        }
开发者ID:anurse,项目名称:talks,代码行数:29,代码来源:ContentTypeCodeGenerator.cs


示例9: GenerateCode

        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            // Try to find the namespace in the existing imports
            string ns = Namespace;
            if (!String.IsNullOrEmpty(ns) && Char.IsWhiteSpace(ns[0]))
            {
                ns = ns.Substring(1);
            }

            CodeNamespaceImport import = context.Namespace
                .Imports
                .OfType<CodeNamespaceImport>()
                .Where(i => String.Equals(i.Namespace, ns.Trim(), StringComparison.Ordinal))
                .FirstOrDefault();

            if (import == null)
            {
                // It doesn't exist, create it
                import = new CodeNamespaceImport(ns);
                context.Namespace.Imports.Add(import);
            }

            // Attach our info to the existing/new import.
            import.LinePragma = context.GenerateLinePragma(target);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:25,代码来源:AddImportCodeGenerator.cs


示例10: GenerateCode

        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            context.FlushBufferedStatement();

            string generatedCode = context.BuildCodeString(cw =>
            {
                cw.WriteSnippet(target.Content);
            });

            int startGeneratedCode = target.Start.CharacterIndex;
            generatedCode = Pad(generatedCode, target);

            // Is this the span immediately following "@"?
            if (context.Host.DesignTimeMode &&
                !String.IsNullOrEmpty(generatedCode) &&
                Char.IsWhiteSpace(generatedCode[0]) &&
                target.Previous != null &&
                target.Previous.Kind == SpanKind.Transition &&
                String.Equals(target.Previous.Content, SyntaxConstants.TransitionString))
            {
                generatedCode = generatedCode.Substring(1);
                startGeneratedCode--;
            }

            context.AddStatement(
                generatedCode,
                context.GenerateLinePragma(target, startGeneratedCode));
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:28,代码来源:StatementCodeGenerator.cs


示例11: GenerateCode

        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            base.GenerateCode(target, context);

            context.GeneratedClass.UserData.Add("ModelType", this.modelType);
            context.GeneratedClass.BaseTypes.Clear();
            context.GeneratedClass.BaseTypes.Add(new CodeTypeReference(context.Host.DefaultBaseClass, new CodeTypeReference(this.modelType)));
        }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:8,代码来源:ModelCodeGenerator.cs


示例12: SpanBuilder

 public SpanBuilder(Span original)
 {
     Kind = original.Kind;
     _symbols = new List<ISymbol>(original.Symbols);
     EditHandler = original.EditHandler;
     CodeGenerator = original.CodeGenerator;
     Start = original.Start;
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:8,代码来源:SpanBuilder.cs


示例13: GenerateCode

 public override void GenerateCode(Span target, CodeGeneratorContext context)
 {
     Span sourceSpan = null;
     if (context.CreateCodeWriter().SupportsMidStatementLinePragmas || context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
     {
         sourceSpan = target;
     }
     context.BufferStatementFragment(target.Content, sourceSpan);
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:9,代码来源:ExpressionCodeGenerator.cs


示例14: CalculatePadding

 protected internal static int CalculatePadding(Span target, int generatedStart)
 {
     int padding = target.Start.CharacterIndex - generatedStart;
     if (padding < 0)
     {
         padding = 0;
     }
     return padding;
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:9,代码来源:CodeGeneratorBase.cs


示例15: GenerateCode

 public override void GenerateCode(Span target, CodeGeneratorContext context)
 {
     var attributeType = new CodeTypeReference(typeof(RazorDirectiveAttribute));
     var attributeDeclaration = new CodeAttributeDeclaration(
         attributeType,
         new CodeAttributeArgument(new CodePrimitiveExpression(Name)),
         new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
     context.GeneratedClass.CustomAttributes.Add(attributeDeclaration);
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:9,代码来源:RazorDirectiveAttributeCodeGenerator.cs


示例16: RewriteSpan

		protected override SyntaxTreeNode RewriteSpan (BlockBuilder parent, Span span)
		{
			var b = new SpanBuilder (span);
			var old = (LiteralAttributeCodeGenerator)span.CodeGenerator;
			b.CodeGenerator = old.ValueGenerator != null
				? new PreprocessedLiteralAttributeCodeGenerator (old.Prefix, old.ValueGenerator)
				: new PreprocessedLiteralAttributeCodeGenerator (old.Prefix, old.Value);
			return b.Build ();
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:9,代码来源:PreprocessedAttributeRewriter.cs


示例17: VisitModelNameSpan

		void VisitModelNameSpan(Span span)
		{
			if (span == null)
				return;
			
			string firstLineOfMarkup = GetFirstLine(span.Content);
			ModelTypeName = firstLineOfMarkup.Trim();
			foundModelTypeName = true;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:9,代码来源:RazorCSharpParserModelTypeVisitor.cs


示例18: GenerateCode

 public override void GenerateCode(Span target, CodeGeneratorContext context)
 {
     if (!context.Host.DesignTimeMode && !String.IsNullOrEmpty(context.Host.GeneratedClassContext.LayoutPropertyName))
     {
         context.TargetMethod.Statements.Add(
             new CodeAssignStatement(
                 new CodePropertyReferenceExpression(null, context.Host.GeneratedClassContext.LayoutPropertyName),
                 new CodePrimitiveExpression(LayoutPath)));
     }
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:10,代码来源:SetLayoutCodeGenerator.cs


示例19: VisitSpan

  public override void VisitSpan(Span span)
  {
      if (span.Kind == SpanKind.Markup && !m_DebugStatusReader.IsDebuggingEnabled())
      {
          string content = span.Content;
          span.Content = m_HtmPagelMinifier.Minify(content, true, true);
      }
 
      base.VisitSpan(span);
  }
开发者ID:LaboFoundation,项目名称:Labo.WebSiteOptimizer,代码行数:10,代码来源:HtmlMinifierMvcCSharpRazorCodeGenerator.cs


示例20: CalculatePaddingForEmptySpanReturnsZero

        public void CalculatePaddingForEmptySpanReturnsZero()
        {
            RazorEngineHost host = CreateHost(designTime: true);

            Span span = new Span(new SpanBuilder());

            int padding = CodeGeneratorPaddingHelper.CalculatePadding(host, span, 0);

            Assert.Equal(0, padding);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:10,代码来源:PaddingTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Text.TextChange类代码示例发布时间:2022-05-26
下一篇:
C# SyntaxTree.Block类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap