示例#1
0
        private string ReadFile(IncludeDirective include)
        {
            string   OFilename = Path.Combine(new FileInfo(FFilename).DirectoryName, include.File);
            FileInfo OFile     = new FileInfo(OFilename);

            if (OFile.Exists)
            {
                using (FileStream OStream = new FileStream(OFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    using (StreamReader OReader = new StreamReader(OStream, Encoding.UTF8)) {
                        return(OReader.ReadToEnd());
                    }
                }
            }
            else
            {
                throw new IOException("File not found - include: '" + include.File + "'");
            }
        }
示例#2
0
 private void HandleCodeTagEnd()
 {
     if (FCurrentBlockType == BlockType.OutputStart)
     {
         WriteLine(Builder, "Write(@\"" + EscapeString(FData.Substring(FTextStart, FTextEnd - FTextStart)) + "\");", true);
         WriteLine(Builder, "Write(" + FData.Substring(FStart, i - FStart - 1).Trim() + ");", true);
         FTextStart     = i + 1;
         FLastBlockType = BlockType.OutputEnd;
     }
     else if (FCurrentBlockType == BlockType.StatementStart)
     {
         string OText = FData.Substring(FTextStart, FTextEnd - FTextStart);
         if (!FOptions.RemoveWhitespaceStatementLines || OText.Trim() != "")
         {
             WriteLine(Builder, "Write(@\"" + EscapeString(OText) + "\");", true);
         }
         WriteLine(Builder, FData.Substring(FStart, i - FStart - 1).Trim(), true);
         FTextStart     = i + 1;
         FLastBlockType = BlockType.StatementEnd;
     }
     else if (FCurrentBlockType == BlockType.DirectiveStart)
     {
         string OTagContent = FData.Substring(FStart, i - FStart - 1).Trim();
         if (OTagContent.StartsWith("template", StringComparison.OrdinalIgnoreCase))
         {
             TemplateDirective ODirective = new TemplateDirective(OTagContent);
             FDebug       = ODirective.Debug;
             FLinePragmas = ODirective.LinePragmas;
         }
         if (OTagContent.StartsWithIC("import"))
         {
             ImportDirective ODirective = new ImportDirective(OTagContent);
             FUsings.Add(ODirective.Namespace);
         }
         if (OTagContent.StartsWithIC("include"))
         {
             IncludeDirective ODirective   = new IncludeDirective(OTagContent);
             string           OFileContent = ReadFile(ODirective);
             FData = FData.Insert(i + 1, OFileContent);
         }
         if (OTagContent.StartsWithIC("assembly"))
         {
             AssemblyDirective ODirective = new AssemblyDirective(this, OTagContent);
             FImports.Add(ODirective.FullName);
         }
         if (OTagContent.StartsWithIC("output"))
         {
             OutputDirective ODirective = new OutputDirective(OTagContent);
             FEncoding  = ODirective.Encoding ?? FEncoding;
             FExtension = ODirective.Extension ?? FExtension;
         }
         if (OTagContent.StartsWithIC("parameter"))
         {
             ParameterDirective ODirective = new ParameterDirective(OTagContent);
             FParameterDirectives.Add(ODirective);
             WriteLine(FTemplateMethods, "\r\npublic " + ODirective.Type + " " + ODirective.Name + " { get; set; }", true);
         }
         FTextStart     = i + 1;
         FLastBlockType = BlockType.DirectiveEnd;
     }
     else if (FCurrentBlockType == BlockType.ClassFeatureStart)
     {
         WriteLine(Builder, FData.Substring(FTextStart, FTextEnd - FTextStart), true);
         WriteLine(Builder, FData.Substring(FStart, i - FStart - 1), true);
         FTextStart     = i + 1;
         FLastBlockType = BlockType.ClassFeatureEnd;
     }
     FCurrentBlockType = BlockType.Text;
 }