ExpressionParserOptions
Namespace: TagBites.Expressions
Assembly: TagBites.Expressions.dll
Product: TagBites.Expressions v. 1.5.0
Options for parsing expressions, including validation, parameters, global members, and custom property resolution.
public class ExpressionParserOptionsInheritance: object → ExpressionParserOptions
Remarks
Section titled “Remarks”An instance becomes read-only the first time it is used for parsing. Use Fork(Type, Type, IList<(Type, string)>, bool?) to reuse the prepared, shared settings while varying the result type or parameters.
Constructors
Section titled “Constructors”ExpressionParserOptions()
Section titled “ExpressionParserOptions()”Initializes a new options instance with the default settings.
public ExpressionParserOptions()ExpressionParserOptions(ExpressionParserOptions)
Section titled “ExpressionParserOptions(ExpressionParserOptions)”Initializes a new mutable options instance by copying every setting from other.
public ExpressionParserOptions(ExpressionParserOptions other)Parameters
Section titled “Parameters”otherExpressionParserOptions
Properties
Section titled “Properties”AllowReflection
Section titled “AllowReflection”Indicates whether to allow reflection. Default: false.
public bool AllowReflection { get; set; }Property Value
Section titled “Property Value”AllowRuntimeCast
Section titled “AllowRuntimeCast”True to allow runtime casting using custom operators. Default: false.
public bool AllowRuntimeCast { get; set; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”Custom operators:
typeis(someExpression, "MyNamespace.MyType,MyAssembly")typeas(someExpression, "MyNamespace.MyType,MyAssembly")typecast(someExpression, "MyNamespace.MyType,MyAssembly")AllowStringRelationalOperators
Section titled “AllowStringRelationalOperators”True to allow < / <= / > / >= on strings, compared ordinally via String.Compare(string, string). Not valid in real C#. Default: false.
public bool AllowStringRelationalOperators { get; set; }Property Value
Section titled “Property Value”AllowThrowExpressions
Section titled “AllowThrowExpressions”True to allow throw expressions (for example x > 0 ? x : throw new ArgumentException()). Default: false.
public bool AllowThrowExpressions { get; set; }Property Value
Section titled “Property Value”CustomPropertyResolver
Section titled “CustomPropertyResolver”Function to resolve property/field-style access for types whose shape only exists at runtime, e.g. a database row, a CMS content type, a value that lives in another process.
public Func<IExpressionMemberResolverContext, Expression> CustomPropertyResolver { get; set; }Property Value
Section titled “Property Value”Func<IExpressionMemberResolverContext, Expression>
GlobalMembers
Section titled “GlobalMembers”List of global members (values or delegates). Member type is optional; if null, the type is based on the value. If both member type and value are null, the type is object. Member with name ‘this’ can be access implicitly (when UseFirstParameterAsThis is false).
public IDictionary<string, (Type, object)> GlobalMembers { get; set; }Property Value
Section titled “Property Value”IDictionary<string, (Type, object)>
IgnoreBuiltInTypes
Section titled “IgnoreBuiltInTypes”True to disable the fixed set of common framework types that are otherwise available by their short name regardless of IncludedTypes. Default: false.
public bool IgnoreBuiltInTypes { get; set; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”The built-in types are for example: TimeSpan, DateTime, DateTimeOffset, DateTimeKind, DayOfWeek, StringComparison, CultureInfo, MidpointRounding, Math, Enumerable, List, Dictionary, HashSet, and Convert and more typically used in an expressions.
The C# primitive keywords (int, string, bool, etc.) are always available and are not affected by this option.
IgnoreCase
Section titled “IgnoreCase”True to resolve parameters, variables, global members, type members and IncludedTypes case-insensitively. Default: false.
public bool IgnoreCase { get; set; }Property Value
Section titled “Property Value”IncludedTypes
Section titled “IncludedTypes”Collection of types that can be used in expressions.
public ICollection<Type> IncludedTypes { get; }Property Value
Section titled “Property Value”Parameters
Section titled “Parameters”List of parameters of the function.
public IList<(Type, string)> Parameters { get; set; }Property Value
Section titled “Property Value”ResultCastType
Section titled “ResultCastType”A type to convert the expression to, for example, to create a general lambda like Func<object>. If null, the result type is based on the expression.
public Type ResultCastType { get; set; }Property Value
Section titled “Property Value”ResultType
Section titled “ResultType”Expected and required result type of the expression. Used only for validation. If null, the result type is not checked.
public Type ResultType { get; set; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”Can be overridden per fork through Fork(Type, Type, IList<(Type, string)>, bool?), because it is not part of the shared cached context.
StaticImports
Section titled “StaticImports”Collection of types imported statically, as if using static was applied. Their public static methods, fields, properties and constants can be used unqualified. For example, adding Math makes Sqrt(x), Max(a, b), PI and E available. Members of instance parameters, global members and instance types always take precedence.
public ICollection<Type> StaticImports { get; }Property Value
Section titled “Property Value”TypeResolver
Section titled “TypeResolver”Function that resolves a type from its name, invoked when a type cannot be found among ResultType, Parameters, IncludedTypes or the built-in types. The name may be namespace-qualified (e.g. System.Text.StringBuilder) when that form is used in expression. A generic type name is suffixed with an apostrophe and the number of type arguments (e.g. List'1, Dictionary'2), and the returned type must be the corresponding open generic definition (e.g. typeof(List<>)). Return null to indicate the name is not recognized.
public Func<string, Type> TypeResolver { get; set; }Property Value
Section titled “Property Value”UseFirstParameterAsThis
Section titled “UseFirstParameterAsThis”True if the first parameter should be used as ‘this’ so its members can be accessed implicitly. Alternatively, the ‘this’ member in GlobalMembers can be used. Default: false.
public bool UseFirstParameterAsThis { get; set; }Property Value
Section titled “Property Value”UseMemberCache
Section titled “UseMemberCache”Caches reflected members (methods, indexers, extension methods) on this options instance. Default: false.
public bool UseMemberCache { get; set; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Fork(Type, Type, IList<(Type, string)>, bool?)
Section titled “Fork(Type, Type, IList<(Type, string)>, bool?)”Creates a read-only variant that reuses the prepared, shared settings of this instance (global members, included types, static imports, member cache and the resolution flags), while overriding the result type, parameters or ‘this’ handling.
public ExpressionParserOptions Fork(Type resultType, Type resultCastType, IList<(Type, string)> parameters, bool? useFirstParameterAsThis)Parameters
Section titled “Parameters”resultTypeType
The result type for the fork, ornullto inherit ResultType.resultCastTypeType
The result cast type for the fork, ornullto inherit ResultCastType.parametersIList<(Type, string)>
The parameters for the fork, ornullto inherit Parameters.useFirstParameterAsThisbool?
The ‘this’ handling for the fork, ornullto inherit UseFirstParameterAsThis.
Returns
Section titled “Returns”A prepared, read-only options instance that shares the reusable lookups of this instance. When every argument is null, this instance is returned, because the fork would be identical.
Remarks
Section titled “Remarks”The shared member cache and settings are reused by every fork. Only the parameters and ‘this’ handling rebuild the parameter-specific part of the context. Forking makes this instance read-only, because its shared settings are now shared with the fork.