c# - 覆盖“公共”继承成员时更改访问修饰符
问题描述
我有两个脚本,即 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);
}
}
它给了我一个错误说
覆盖“公共”继承成员时无法更改访问修饰符
我该如何解决这个错误?
解决方案
更改派生类型中的访问修饰符是没有意义的,也是不允许的
更改internal
为public
_HTTPProxyResponse
public override bool Receive(int forceReadRawContentLength = -1, bool readPayloadData = false)
推荐阅读
- asp.net-core - 需要 asp.net 核心 webapi 的请求标头
- d3.js - 线条突出,但点不突出
- html - 如何将两个项目并排与一个项目并排对齐
- node.js - 如何避免从 node.js 中的 Application Insights 收集客户端位置信息?
- r - R如何将mathml转换为r方程
- python - 如何在python字典中获取特定键
- flutter - Flutter & AlertDialog : 我的应用在加载后不显示警报对话框
- reactjs - React-hook-form 如何与其他字段交互?
- javascript - VJS 如何使用回车键导航到下一个 tr
- php - 在更新的 php/apache 上的 php/mysql 中的字符 ü 有问题