protected override void Visit(ViewDataChunk chunk) { string key = chunk.Key; Snippets name = chunk.Name; Snippets snippets2 = chunk.Type ?? "object"; if (!this._globalSymbols.ContainsKey((string)name)) { this._globalSymbols.Add((string)name, null); } if (this._viewDataAdded.ContainsKey((string)name)) { if (this._viewDataAdded[(string)name] != (key + ":" + ((string)snippets2))) { throw new CompilerException(string.Format("The view data named {0} cannot be declared with different types '{1}' and '{2}'", name, snippets2, this._viewDataAdded[(string)name])); } } else { this._viewDataAdded.Add((string)name, key + ":" + ((string)snippets2)); this._source.Write("Public ReadOnly Property ").WriteCode(name).Write("() As ").WriteCode(snippets2).WriteLine().AddIndent().WriteLine("Get").AddIndent(); if (Snippets.IsNullOrEmpty(chunk.Default)) { this.CodeIndent(chunk).Write("Return CType(ViewData.Eval(\"").Write(key).Write("\"),").WriteCode(snippets2).WriteLine(")"); } else { this.CodeIndent(chunk).Write("Return CType(If(ViewData.Eval(\"").Write(key).Write("\"),").WriteCode(chunk.Default).Write("),").WriteCode(snippets2).WriteLine(")"); } this._source.RemoveIndent().WriteLine("End Get").RemoveIndent().WriteLine("End Property"); this.CodeDefault(); } }
private void VisitViewdata(SpecialNodeInspector inspector) { AttributeNode attr = inspector.TakeAttribute("default"); Snippets snippets = null; if (attr != null) { snippets = this.AsTextOrientedCode(attr); } AttributeNode node2 = inspector.TakeAttribute("model"); if (node2 != null) { TypeInspector inspector2 = new TypeInspector(this.AsCode(node2)); ViewDataModelChunk chunk = new ViewDataModelChunk { TModel = inspector2.Type, TModelAlias = inspector2.Name }; this.AddUnordered(chunk); } foreach (AttributeNode node3 in inspector.Attributes) { TypeInspector inspector3 = new TypeInspector(this.AsCode(node3)); ViewDataChunk chunk2 = new ViewDataChunk { Type = inspector3.Type, Name = inspector3.Name ?? node3.Name, Key = node3.Name, Default = snippets, Position = this.Locate(node3) }; this.AddUnordered(chunk2); } }
protected override void Visit(ViewDataChunk chunk) { var key = chunk.Key; var name = chunk.Name; var type = chunk.Type ?? "object"; if (!_globalSymbols.ContainsKey(name)) { _globalSymbols.Add(name, null); } if (_viewDataAdded.ContainsKey(name)) { if (_viewDataAdded[name] != key + ":" + type) { throw new CompilerException( string.Format("The view data named {0} cannot be declared with different types '{1}' and '{2}'", name, type, _viewDataAdded[name])); } return; } _viewDataAdded.Add(name, key + ":" + type); //_source.WriteCode(type).Write(" ").WriteLine(name); _source .Write("Public ReadOnly Property ") .WriteCode(name) .Write("() As ") .WriteCode(type) .WriteLine().AddIndent() .WriteLine("Get").AddIndent(); if (Snippets.IsNullOrEmpty(chunk.Default)) { CodeIndent(chunk) .Write("Return CType(ViewData.Eval(\"") .Write(key) .Write("\"),") .WriteCode(type) .WriteLine(")"); } else { CodeIndent(chunk) .Write("Return CType(If(ViewData.Eval(\"") .Write(key) .Write("\"),") .WriteCode(chunk.Default) .Write("),") .WriteCode(type) .WriteLine(")"); } _source .RemoveIndent().WriteLine("End Get") .RemoveIndent().WriteLine("End Property"); CodeDefault(); }
protected override void Visit(ViewDataChunk chunk) { _source .Append("var ") .Append(chunk.Name) .Append(" = viewData[\"") .Append(chunk.Key) .AppendLine("\"];"); }
protected abstract void Visit(ViewDataChunk chunk);
protected override void Visit(ViewDataChunk chunk) { }
protected override void Visit(ViewDataChunk chunk) { var key = chunk.Key; var name = chunk.Name; var type = chunk.Type ?? "object"; if (!_globalSymbols.ContainsKey(name)) _globalSymbols.Add(name, null); if (_viewDataAdded.ContainsKey(name)) { if (_viewDataAdded[name] != key + ":" + type) { throw new CompilerException( string.Format("The view data named {0} cannot be declared with different types '{1}' and '{2}'", name, type, _viewDataAdded[name])); } return; } _viewDataAdded.Add(name, key + ":" + type); _source.WriteCode(type).Write(" ").WriteLine(name); if (Snippets.IsNullOrEmpty(chunk.Default)) { CodeIndent(chunk) .Write("{get {return (") .WriteCode(type) .Write(")ViewData.Eval(\"") .Write(key) .WriteLine("\");}}"); } else { CodeIndent(chunk) .Write("{get {return (") .WriteCode(type) .Write(")(ViewData.Eval(\"") .Write(key) .Write("\")??") .WriteCode(chunk.Default) .WriteLine(");}}"); } CodeDefault(); }