Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a piece of code like the following....

VB
Delegate Function CreateObject(Of I)(Object context) As I

Class Container
    Property ReadOnly ObjectType() As Type
End Class

Class Container(of I)
    Inherits Container

    Property ReadOnly Creator() As CreateObject(Of I)
End Class


'And some where in the code i am trying to achieve this
Class SomeClass

    Function SomewhereIntheCode(myContainer As Container) As Expresion
        Dim delType As Type
        Dim del as [Delegate]
        Dim exp as Expression

        delType = GetType(CreateObject(Of )).MakeGenericType(myContainer.ObjectType)
        'del=[Delegate].CreateDelegate(delType,...here is a problem
        'return del
        'but now i want to return an 
        'exp=.....here is the biggest problem

        return exp

    End Function
End Class


How do i achieve this, calling an object's property which is of delegate type
using expressions.

Thank you so much
Posted
Comments
BillWoodruff 14-Sep-14 8:32am    
Please do not post a question ... clearly a VB.NET question ... here that you've already posted in the VB.NET forum in the C# forum.
Sergey Alexandrovich Kryukov 14-Sep-14 9:16am    
Do you mean invocation of the delegate instance via reflection? If that what you show all this fragment of code for? (Otherwise this fragment would be irrelevant to the question...)
—SA
Simba Mukodzani 15-Sep-14 7:23am    
Yes I mean invocation of a generic delegete which on a property of an object via reflection, the type parameter is obtained during runtime.

equivalent of 'MyGenericInstance.PropertyToADelegate.Invoke()'
using a LambdaExpression
Sergey Alexandrovich Kryukov 15-Sep-14 10:35am    
Okay, thank you for this important clarification. Will you remind me by commenting on this my comment? I have no time at this moment, will try to write the solution as soon as I can.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900