Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15033

[RESOLVED] Multiple Interface Variants

$
0
0
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.

Viewing all articles
Browse latest Browse all 15033

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>