开发者

Take in variable, instead of direct file path?

I'm not sure how to ask this question actually...开发者_JAVA技巧

REF: http://qif.codeplex.com/

This API takes in the path of a file, can I have it take in a variable instead? binary of the file or string content of the file?


Not directly, but there is an overload of ImportFile that takes a StreamReader, so you can do something like that:

  • If you have the content as a byte array:

    byte[] contentBytes = ...
    QifDom qifDom;
    using (Stream stream = new MemoryStream(contentBytes))
    using (StreamReader reader = new StreamReader(stream))
    {
        qifDom = QifDom.ImportFile();
    }
    
  • If you have the content as a string:

    string content = ...
    byte[] contentBytes = Encoding.UTF8.GetBytes(content);
    QifDom qifDom;
    using (Stream stream = new MemoryStream(contentBytes))
    using (StreamReader reader = new StreamReader(stream))
    {
        qifDom = QifDom.ImportFile();
    }
    

(Bad API design, by the way... the parameter should have been TextReader, not StreamReader, so we could have used a StringReader rather than converting the string to bytes)

Also, note that the example on the home page is incorrect (there is no QifDom.Import property)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜