Tom Knowlton
asked on
Interface - how to implement read-only values. C# 7.3
How do I declare a read only value in an interface and properly declare it in a class that uses the Interface?
Says "The name 'Consumer Key' does not exist (same for the other params)":
public interface ISalesForceRepository
{
string SecurityToken { get; }
string ConsumerKey { get; }
string ConsumerSecret { get; }
string Username { get; }
string Password { get; }
...
...
}
public class SalesForceRepository : ISalesForceRepository
{
Says "Error CS0535 'SalesForceRepository' does not implement interface member 'ISalesForceRepository.ConsumerKey.set' SalesForceRepository":
string ISalesForceRepository.ConsumerKey
{
get
{
return "3MVG9fMtCkV6eLhf5nAFy1[truncated].";
}
}
}
Says "The name 'Consumer Key' does not exist (same for the other params)":
await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I do control the interface as well as the implementation so I can make whatever changes are needed.
I just want to ensure that the interface declares these as read only private properties. Possible?
I just want to ensure that the interface declares these as read only private properties. Possible?
See my example in the post above. It does exactly that.
ASKER
Thank you both!
Error CS0535 'SalesForceRepository' does not implement interface member 'ISalesForceRepository.Con
...then it's basically saying that your interface definition requires a "set" method in the implementation. So if you're not the one in control of the interface definition, then you can just choose to not do anything in set of your implementation (stealing from ste5fan's code above):
public class SalesForceRepository3 : ISalesForceRepository
{
public string ConsumerKey { get { return "3MVG9fMtCkV6eLhf5nAFy1"} set {} };
}