CKTIS / C#
System.Linq.Expressions.Expression: praktická reference
System.Linq.Expressions.Expression: praktická reference: Expression představuje uzly stromu kódu, který lze analyzovat nebo zkompilovat.
Verze: .NET API; verified on .NET 10.0.14
Syntaxe
System.Linq.Expressions.Expression /* select a documented member or constructor */Expression představuje uzly stromu kódu, který lze analyzovat nebo zkompilovat.
Použijte jej pro poskytovatele dotazů, dynamické predikáty a řízené generování spustitelného kódu.
Ne každý konstrukt C# má uzel či podporu poskytovatele; Compile něco stojí a může vyžadovat dynamický kód.
Parametry musí být konzistentně svázány a nekompatibilní typy uzlů při sestavení vyvolají ArgumentException.
Úplný program skutečně používá System.Linq.Expressions.Expression; přesně očekávaný stdout je 5.
Pří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;
Expression<Func<int, int>> tree = value => value + 1;
Console.WriteLine(tree.Compile()(4));
Výsledek
5
Úplný program skutečně používá `System.Linq.Expressions.Expression`; přesně očekávaný stdout je `5`.