|
-
Apr 14th, 2021, 01:42 PM
#1
[RESOLVED] Multiple Interface Variants
That subject line sucks, but I couldn't think of a good one, as the question is a bit odd.
In VB, you can do this:
Code:
Interface ITestReadOnly
ReadOnly Property MyProperty As Boolean
End Interface
Interface ITestRW
Inherits ITestReadOnly
Overloads Property MyProperty As Boolean
End Interface
What this does is allow you to create a class like so:
Code:
Public Class TestClass
Implements ITestRW
Implements ITestReadOnly
Public Property MyProperty As Boolean Implements ITestRW.MyProperty, ITestReadOnly.MyProperty
Get
End Get
Set(value As Boolean)
End Set
End Property
End Class
If an instance of TestClass is created and put in a variable of type ITestRW, then the property is read/write, whereas if the class is put in a variable of type ITestReadOnly, then the property is read only. I'm looking for an efficient way to do the same in C#, and my experience with C# is not up to it. I can see a bad way to do it, but without the Implements keyword, I don't see a way that is as easy. Maybe that's just how it is, but I figured I'd ask on here to see if there is a piece of the language that I am not familiar with that would allow this. The goal is a single property that is read only for one interface and read/write for a second interface, such that one interface could inherit the other to add write functionality where the base interface is read only.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|