2

Imagine I have class like this :

Class A
    Public Function Some(str As String) As String
        Return "Some " + str
    End Function
End Class

I have consuming code like this :

Public Sub Foo()
    Dim thisWorks = New With {.prop = "thing"}
    Dim thisDoesntWork = New inherits A with { .prop = Some("thing") }
End Sub

I'm trying to create an anonymous type with inheritance so that I can use the methods within. Is this possible ?

Use case : I'm trying to create a class that has methods like Select, From etc. that would help in cleaner query construction. In the consuming code, I would just create an anonymous type inheriting from the class and use the methods.

1
  • Would it be something like in This Post? Commented May 27, 2015 at 22:06

1 Answer 1

1

What you want is not possible (at least not the way you describe it).

From what I think I understood ; you should try to mimic what has been donne for Linq ; an interface (like IEnumerable) with all the method you want (or maybe an abstract class bu that prevent you to inherit from something else) + something else (probably a module if you want them as extension method) defining the Select etc. acting on the interface.

From that point you can create classes which implement the interface and use your custom Select etc. on them

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.