从StreamWriter的继承与最小可能的努力 [英] Inheriting from StreamWriter with smallest possible effort
本文介绍了从StreamWriter的继承与最小可能的努力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是外部库,它允许使用StreamWriter的记录 - 现在我想基于日志的内容添加一些处理。因为我想,以避免通过日志文件的循环,我想编写从StreamWriter的继承的类。结果
什么是从StreamWriter的继承与方法/构造函数尽可能少的重新实现的最佳途径?
I am using an external library which allows logging using StreamWriter - now I want to add some handling based on the content of the logging. As I want to avoid to loop through the log file, I would like to write a class which inherits from StreamWriter.
What is the best way to inherit from StreamWriter with as few re-implementations of methods/constructors?
推荐答案
我不知道你想做什么,但如果你只是想检查正在写了什么在流,你可以这样做:
I'm not sure of what you want to do exactly, but if you only want to inspect what is being written in the stream, you can do this:
public class CustomStreamWriter : StreamWriter
{
public CustomStreamWriter(Stream stream)
: base(stream)
{}
public override void Write(string value)
{
//Inspect the value and do something
base.Write(value);
}
}
这篇关于从StreamWriter的继承与最小可能的努力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文