Skip to content

Add conversion from PSMethodInfo to delegate/Func<>  #2864

@powercode

Description

@powercode

As a step on the way to realize #2226, I think we should start with adding a conversion from PSMethodInfo to System.Func.

Today, we have to do something like this:

Class MyClass {
      
    [int] Add47([int] $value) {    
      return 47 + $value
    }
            
    [int] DoStuff([System.Collections.Generic.IEnumerable[int]] $collection) {
        # ugly
        $func = $this.GetType().GetMethod("Add47").CreateDelegate([Func[int,int]], $this)
        return [Linq.Enumerable]::Sum($collection, $func)
    }
}

I would like to express that as:

Class MyClass {    
    [int] Add47([int] $value) {    
      return 47 + $value
    }
            
    [int] DoStuff([System.Collections.Generic.IEnumerable[int]] $collection) {
        return [Linq.Enumerable]::Sum($collection, $this.Add47)
    }
}

What is the right place to do this?

Metadata

Metadata

Assignees

Labels

Issue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions