streamwrite覆盖不仅仅是“写”功能

时间:2016-01-22 19:26:58

标签: c# console override

这是我目前编写的文本编写器代码:

>>> import requests
>>> r = requests.get("http://108.168.175.149:10128/status-json.xsl")
>>> r.text
u'Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\nCache-Control: no-store, no-cache, must-revalidate\r\nPragma: no-cache\r\nAccess-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type\r\nAccess-Control-Allow-Methods: GET, OPTIONS, HEAD\r\n\r\n{"icestats":{"admin":"icemaster@localhost","banned_IPs":0,"build":20141112090605,"host":"pro02.caster.fm","location":"Earth","outgoing_kbitrate":3844,"server_id":"Icecast 2.3.3-kh11","server_start":"05/Oct/2015:10:43:46 -0500","stream_kbytes_read":104438630,"stream_kbytes_sent":5124109510,"source":[{"audio_codecid":2,"audio_info":"ice-samplerate=44100;ice-bitrate=96;ice-channels=2","bitrate":96,"connected":35133,"genre":"Various","ice-bitrate":96,"ice-channels":2,"ice-samplerate":44100,"incoming_bitrate":95920,"listener_peak":153,"listeners":43,"listenurl":"http://pro02.caster.fm:10128/live","mpeg_channels":2,"mpeg_samplerate":44100,"outgoing_kbitrate":3837,"queue_size":164258,"se'
>>>

正如您所看到的,它可以覆盖Write函数,但我希望能够覆盖从Clear到color设置的所有内容。我尝试添加一个Clear覆盖,但它说没有什么可以覆盖。

如何在System.Console中覆盖我需要的所有功能?

2 个答案:

答案 0 :(得分:0)

仅仅因为TextWriter不包含清除或颜色设置功能 检查msdn
尝试创建一个新方法而不覆盖:

lock

答案 1 :(得分:0)

如果您尝试编辑文本框内容,请尝试使用此代码

myDF.as[(String, Int)].rdd

并创建班级的新实例

using System;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace ConsoleRedirection
{
    public class TextBoxStreamWriter
    {
        TextBox _output = null;

        public TextBoxStreamWriter(ref TextBox output)
        {
            _output = output;
        }

        public void Write(char value)
        {
            _output.AppendText(value.ToString());
        }
        public void Write(string value)
        {
            _output.AppendText(value);
        }
        public Encoding Encoding
        {
            get { return Encoding.UTF8; }
        }

        public void clear()
        {
            _output.Clear();
        }

        public void textColor(System.Drawing.Color color)
        {
            _output.ForeColor = color;
        }
    }
}