【问题标题】:The name 'process' does not exist in current context当前上下文中不存在名称“进程”
【发布时间】:2019-10-08 23:59:38
【问题描述】:

我正在浏览 iText7 快速启动示例,如 here 所示。在“发布数据库”部分。我创建了一个基本的 .Net 控制台应用程序并复制并粘贴了代码。我在行process(table, line, bold, true);process(table, line, font, false); 上不断收到“当前上下文中不存在命名空间'进程'”错误

我看到一个关于 PDFsharp here 的类似问题,它说要使用 System.Diagnostics.Process.Start,但这似乎不能解决我的问题。

var writer = new PdfWriter(dest);
var pdf = new PdfDocument(writer);
var document = new Document(pdf, PageSize.A4.Rotate());
document.SetMargins(20, 20, 20, 20);
var font = PdfFontFactory.CreateFont(FontConstants.HELVETICA);
var bold = PdfFontFactory.CreateFont(FontConstants.HELVETICA_BOLD);
var table = new Table(new float[] { 4, 1, 3, 4, 3, 3, 3, 3, 1 });
table.SetWidth(UnitValue.CreatePercentValue(100));
StreamReader sr = File.OpenText(DATA);
var line = sr.ReadLine();
process(table, line, bold, true);
while ((line = sr.ReadLine()) != null)
{
  process(table, line, font, false);
}
sr.Close();
document.Add(table);
document.Close();

删除“当前上下文中不存在命名空间'进程'”错误的正确方法是什么?

【问题讨论】:

  • 就在您复制粘贴的代码下方,有另一个代码用于process(...) 函数
  • 我投票决定将此问题作为离题结束,因为向下滚动您从中获取此代码的页面会显示 process 方法的实现。
  • 请注意,此类教程有时可能会先显示一个代码块,然后再显示相关的代码块。请注意,因为它没有引用静态类(例如Process.DoSomething(...))或定义的变量(例如myProcessInstance.DoSomething(...)),所以很明显该方法与您显示的方法在同一个类中定义。因此,这是您必须实施的一种方法——本文继续这样做。
  • 您应该在流程实现中添加“静态”并遵循命名约定,这让我很反感。但是,是的,这个问题应该被关闭
  • 鉴于提供的代码,您可能需要添加static 的唯一原因是调用方法是否也是static

标签: c# itext7


【解决方案1】:

您应该阅读本文的其余部分。实现比较低。

【讨论】:

    猜你喜欢
    • 2015-08-30
    • 2013-10-02
    • 2014-04-22
    • 2017-06-17
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    相关资源
    最近更新 更多