當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。