Open sandboxFocus

Class ExpressionFactory

Provides several ways to create instances of the IExpression interface.

Inheritance
ExpressionFactory
Namespace: Metalama.Framework.Code.SyntaxBuilders
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public static class ExpressionFactory

Methods

Name Description
Capture(dynamic?)

Creates a compile-time object that represents a run-time expression, i.e. the syntax or code, and not the result itself. The returned IExpression can then be used in run-time C# code thanks to the Value property. This mechanism allows to generate expressions that depend on a compile-time control flow.

CastTo(IExpression, IType)

Returns an expression obtained by casting another expression to a type given as an IType.

CastTo(IExpression, Type)

Returns an expression obtained by casting another expression to a type given as a Type.

CastTo<T>(IExpression)

Returns an expression obtained by casting another expression to a type given as a generic parameter.

Default()

Gets a default expression without specifying a type. The expression will be target-typed.

Default(IType?)

Gets a default expression for a given type.

Default(SpecialType)

Gets a default expression for a given type.

Default(Type)

Gets a default expression for a given type.

Default<T>()

Gets a default expression for a given type.

Literal(byte, bool)

Returns an expression that represents a literal of type byte.

Literal(decimal, bool)

Returns an expression that represents a literal of type decimal.

Literal(double, bool)

Returns an expression that represents a literal of type double.

Literal(short, bool)

Returns an expression that represents a literal of type short.

Literal(int)

Returns an expression that represents a literal of type int.

Literal(long, bool)

Returns an expression that represents a literal of type long.

Literal(object?, bool)

Returns an expression that represents a literal.

Literal(sbyte, bool)

Returns an expression that represents a literal of type sbyte.

Literal(float, bool)

Returns an expression that represents a literal of type float.

Literal(string?, bool)

Returns an expression that represents a literal of type string.

Literal(ushort, bool)

Returns an expression that represents a literal of type ushort.

Literal(uint, bool)

Returns an expression that represents a literal of type uint.

Literal(ulong, bool)

Returns an expression that represents a literal of type ulong.

Null()

Gets a null expression without specifying a type. The expression will be target-typed.

Null(IType?)

Gets a null expression for a given type.

Null(SpecialType)

Gets a null expression for a given type.

Null(Type)

Gets a null expression for a given type.

Null<T>()

Gets a null expression for a given type.

Parse(string)

Parses a string containing a C# expression and returns an IExpression. The Value property allows to use this expression in a template. An alternative to this method is the ExpressionBuilder class.

This()

Gets a this expression for the current type when inside a template.

This(INamedType)

Gets a this expression for the given type.

WithNullability(IExpression, bool)

Returns the same expression, but assuming it has a different nullability. This method does not generate any cast (unlike CastTo(IExpression, IType)) and should only be used when the of the nullability given expression is wrongly infered.

WithType(IExpression, IType)

Returns the same expression, but assuming it has a different type Type. This method does not generate any cast (unlike CastTo(IExpression, IType)) and should only be used when the of the type given expression is wrongly infered.