本文整理汇总了C#中System.Linq.Expressions.Expression.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Cast方法的具体用法?C# Expression.Cast怎么用?C# Expression.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.Cast方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeConverter
internal static Expression InvokeConverter(LanguagePrimitives.ConversionData conversion, Expression value, Type resultType, bool debase, Expression formatProvider)
{
Expression expression;
if ((conversion.Rank == ConversionRank.Identity) || (conversion.Rank == ConversionRank.Assignable))
{
expression = debase ? Expression.Call(CachedReflectionInfo.PSObject_Base, value) : value;
}
else
{
Expression expression2;
Expression nullPSObject;
if (debase)
{
expression2 = Expression.Call(CachedReflectionInfo.PSObject_Base, value);
nullPSObject = value.Cast(typeof(PSObject));
}
else
{
expression2 = value.Cast(typeof(object));
nullPSObject = ExpressionCache.NullPSObject;
}
expression = Expression.Call(Expression.Constant(conversion.Converter), conversion.Converter.GetType().GetMethod("Invoke"), new Expression[] { expression2, Expression.Constant(resultType), ExpressionCache.Constant(true), nullPSObject, formatProvider, ExpressionCache.NullTypeTable });
}
if (expression.Type.Equals(resultType) || resultType.Equals(typeof(LanguagePrimitives.InternalPSCustomObject)))
{
return expression;
}
if (resultType.IsValueType && (Nullable.GetUnderlyingType(resultType) == null))
{
return Expression.Unbox(expression, resultType);
}
return Expression.Convert(expression, resultType);
}
示例2: InvokeToString
internal static Expression InvokeToString(Expression context, Expression target)
{
if (target.Type.Equals(typeof(string)))
{
return target;
}
return Expression.Call(CachedReflectionInfo.PSObject_ToStringParser, context.Cast(typeof(ExecutionContext)), target.Cast(typeof(object)));
}
示例3: SafeIndexResult
private Expression SafeIndexResult(Expression expr)
{
ParameterExpression variable = Expression.Parameter(typeof(Exception));
return Expression.TryCatch(expr.Cast(typeof(object)), new CatchBlock[] { Expression.Catch(variable, Expression.Block(Expression.Call(CachedReflectionInfo.CommandProcessorBase_CheckForSevereException, variable), Expression.IfThen(Compiler.IsStrictMode(3, null), Expression.Rethrow()), this.GetNullResult())) });
}
示例4: CallSetVariable
internal static Expression CallSetVariable(Expression variablePath, Expression rhs, Expression attributes = null)
{
return Expression.Call(CachedReflectionInfo.VariableOps_SetVariableValue,
variablePath, rhs.Cast(typeof(object)), _executionContextParameter,
attributes ?? ExpressionCache.NullConstant.Cast(typeof(AttributeAst[])));
}
示例5: GenerateCallContains
public Expression GenerateCallContains(Expression lhs, Expression rhs, bool ignoreCase)
{
return Expression.Call(
CachedReflectionInfo.ParserOps_ContainsOperatorCompiled,
_executionContextParameter,
Expression.Constant(CallSite<Func<CallSite, object, IEnumerator>>.Create(PSEnumerableBinder.Get())),
Expression.Constant(CallSite<Func<CallSite, object, object, object>>.Create(
PSBinaryOperationBinder.Get(ExpressionType.Equal, ignoreCase, scalarCompare: true))),
lhs.Cast(typeof(object)),
rhs.Cast(typeof(object)));
}
示例6: CallAddPipe
internal Expression CallAddPipe(Expression expr, Expression pipe)
{
if (!PSEnumerableBinder.IsStaticTypePossiblyEnumerable(expr.Type))
{
return Expression.Call(pipe, CachedReflectionInfo.Pipe_Add, expr.Cast(typeof(object)));
}
return DynamicExpression.Dynamic(PSPipeWriterBinder.Get(), typeof(void), expr, pipe, _executionContextParameter);
}
示例7: ConvertStringToNumber
internal static Expression ConvertStringToNumber(Expression expr, Type toType)
{
if (!toType.IsNumeric())
{
toType = typeof(int);
}
return Expression.Call(CachedReflectionInfo.Parser_ScanNumber, expr.Cast(typeof(string)), Expression.Constant(toType));
}
示例8: ArgumentsWrap
public ArgumentsWrap(bool isNewArray, Expression[] args)
{
_isNewArray = isNewArray;
var invalid = args.FirstOrDefault(x => !(x is IEvaluatesToString));
if (invalid != null)
throw new InvalidExpressionInRpcCallException(invalid, "Not supported expression");
_args = args.Cast<IEvaluatesToString>().ToArray();
}