我正在创建一个需要打印HTML字符串和HTML文档的打印机类。所以基本上可以得到:发送HTML参数和文件路径参数?
Printer.Print("<b>Hello world</b>");
而且
Printer.Print(@"C:\hello.html");
设计我的课,我下面之间作出决定的打印方法定义
所以:
public static void Print(string inputString, string mode){
if(mode=="htmlString"){//Print the string itself}
else if(mode=="htmlFile"){//Print the document in the filepath}
}
或者
public static void Print(string inputString){
if(file.Exists(inputString)){//Print the document in the filepath}
else{//Print the string itself}
}
一般来说,这是t他更好的练习?第一个选项需要另一个不太好的参数,但如果我们使用第二个选项,如果打算实际打印文件但使用不正确的文件名,则会打印错误的内容。
建筑外墙的用户可以关注一下聪明,但它可以变得非常混乱构建做几不同的事情的方法,而他们的名字都不告诉你关于他们做什么的一切。在这种情况下,打印一个简单的字符串并打开和关闭一个文件会有很大的差异(和影响)。首先,包含文件名纯文本的HTML如何?在你的示例中,我不能打印一个简单的filePath作为字符串。 – 2011-02-10 18:36:29
好点,我从这个角度没有想到太多。 – sooprise 2011-02-10 18:38:09