接口不匹配 属性 存取器
Interface Mismatch Property Accessor
我有一个简单的接口,我想用不同的访问器来实现它
public interface IValidatorByState : IValidator
{
AuthorizedDbContext Context { get; set; }
}
我正在尝试在 class 上使用 Public 或 Protected Get 和内部集实现此功能;
编辑 这个 class 是暴露给用户的,他们应该只能检索上下文。
public class ValidatorByState<TEntity> : AbstractValidator<TEntity>, IValidatorByState
{
public AuthorizedDbContext Context { get; internal set;}
}
无论用哪种方式实现我都报错
尝试次数:
public AuthorizedDbContext Context { get; internal set;}
ValidatorByState.Context is not public
protected AuthorizedDbContext Context { get; internal set;}
ValidatorByState.Context.set Accessor must be more restrictive than property,
AuthorizedDbContext _context;
public AuthorizedDbContext IValidatorByState.Context => this._context;
public AuthorizedDbContext IValidatorByState.Context {
set { this._context = value; }
}
为此,我在两个陈述中都遇到了错误
Explicit implementation missing Accessor
如何使用内部集获取 public 方法?
接口成员必须是public。
关于:
public interface IValidatorByStateReader
{
AuthorizedDbContext Context { get; }
}
internal interface IValidatorByStateWriter
{
AuthorizedDbContext Context { set; }
}
public class ValidatorByState<TEntity> : IValidatorByStateReader, IValidatorByStateWriter
{
private AuthorizedDbContext _context;
AuthorizedDbContext IValidatorByStateReader.Context => this._context;
AuthorizedDbContext IValidatorByStateWriter.Context { set => this._context = value; }
}
我会创建一个 public 接口,它是只读的,并且是 setter methods/properties 的内部接口。必须显式实现内部接口:
public interface IValidatorByStateReadOnly
{
AuthorizedDbContext Context { get; }
}
internal interface IValidatorByState : IValidatorByStateReadOnly
{
new AuthorizedDbContext Context { get; set; }
}
public class ValidatorByState<TEntity> : IValidatorByState
{
private AuthorizedDbContext _context;
public AuthorizedDbContext Context => _context;
AuthorizedDbContext IValidatorByState.Context
{
get => _context;
set => _context = value;
}
}
我有一个简单的接口,我想用不同的访问器来实现它
public interface IValidatorByState : IValidator
{
AuthorizedDbContext Context { get; set; }
}
我正在尝试在 class 上使用 Public 或 Protected Get 和内部集实现此功能;
编辑 这个 class 是暴露给用户的,他们应该只能检索上下文。
public class ValidatorByState<TEntity> : AbstractValidator<TEntity>, IValidatorByState
{
public AuthorizedDbContext Context { get; internal set;}
}
无论用哪种方式实现我都报错
尝试次数:
public AuthorizedDbContext Context { get; internal set;}
ValidatorByState.Context is not public
protected AuthorizedDbContext Context { get; internal set;}
ValidatorByState.Context.set Accessor must be more restrictive than property,
AuthorizedDbContext _context;
public AuthorizedDbContext IValidatorByState.Context => this._context;
public AuthorizedDbContext IValidatorByState.Context {
set { this._context = value; }
}
为此,我在两个陈述中都遇到了错误
Explicit implementation missing Accessor
如何使用内部集获取 public 方法?
接口成员必须是public。
关于:
public interface IValidatorByStateReader
{
AuthorizedDbContext Context { get; }
}
internal interface IValidatorByStateWriter
{
AuthorizedDbContext Context { set; }
}
public class ValidatorByState<TEntity> : IValidatorByStateReader, IValidatorByStateWriter
{
private AuthorizedDbContext _context;
AuthorizedDbContext IValidatorByStateReader.Context => this._context;
AuthorizedDbContext IValidatorByStateWriter.Context { set => this._context = value; }
}
我会创建一个 public 接口,它是只读的,并且是 setter methods/properties 的内部接口。必须显式实现内部接口:
public interface IValidatorByStateReadOnly
{
AuthorizedDbContext Context { get; }
}
internal interface IValidatorByState : IValidatorByStateReadOnly
{
new AuthorizedDbContext Context { get; set; }
}
public class ValidatorByState<TEntity> : IValidatorByState
{
private AuthorizedDbContext _context;
public AuthorizedDbContext Context => _context;
AuthorizedDbContext IValidatorByState.Context
{
get => _context;
set => _context = value;
}
}