本文整理汇总了C#中Spark.Parser.Markup.SpecialNode类的典型用法代码示例。如果您正苦于以下问题:C# SpecialNode类的具体用法?C# SpecialNode怎么用?C# SpecialNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpecialNode类属于Spark.Parser.Markup命名空间,在下文中一共展示了SpecialNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetKnownAttributesForSpecialNode
private List<string> GetKnownAttributesForSpecialNode(SpecialNode node)
{
var allKnown = new Dictionary<string, List<string>>
{
{"var", new List<string>{"type"}},
{"def", new List<string>{"type"}},
{"default", new List<string>{"type"}},
{"global", new List<string>{"type"}},
{"viewdata", new List<string>{"default","model"}},
{"set", new List<string>()},
{"for", new List<string>{"each"}},
{"test", new List<string>{"condition", "if", "once"}},
{"if", new List<string>{"condition", "once"}},
{"else", new List<string>{"if"}},
{"elseif", new List<string>{"condition"}},
{"content", new List<string>{"add","def", "name", "set", "var"}},
{"use", new List<string>{"assembly", "content", "file", "import", "master", "namespace", "pageBaseType" }},
{"macro", new List<string>{"name"}},
{"render", new List<string>{"partial", "section"}},
{"section", new List<string>{"name"}},
{"cache", new List<string>{"expires", "key", "signal"}}
};
List<string> knownAttributes;
return allKnown.TryGetValue(node.Element.Name, out knownAttributes)
? knownAttributes
: new List<string>();
}
示例2: VisitGlobal
private void VisitGlobal(SpecialNode specialNode)
{
var typeAttr = specialNode.Element.Attributes.FirstOrDefault(attr => attr.Name == "type");
var type = typeAttr != null ? AsCode(typeAttr) : (Snippets)"object";
foreach (var attr in specialNode.Element.Attributes.Where(a => a != typeAttr))
{
AddUnordered(new GlobalVariableChunk { Type = type, Name = attr.Name, Value = AsCode(attr) });
}
}
示例3: VisitFor
private void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
{
var eachAttr = inspector.TakeAttribute("each");
var forEachChunk = new ForEachChunk { Code = AsCode(eachAttr), Position = Locate(specialNode.Element) };
Chunks.Add(forEachChunk);
using (new Frame(this, forEachChunk.Body))
{
foreach (var attr in inspector.Attributes)
{
Chunks.Add(new AssignVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
}
Accept(specialNode.Body);
}
}
示例4: VisitElseIf
private void VisitElseIf(SpecialNode specialNode, SpecialNodeInspector inspector)
{
if (!SatisfyElsePrecondition())
throw new CompilerException("An 'elseif' may only follow an 'if' or 'elseif'.");
var conditionAttr = inspector.TakeAttribute("condition");
var elseIfChunk = new ConditionalChunk { Type = ConditionalType.ElseIf, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
Chunks.Add(elseIfChunk);
using (new Frame(this, elseIfChunk.Body))
Accept(specialNode.Body);
}
示例5: VisitCache
private void VisitCache(SpecialNode specialNode, SpecialNodeInspector inspector)
{
var keyAttr = inspector.TakeAttribute("key");
var expiresAttr = inspector.TakeAttribute("expires");
var signalAttr = inspector.TakeAttribute("signal");
var chunk = new CacheChunk { Position = Locate(specialNode.Element) };
if (keyAttr != null)
chunk.Key = AsCode(keyAttr);
else
chunk.Key = "\"\"";
if (expiresAttr != null)
chunk.Expires = AsCode(expiresAttr);
else
chunk.Expires = "";
if (signalAttr != null)
chunk.Signal = AsCode(signalAttr);
else
chunk.Signal = "";
Chunks.Add(chunk);
using (new Frame(this, chunk.Body))
Accept(inspector.Body);
}
示例6: Visit
protected override void Visit(SpecialNode specialNode)
{
Add(specialNode);
}
示例7: VisitUse
private void VisitUse(SpecialNode specialNode, SpecialNodeInspector inspector)
{
var file = inspector.TakeAttribute("file");
if (file != null)
{
var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
Chunks.Add(scope);
using (new Frame(this, scope.Body))
{
foreach (var attr in inspector.Attributes)
{
Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
}
var useFileChunk = new RenderPartialChunk { Name = file.Value, Position = Locate(inspector.OriginalNode) };
Chunks.Add(useFileChunk);
using (new Frame(this, useFileChunk.Body, useFileChunk.Sections))
{
Accept(inspector.Body);
}
}
}
else
{
var contentAttr = inspector.TakeAttribute("content");
var namespaceAttr = inspector.TakeAttribute("namespace");
var assemblyAttr = inspector.TakeAttribute("assembly");
var importAttr = inspector.TakeAttribute("import");
var masterAttr = inspector.TakeAttribute("master");
var pageBaseTypeAttr = inspector.TakeAttribute("pageBaseType");
if (contentAttr != null)
{
var useContentChunk = new UseContentChunk { Name = contentAttr.Value, Position = Locate(inspector.OriginalNode) };
Chunks.Add(useContentChunk);
using (new Frame(this, useContentChunk.Default))
{
Accept(specialNode.Body);
}
}
else if (namespaceAttr != null || assemblyAttr != null)
{
if (namespaceAttr != null)
{
var useNamespaceChunk = new UseNamespaceChunk { Namespace = AsCode(namespaceAttr) };
AddUnordered(useNamespaceChunk);
}
if (assemblyAttr != null)
{
var useAssemblyChunk = new UseAssemblyChunk { Assembly = assemblyAttr.Value };
AddUnordered(useAssemblyChunk);
}
}
else if (importAttr != null)
{
var useImportChunk = new UseImportChunk { Name = importAttr.Value };
AddUnordered(useImportChunk);
}
else if (masterAttr != null)
{
var useMasterChunk = new UseMasterChunk { Name = masterAttr.Value };
AddUnordered(useMasterChunk);
}
else if (pageBaseTypeAttr != null)
{
var usePageBaseTypeChunk = new PageBaseTypeChunk { BaseClass = AsCode(pageBaseTypeAttr) };
AddUnordered(usePageBaseTypeChunk);
}
else
{
throw new CompilerException("Special node use had no understandable attributes");
}
}
}
示例8: VisitRender
private void VisitRender(SpecialNode node, SpecialNodeInspector inspector)
{
var partial = inspector.TakeAttribute("partial");
if (partial != null)
{
var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
Chunks.Add(scope);
using (new Frame(this, scope.Body))
{
foreach (var attr in inspector.Attributes)
{
Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
}
var renderPartial = new RenderPartialChunk { Name = partial.Value, Position = Locate(inspector.OriginalNode) };
Chunks.Add(renderPartial);
using (new Frame(this, renderPartial.Body, renderPartial.Sections))
{
Accept(inspector.Body);
}
}
}
else
{
var sectionAttr = inspector.TakeAttribute("section");
string sectionName = null;
if (sectionAttr != null)
sectionName = sectionAttr.Value;
var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
Chunks.Add(scope);
using (new Frame(this, scope.Body))
{
foreach (var attr in inspector.Attributes)
{
Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
}
var render = new RenderSectionChunk { Name = sectionName };
Chunks.Add(render);
using (new Frame(this, render.Default))
{
Accept(inspector.Body);
}
}
}
}
示例9: Visit
protected abstract void Visit(SpecialNode specialNode);
示例10: Visit
protected override void Visit(SpecialNode node)
{
bool detachFromParent = false;
if (NameUtility.IsMatch("else", Context.Namespaces, node.Element.Name, node.Element.Namespace) &&
node.Element.IsEmptyElement &&
_frame.TestParentNodes != null)
{
detachFromParent = true;
}
if (detachFromParent)
{
var reconstructed = new SpecialNode(node.Element);
_frame.TestParentNodes.Add(reconstructed);
_frame.Nodes = reconstructed.Body;
}
else
{
var reconstructed = new SpecialNode(node.Element);
Nodes.Add(reconstructed);
var parentNodes = _frame.Nodes;
PushFrame();
_frame.Nodes = reconstructed.Body;
if (NameUtility.IsMatch("if", Context.Namespaces, node.Element.Name, node.Element.Namespace) ||
NameUtility.IsMatch("test", Context.Namespaces, node.Element.Name, node.Element.Namespace))
{
_frame.TestParentNodes = parentNodes;
}
Accept(node.Body);
PopFrame();
}
}
示例11: SpecialNodeInspector
public SpecialNodeInspector(SpecialNode node)
{
_node = node;
Attributes = new List<AttributeNode>(node.Element.Attributes);
}
示例12: VisitIgnore
private void VisitIgnore(SpecialNode specialNode, SpecialNodeInspector inspector)
{
Accept(specialNode.Body);
}
示例13: PushSpecial
private void PushSpecial(ElementNode element)
{
SpecialNode special = new SpecialNode(element) { OriginalNode = element };
Nodes.Add(special);
_stack.Push(Nodes);
_nodes = special.Body;
}
示例14: Visit
protected override void Visit(SpecialNode specialNode)
{
throw new System.NotImplementedException();
}
示例15: VisitIf
private void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
{
var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("if");
var onceAttr = inspector.TakeAttribute("once");
if (conditionAttr == null && onceAttr == null)
{
throw new CompilerException("Element must contain an if, condition, or once attribute");
}
Frame ifFrame = null;
if (conditionAttr != null)
{
var ifChunk = new ConditionalChunk { Type = ConditionalType.If, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
Chunks.Add(ifChunk);
ifFrame = new Frame(this, ifChunk.Body);
}
Frame onceFrame = null;
if (onceAttr != null)
{
var onceChunk = new ConditionalChunk { Type = ConditionalType.Once, Condition = onceAttr.AsCodeInverted(), Position = Locate(inspector.OriginalNode) };
Chunks.Add(onceChunk);
onceFrame = new Frame(this, onceChunk.Body);
}
Accept(specialNode.Body);
if (onceFrame != null)
onceFrame.Dispose();
if (ifFrame != null)
ifFrame.Dispose();
}