Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 覆盖';时更改访问修饰符;公共';继承成员_C#_Unity3d - Fatal编程技术网

C# 覆盖';时更改访问修饰符;公共';继承成员

C# 覆盖';时更改访问修饰符;公共';继承成员,c#,unity3d,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.Logg

我有两个脚本,即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);
    }
public class HTTPProxyResponse : HTTPResponse
{

    internal override bool Receive(int forceReadRawContentLength = -1, bool readPayloadData = false)
    {
        return base.Receive(forceReadRawContentLength, false);
    }
}
HTTPProxyResponse.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);
    }
public class HTTPProxyResponse : HTTPResponse
{

    internal override bool Receive(int forceReadRawContentLength = -1, bool readPayloadData = false)
    {
        return base.Receive(forceReadRawContentLength, false);
    }
}
这给了我一个错误的说法

重写“public”继承成员时无法更改访问修饰符


如何修复此错误?

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


HTTPProxyResponse

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

内部
更改为
公共
。内部比公共更严格。您是否尝试将HTTPProxyResponse中的接收方法标记为
公共
,而不是
内部
?您无法更改覆盖方法的访问修饰符。想象一下,将一个对象转换回它的基类型,然后您将神奇地能够访问以前的
内部
方法。好了,您只能增加重写方法的可见性(尽管C#不支持,所以您必须使用IL或其他支持该方法的语言),但不能减少它。谢谢。4分钟后,我才能接受这个作为answer@Ketskie谢谢你