Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LambdaExpressionExtensions sample notebook #191

Merged
merged 7 commits into from
Oct 19, 2022
Merged
44 changes: 44 additions & 0 deletions Corvus.Extensions.Samples/LambdaExpressionExtensionsSample.dib
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!markdown

## Lambda Expression Extensions = Sample Notebook
jesshill99 marked this conversation as resolved.
Show resolved Hide resolved

#!markdown

First, add a reference to the `Corvus.Extensions` NuGet package.

#!csharp

#r "nuget: Corvus.Extensions, 1.1.4"

using Corvus.Extensions;
using System.Linq.Expressions;

#!markdown

### ExtractPropertyName()

#!markdown

Extracts a property name from a lambda expression, throwing if that expression is not a `MemberExpression`.

#!csharp

Expression<Func<string, int>> getter = x => x.Length;

#!csharp

getter.ExtractPropertyName()

#!markdown

### GetMemberExpression()

#!markdown

Extracts a `MemberExpression` from a `LambdaExpression`, throwing if the body is not a `MemberExpression`.

#!csharp

getter.GetMemberExpression().Expression

//{ x: Type: System.String, NodeType: Parameter, Name: x, IsByRef: False, CanReduce: False }