Skip to content

Releases: SeeminglyScience/PSLambda

v0.2.0

29 Apr 18:55
393597b
Compare
Choose a tag to compare
v0.2.0 Pre-release
Pre-release

Extension methods (Linq)

Extension methods can now be resolved based on using namespace statements of the main script.
By default the System.Linq namespace is included to allow easy access to the Enumerable methods like Where, Select, OfType, etc.

Along with this change brings significantly improved generic type argument resolution and
ScriptBlock to Delegate conversion within the delegate.

$delegate = New-PSDelegate {
    $ExecutionContext.InvokeProvider.ChildItem.Get('function:', $true).
        Select{ $pso => $pso.BaseObject }.
        OfType([g[System.Management.Automation.FunctionInfo]]).
        FirstOrDefault{ $f => $f.Name.Equals('TabExpansion2') }
}

$delegate.Invoke()
# CommandType     Name             Version    Source
# -----------     ----             -------    ------
# Function        TabExpansion2

Anonymous method syntax relaxed

Originally to use the alternate parameter declaration syntax you needed:

  1. Parenthesis around each parameter
  2. A ScriptBlock around the body
  3. All parameters to be explicitly typed (when used as a method argument)

Now none of that is required, but is still supported. See above for example.

Improved generic argument declaration

You can now specify generic arguments inline in the method. This works a lot better for
the method chaining that is common with Linq methods.

If the first argument in a method is a type literal expression of the type g, then
any generic arguments on that type will be used as generic arguments for the method. The
compiled result will be a call to the constructed generic method with all other parameters
in tact.

$delegate = New-PSDelegate { [array]::Empty([g[Type]]) }
$delegate.Invoke().GetType()
# IsPublic IsSerial Name        BaseType
# -------- -------- ----        --------
# True     True     Type[]      System.Array

$delegate = New-PSDelegate {
    [System.Management.Automation.LanguagePrimitives]::ConvertTo(
        [g[int]],
        '10')
}

$delegate.Invoke().GetType()
# IsPublic IsSerial Name         BaseType
# -------- -------- ----         --------
# True     True     Int32        System.ValueType

Lock keyword

Added the lock keyword from C# for synchronizing access to an object between threads. Like
the C# compiler, lock statements are replaced in the compiler with calls to Monitor.Enter
in a try and Monitor.Exit in the finally.

Fixes

  • Index expressions on objects that did not implement IList or IDictionary will now
    work properly. Originally the implementation looked for specific interfaces to determine
    the indexer, now it uses the DefaultMemberAttribute.

  • The iterator variable in a foreach statement is now typed properly if possible.

v0.1.1

24 Apr 23:46
Compare
Choose a tag to compare
v0.1.1 Pre-release
Pre-release

Fix exceptions that occurred with:

  • Empty Hashtable initialization expressions
  • switch statements with just a default block
  • Index operations on expressions typed explicitly as IEnumerable<>
  • The -as and -not operators
  • The -bor and -band operators when used against an Enum

v0.1.0

23 Apr 00:46
Compare
Choose a tag to compare
v0.1.0 Pre-release
Pre-release

Initial release.