覆盖“公共”继承的成员时更改访问修饰符

时间:2018-08-30 09:47:08

标签: c# unity3d

我有两个脚本,即HTTPReponse.cs和HTTPProxyReponse.cs,它们是继承到HTTPResponse.cs的。

HTTPResponse.cs

public virtual bool Receive(int forceReadRawContentLength = -1, bool readPayloadData = true)
    {
        string statusLine = string.Empty;

        if (HTTPManager.Logger.Level == Logger.Loglevels.All)
            VerboseLogging(string.Format("Receive. forceReadRawContentLength: '{0:N0}', readPayloadData: '{1:N0}'", forceReadRawContentLength, readPayloadData));

        // On WP platform we aren't able to determined sure enough whether the tcp connection is closed or not.
        //  So if we get an exception here, we need to recreate the connection.
        try
        {
            // Read out 'HTTP/1.1' from the "HTTP/1.1 {StatusCode} {Message}"
            statusLine = ReadTo(Stream, (byte)' ');
        }
        catch
        {
            if (!baseRequest.DisableRetry)
            {
                HTTPManager.Logger.Warning("HTTPResponse", string.Format("{0} - Failed to read Status Line! Retry is enabled, returning with false.", this.baseRequest.CurrentUri.ToString()));
                return false;
            }

            HTTPManager.Logger.Warning("HTTPResponse", string.Format("{0} - Failed to read Status Line! Retry is disabled, re-throwing exception.", this.baseRequest.CurrentUri.ToString()));
            throw;
        }

        if (HTTPManager.Logger.Level == Logger.Loglevels.All)
            VerboseLogging(string.Format("Status Line: '{0}'", statusLine));

        if (string.IsNullOrEmpty(statusLine))
        {
            if (!baseRequest.DisableRetry)
                return false;

            throw new Exception("Remote server closed the connection before sending response header!");
        }

        string[] versions = statusLine.Split(new char[] { '/', '.' });
        this.VersionMajor = int.Parse(versions[1]);
        this.VersionMinor = int.Parse(versions[2]);

        if (HTTPManager.Logger.Level == Logger.Loglevels.All)
            VerboseLogging(string.Format("HTTP Version: '{0}.{1}'", this.VersionMajor.ToString(), this.VersionMinor.ToString()));

        int statusCode;
        string statusCodeStr = NoTrimReadTo(Stream, (byte)' ', LF);

        if (HTTPManager.Logger.Level == Logger.Loglevels.All)
            VerboseLogging(string.Format("Status Code: '{0}'", statusCodeStr));

        if (baseRequest.DisableRetry)
            statusCode = int.Parse(statusCodeStr);
        else if (!int.TryParse(statusCodeStr, out statusCode))
            return false;

        this.StatusCode = statusCode;

        if (statusCodeStr.Length > 0 && (byte)statusCodeStr[statusCodeStr.Length - 1] != LF && (byte)statusCodeStr[statusCodeStr.Length - 1] != CR)
        {
            this.Message = ReadTo(Stream, LF);
            if (HTTPManager.Logger.Level == Logger.Loglevels.All)
                VerboseLogging(string.Format("Status Message: '{0}'", this.Message));
        }
        else
        {
            HTTPManager.Logger.Warning("HTTPResponse", string.Format("{0} - Skipping Status Message reading!", this.baseRequest.CurrentUri.ToString()));

            this.Message = string.Empty;
        }

        //Read Headers
        ReadHeaders(Stream);

        IsUpgraded = StatusCode == 101 && (HasHeaderWithValue("connection", "upgrade") || HasHeader("upgrade"));

        if (IsUpgraded && HTTPManager.Logger.Level == Logger.Loglevels.All)
            VerboseLogging("Request Upgraded!");

        if (!readPayloadData)
            return true;

        return ReadPayload(forceReadRawContentLength);
    }

HTTPProxyResponse.cs

public class HTTPProxyResponse : HTTPResponse
{

    internal override bool Receive(int forceReadRawContentLength = -1, bool readPayloadData = false)
    {
        return base.Receive(forceReadRawContentLength, false);
    }
}

这让我说错了

  

覆盖“公开”继承的成员时无法更改访问修饰符

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

更改派生类型中的访问修饰符是毫无意义的,而且是不允许的

internal中的public更改为HTTPProxyResponse

public override bool Receive(int forceReadRawContentLength = -1, bool readPayloadData = false)