How does this generic function work?

When I see a form function call:

Dim i as Integer = getAnInteger("I am groot")

I can understand that the signature getAnIntegershould be something like

Function getAnInteger(inp As String) As Integer

Now I have this call:

Property Name As String
    Get
        Return _name
    End Get
    Set(ByVal value as String)
        _name = value
        doSomething(Function() Name)  '<---- this one
    End Set
End Property

I realized that it doSomethingshould be defined as

Sub doSomething(ByVal fnName As Func(Of String))
                     '
                     ' or
                     '
Sub doSomething(Of T)(ByVal fnName As Func(Of T)) '....................(1)

I found out that it

Sub doSomething(Of T)(ByVal fnName As Expression(Of Func(Of T))) '.....(2)

Question

How is it that Func(Of T)they Expression(Of Func(Of T))can take an argument Function() Name, where Nameis a property of type String. Also Expressionlocated in the namespace Linq. So the argument must be a linq expression. But Function() Namenot Linq! this is a simple delegate for a property Name. So how does it work?

+4
source share
1 answer

Expression(Of T) - , , , .

- (, Function() Name) (, Func(Of String)), , lambda- Expression(Of Func(Of String)), , , .

, . Entity Framework SQL, .

Expression(Of Func(Of String)) Func(Of String) , Compile. Func(Of String) Expression(Of Func(String)), , . Expression, , , .

+2

Source: https://habr.com/ru/post/1584434/


All Articles