Interface Mismatch Property Accessor

johnny 5

I have a simple Interface which I would like to implement with different Accessors

public interface IValidatorByState : IValidator
{
    AuthorizedDbContext Context { get; set; }
}

I'm trying to implement this on a class with an Public, Or Protected Get and an Internal Set;

Edit This class is is exposed to the user, they should only be able to retrieve the Context.

public class ValidatorByState<TEntity> : AbstractValidator<TEntity>, IValidatorByState
{
    public AuthorizedDbContext Context { get; internal set;}
}

No matter which way Implement this I've been given an error

Attempts:

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; }
}

For this I get an error on both stating

Explicit implementation missing Accessor

How can I have a public get method with a internal set?

Mike Zboray

I would create a public interface that was readonly and internal interface with the setter methods/properties. The internal interface has to be explicitly implementated:

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; 
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Property accessor of an object in javascript

Lua property accessor

Accessor in interface cannot be delimited by comma

FakeItEasy setting property with no get accessor?

Interface mismatch in dummy procedure

Difference between accessor property and data property in ECMAScript?

How to prevent get accessor to call set accessor when assigning a property

Angular2 linq style property accessor

Calling a VB property from its own accessor

Reflect property name from inside accessor?

Fluent Validation Rule Builder Get Property Accessor

Is UIColor's CGColor accessor a property or method?

What is the property accessor for a mask on SVG elements?

Type of property does not match type of accessor

Property or indexer must have at least one accessor

typescript, import * as, no index signature with bracket property accessor

What is Property Accessor Recursion in C#?

Are parentheses ignored if they only contain a property accessor?

Interface mismatch - higher order functions

Interface Implementing with interface property

Converting data property to accessor property and vice versa in JavaScript

C# Why property's get and set methods both called accessor but not accessor and mutator?

Localized app name vs interface language mismatch

Interface property depend on other property

Prefer property-accessor or KVC style for accessing Core Data properties

Laravel not getting Accessor Trying to get property on a non-object

Why doesn't defining the accessor descriptor of a property of computedStyle work?

MATLAB GUI - Accessor method or property edit? What's best practice?

TypeScript Unexpected token, A constructor, method, accessor or property was expected