当前位置: 首页>>代码示例>>C#>>正文


C# Expression.Cast方法代码示例

本文整理汇总了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);
 }
开发者ID:nickchal,项目名称:pash,代码行数:33,代码来源:PSConvertBinder.cs

示例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)));
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:PSToStringBinder.cs

示例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())) });
 }
开发者ID:nickchal,项目名称:pash,代码行数:5,代码来源:PSGetIndexBinder.cs

示例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[])));
 }
开发者ID:40a,项目名称:PowerShell,代码行数:6,代码来源:Compiler.cs

示例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)));
 }
开发者ID:40a,项目名称:PowerShell,代码行数:11,代码来源:Compiler.cs

示例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);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:9,代码来源:Compiler.cs

示例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));
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:PSBinaryOperationBinder.cs

示例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();
 }
开发者ID:kevinmw,项目名称:rpcsharp,代码行数:8,代码来源:RpcCallVisitor.cs


注:本文中的System.Linq.Expressions.Expression.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。