예제 #1
0
        protected override void Visit(SendExpressionChunk chunk)
        {
            var automaticallyEncode = chunk.AutomaticallyEncode;

            if (chunk.Code.ToString().StartsWith("H("))
            {
                automaticallyEncode = false;
            }

            _source.WriteLine("Try").AddIndent();
            CodeIndent(chunk)
            .Write("Output.Write(")
            .Write(automaticallyEncode ? "H(" : "")
            .WriteCode(chunk.Code)
            .Write(automaticallyEncode ? ")" : "")
            .WriteLine(")")
            .RemoveIndent();
            CodeDefault();

            if (_nullBehaviour == NullBehaviour.Lenient)
            {
                _source.WriteLine("Catch ex As Global.System.NullReferenceException");
                if (!chunk.SilentNulls)
                {
                    _source
                    .AddIndent()
                    .Write("Output.Write(\"${")
                    .Write(EscapeStringContents(chunk.Code))
                    .WriteLine("}\")")
                    .RemoveIndent();
                }
                _source.WriteLine("End Try");
            }
            else
            {
                _source.WriteLine("Catch ex As Global.System.NullReferenceException");
                _source
                .AddIndent()
                .Write("Throw New Global.System.ArgumentNullException(\"${")
                .Write(EscapeStringContents(chunk.Code))
                .WriteLine("}\", ex)")
                .RemoveIndent();
                _source.WriteLine("End Try");
            }
        }