CKTIS / C#
System.Linq.Expressions.LambdaExpression: praktická referencia
System.Linq.Expressions.LambdaExpression: praktická referencia: LambdaExpression je negenerický základ stromu lambda s Body, Parameters a ReturnType.
Verzia: .NET API; verified on .NET 10.0.14
Syntax
System.Linq.Expressions.LambdaExpression /* select a documented member or constructor */LambdaExpression je negenerický základ stromu lambda s Body, Parameters a ReturnType.
Použite ho v reflexných nástrojoch pre lambdy, ktorých typ delegáta je známy až za behu.
Compile a dynamické volanie strácajú časť statickej kontroly a pri AOT nemusia byť dostupné.
Počet a typy parametrov musia zodpovedať typu delegáta, inak zostavenie lambdy vyvolá výnimku.
Úplný program skutočne používa System.Linq.Expressions.LambdaExpression; presne očakávaný stdout je 1.
Príklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
LambdaExpression expression = (Expression<Func<int, int>>)(value => value * 2);
Console.WriteLine(expression.Parameters.Count);
Výsledok
1
Úplný program skutočne používa `System.Linq.Expressions.LambdaExpression`; presne očakávaný stdout je `1`.