本文整理汇总了C#中RazorEngineHost类的典型用法代码示例。如果您正苦于以下问题:C# RazorEngineHost类的具体用法?C# RazorEngineHost怎么用?C# RazorEngineHost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RazorEngineHost类属于命名空间,在下文中一共展示了RazorEngineHost类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BackgroundParser
public BackgroundParser(RazorEngineHost host, string fileName)
{
_main = new MainThreadState(fileName);
_bg = new BackgroundThread(_main, host, fileName);
_main.ResultsReady += (sender, args) => OnResultsReady(args);
}
开发者ID:huoxudong125,项目名称:Razor,代码行数:7,代码来源:BackgroundParser.cs
示例2: CodeTreeWithUsings
public void CodeTreeWithUsings()
{
var syntaxTreeNode = new Mock<Span>(new SpanBuilder());
var language = new CSharpRazorCodeLanguage();
var host = new RazorEngineHost(language);
var codeBuilderContext = new CodeBuilderContext(
host,
"TestClass",
"TestNamespace",
"Foo.cs",
shouldGenerateLinePragmas: false,
errorSink: new ParserErrorSink());
codeBuilderContext.CodeTreeBuilder.AddUsingChunk("FakeNamespace1", syntaxTreeNode.Object);
codeBuilderContext.CodeTreeBuilder.AddUsingChunk("FakeNamespace2.SubNamespace", syntaxTreeNode.Object);
var codeBuilder = language.CreateCodeBuilder(codeBuilderContext);
// Act
var result = codeBuilder.Build();
BaselineWriter.WriteBaseline(
@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\CS\Output\CSharpCodeBuilder.cs",
result.Code);
var expectedOutput = TestFile.Create("TestFiles/CodeGenerator/CS/Output/CSharpCodeBuilder.cs").ReadAllText();
// Assert
Assert.Equal(expectedOutput, result.Code);
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:28,代码来源:CSharpCodeBuilderTests.cs
示例3: Create
internal static CodeGeneratorContext Create(RazorEngineHost host, Func<CodeWriter> writerFactory, string className, string rootNamespace, string sourceFile, bool shouldGenerateLinePragmas)
{
CodeGeneratorContext context = new CodeGeneratorContext()
{
Host = host,
CodeWriterFactory = writerFactory,
SourceFile = shouldGenerateLinePragmas ? sourceFile : null,
CompileUnit = new CodeCompileUnit(),
Namespace = new CodeNamespace(rootNamespace),
GeneratedClass = new CodeTypeDeclaration(className)
{
IsClass = true
},
TargetMethod = new CodeMemberMethod()
{
Name = host.GeneratedClassContext.ExecuteMethodName,
Attributes = MemberAttributes.Override | MemberAttributes.Public
},
CodeMappings = new Dictionary<int, GeneratedCodeMapping>()
};
context.CompileUnit.Namespaces.Add(context.Namespace);
context.Namespace.Types.Add(context.GeneratedClass);
context.GeneratedClass.Members.Add(context.TargetMethod);
context.Namespace.Imports.AddRange(host.NamespaceImports
.Select(s => new CodeNamespaceImport(s))
.ToArray());
return context;
}
开发者ID:KennyBu,项目名称:Razor,代码行数:30,代码来源:CodeGeneratorContext.cs
示例4: 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:KennyBu,项目名称:Razor,代码行数:32,代码来源:CodeGeneratorPaddingHelper.cs
示例5: 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:KennyBu,项目名称:Razor,代码行数:35,代码来源:CodeGeneratorPaddingHelper.cs
示例6: RazorChunkGenerator
public RazorChunkGenerator(
string className,
string rootNamespaceName,
string sourceFileName,
RazorEngineHost host)
{
if (rootNamespaceName == null)
{
throw new ArgumentNullException(nameof(rootNamespaceName));
}
if (host == null)
{
throw new ArgumentNullException(nameof(host));
}
if (string.IsNullOrEmpty(className))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, nameof(className));
}
ClassName = className;
RootNamespaceName = rootNamespaceName;
SourceFileName = sourceFileName;
GenerateLinePragmas = string.IsNullOrEmpty(SourceFileName) ? false : true;
Host = host;
}
开发者ID:huoxudong125,项目名称:Razor,代码行数:27,代码来源:RazorChunkGenerator.cs
示例7: ConstructorInitializesHost
public void ConstructorInitializesHost() {
// Arrange
RazorEngineHost host = new RazorEngineHost(new CSharpRazorCodeLanguage());
// Act
RazorTemplateEngine engine = new RazorTemplateEngine(host);
// Assert
Assert.AreSame(host, engine.Host);
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:10,代码来源:RazorTemplateEngineTest.cs
示例8: Create
public static CodeGeneratorContext Create(RazorEngineHost host, string className, string rootNamespace, string sourceFile, bool shouldGenerateLinePragmas)
{
return new CodeGeneratorContext()
{
CodeTreeBuilder = new CodeTreeBuilder(),
Host = host,
SourceFile = shouldGenerateLinePragmas ? sourceFile : null,
RootNamespace = rootNamespace,
ClassName = className
};
}
开发者ID:hamaky,项目名称:Razor,代码行数:11,代码来源:CodeGeneratorContext.cs
示例9: CodeBuilderContext
// Internal for testing.
internal CodeBuilderContext(RazorEngineHost host,
string className,
string rootNamespace,
string sourceFile,
bool shouldGenerateLinePragmas,
ParserErrorSink errorSink)
: base(host, className, rootNamespace, sourceFile, shouldGenerateLinePragmas)
{
ErrorSink = errorSink;
ExpressionRenderingMode = ExpressionRenderingMode.WriteToOutput;
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:12,代码来源:CodeBuilderContext.cs
示例10: ConstructorWithCodeLanguageSetsPropertiesAppropriately
public void ConstructorWithCodeLanguageSetsPropertiesAppropriately() {
// Arrange
RazorCodeLanguage language = new CSharpRazorCodeLanguage();
// Act
RazorEngineHost host = new RazorEngineHost(language);
// Assert
VerifyCommonDefaults(host);
Assert.AreSame(language, host.CodeLanguage);
Assert.IsInstanceOfType(host.CreateMarkupParser(), typeof(HtmlMarkupParser));
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:12,代码来源:RazorEngineHostTest.cs
示例11: CodeGeneratorContext
public CodeGeneratorContext(RazorEngineHost host,
string className,
string rootNamespace,
string sourceFile,
bool shouldGenerateLinePragmas)
{
CodeTreeBuilder = new CodeTreeBuilder();
Host = host;
SourceFile = shouldGenerateLinePragmas ? sourceFile : null;
RootNamespace = rootNamespace;
ClassName = className;
}
开发者ID:billwaddyjr,项目名称:Razor,代码行数:12,代码来源:CodeGeneratorContext.cs
示例12: SetBaseTypeFromHost
private void SetBaseTypeFromHost(RazorEngineHost mvcHost)
{
if (!mvcHost.DefaultBaseTemplateType.IsGenericType)
{
SetBaseType(mvcHost.DefaultBaseTemplateType.FullName);
}
else
{
var modelTypeName = CompilerServicesUtility.ResolveCSharpTypeName(mvcHost.DefaultModelType);
SetBaseType(mvcHost.DefaultBaseClass + "<" + modelTypeName + ">");
}
}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:12,代码来源:CSharpRazorCodeGenerator.cs
示例13: ConstructorWithCodeLanguageSetsPropertiesAppropriately
public void ConstructorWithCodeLanguageSetsPropertiesAppropriately()
{
// Arrange
var language = new CSharpRazorCodeLanguage();
// Act
var host = new RazorEngineHost(language);
// Assert
VerifyCommonDefaults(host);
Assert.Same(language, host.CodeLanguage);
Assert.IsType<HtmlMarkupParser>(host.CreateMarkupParser());
}
开发者ID:x-strong,项目名称:Razor,代码行数:13,代码来源:RazorEngineHostTest.cs
示例14: ConstructorWithCodeLanguageAndMarkupParserSetsPropertiesAppropriately
public void ConstructorWithCodeLanguageAndMarkupParserSetsPropertiesAppropriately() {
// Arrange
RazorCodeLanguage language = new CSharpRazorCodeLanguage();
MarkupParser expected = new HtmlMarkupParser();
// Act
RazorEngineHost host = new RazorEngineHost(language, () => expected);
// Assert
VerifyCommonDefaults(host);
Assert.AreSame(language, host.CodeLanguage);
Assert.AreSame(expected, host.CreateMarkupParser());
}
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:13,代码来源:RazorEngineHostTest.cs
示例15: PaddingCharCount
// there is some duplicity of code here, but its very simple and since this is a host path, I'd rather not create another class to encapsulate the data.
public static int PaddingCharCount(RazorEngineHost host, Span target, int generatedStart)
{
int padding = CalculatePadding(host, target, generatedStart);
if (host.DesignTimeMode && host.IsIndentingWithTabs)
{
int spaces;
int tabs = Math.DivRem(padding, host.TabSize, out spaces);
return tabs + spaces;
}
else
{
return padding;
}
}
开发者ID:KennyBu,项目名称:Razor,代码行数:17,代码来源:CodeGeneratorPaddingHelper.cs
示例16: CreateCodeGeneratorParserListenerReturnsNewCSharpCodeGeneratorParserListener
public void CreateCodeGeneratorParserListenerReturnsNewCSharpCodeGeneratorParserListener() {
// Arrange
RazorCodeLanguage service = new CSharpRazorCodeLanguage();
// Act
RazorEngineHost host = new RazorEngineHost(service);
RazorCodeGenerator generator = service.CreateCodeGenerator("Foo", "Bar", "Baz", host);
// Assert
Assert.IsNotNull(generator);
Assert.IsInstanceOfType(generator, typeof(CSharpRazorCodeGenerator));
Assert.AreEqual("Foo", generator.ClassName);
Assert.AreEqual("Bar", generator.RootNamespaceName);
Assert.AreEqual("Baz", generator.SourceFileName);
Assert.AreSame(host, generator.Host);
}
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:16,代码来源:CSharpRazorCodeLanguageTest.cs
示例17: CreateCodeBuilder_ReturnsNewCSharpCodeBuilder
public void CreateCodeBuilder_ReturnsNewCSharpCodeBuilder()
{
// Arrange
var language = new CSharpRazorCodeLanguage();
var host = new RazorEngineHost(language);
var context = CodeGeneratorContext.Create(host,
"myclass",
"myns",
string.Empty,
shouldGenerateLinePragmas: false);
// Act
var generator = language.CreateCodeBuilder(context);
// Assert
Assert.IsType<CSharpCodeBuilder>(generator);
}
开发者ID:hamaky,项目名称:Razor,代码行数:17,代码来源:CSharpRazorCodeLanguageTest.cs
示例18: RazorCodeGenerator
protected RazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host)
{
if (String.IsNullOrEmpty(className))
{
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "className");
}
if (rootNamespaceName == null)
{
throw new ArgumentNullException("rootNamespaceName");
}
if (host == null)
{
throw new ArgumentNullException("host");
}
ClassName = className;
RootNamespaceName = rootNamespaceName;
SourceFileName = sourceFileName;
GenerateLinePragmas = String.IsNullOrEmpty(SourceFileName) ? false : true;
Host = host;
}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:21,代码来源:RazorCodeGenerator.cs
示例19: Create
internal static CodeGeneratorContext Create(RazorEngineHost host, Func<CodeWriter> writerFactory, string className, string rootNamespace, string sourceFile, bool shouldGenerateLinePragmas)
{
CodeGeneratorContext context = new CodeGeneratorContext()
{
Host = host,
CodeWriterFactory = writerFactory,
SourceFile = shouldGenerateLinePragmas ? sourceFile : null,
CompileUnit = new CodeCompileUnit(),
Namespace = new CodeNamespace(rootNamespace),
GeneratedClass = new CodeTypeDeclaration(className)
{
IsClass = true
},
TargetMethod = new CodeMemberMethod()
{
Name = host.GeneratedClassContext.ExecuteMethodName,
Attributes = MemberAttributes.Override | MemberAttributes.Public
},
CodeMappings = new Dictionary<int, GeneratedCodeMapping>()
};
var entryPoint = context.TargetMethod;
if (entryPoint.Name.EndsWith("Async", StringComparison.Ordinal)
&& entryPoint.ReturnType.BaseType == "System.Void"
&& host.NamespaceImports.Contains("System.Threading.Tasks"))
{
entryPoint.ReturnType = new CodeTypeReference("async global::System.Threading.Tasks.Task");
}
context.CompileUnit.Namespaces.Add(context.Namespace);
context.Namespace.Types.Add(context.GeneratedClass);
context.GeneratedClass.Members.Add(context.TargetMethod);
context.Namespace.Imports.AddRange(host.NamespaceImports
.Select(s => new CodeNamespaceImport(s))
.ToArray());
return context;
}
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:38,代码来源:CodeGeneratorContext.cs
示例20: CreateHost
/// <summary>
/// Creates a <see cref="RazorEngineHost"/> used for class generation.
/// </summary>
/// <param name="templateType">The template base type.</param>
/// <param name="modelType">The model type.</param>
/// <param name="className">The class name.</param>
/// <returns>An instance of <see cref="RazorEngineHost"/>.</returns>
private RazorEngineHost CreateHost(Type templateType, Type modelType, string className)
{
var host = new RazorEngineHost(CodeLanguage, MarkupParserFactory)
{
DefaultBaseTemplateType = templateType,
DefaultBaseClass = BuildTypeName(templateType, modelType),
DefaultClassName = className,
DefaultNamespace = "CompiledRazorTemplates.Dynamic",
GeneratedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral",
"WriteTo", "WriteLiteralTo",
"RazorEngine.Templating.TemplateWriter",
"DefineSection")
};
return host;
}
开发者ID:MikkoCodes,项目名称:RazorEngine,代码行数:23,代码来源:CompilerServiceBase.cs
注:本文中的RazorEngineHost类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论