首页 > 解决方案 > 覆盖“公共”继承成员时更改访问修饰符

问题描述

我有两个脚本,即 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);
    }
}

它给了我一个错误说

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

我该如何解决这个错误?

标签: c#unity3d

解决方案


更改派生类型中的访问修饰符是没有意义的,也是不允许的

更改internalpublic_HTTPProxyResponse

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

推荐阅读