我正在創建一個需要打印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